Skip to content

Analytics Config CRUD Methods - #215

Merged
UZ9 merged 16 commits into
mainfrom
ankith/analytics-config-crud
Oct 21, 2025
Merged

UZ9 merged 16 commits into
mainfrom
ankith/analytics-config-crud

Conversation

@Duckierstone42

@Duckierstone42 Duckierstone42 commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor

#213

Tests passing, also added integration into analytics routes.

@Duckierstone42
Duckierstone42 requested a review from UZ9 October 20, 2025 04:12
@Duckierstone42
Duckierstone42 marked this pull request as ready for review October 20, 2025 20:58

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

Greptile Overview

Summary

This PR implements Analytics Config CRUD operations to enable per-project analytics configuration storage and retrieval. The implementation follows the existing patterns from email and file service configs.

Key Changes:

  • Created AnalyticsServiceConfig proto definitions and Prisma schema with composite primary key (id, environment)
  • Implemented full CRUD operations across db-service, analytics-service, and api-gateway layers
  • Integrated analytics config lookup into analytics event logging, replacing hardcoded API keys with dynamic config retrieval
  • Updated analytics proto to use projectId and environment instead of hardcoded apiKey fields
  • Added comprehensive e2e tests covering all requirements from issue #213

Architecture:

  • API Gateway exposes REST endpoints (/analytics/config) that extract projectId from API key
  • DB Service handles Prisma operations with proper error handling (P2002 for duplicates, P2025 for not found)
  • Analytics Service retrieves configs via gRPC to authenticate with bog-analytics
  • Composite key (id, environment) allows multiple configs per project across environments

Test Coverage:
All required test cases are implemented and passing:

  • Creating analytics configs (including duplicate handling)
  • Reading configs (including non-existent)
  • Updating configs (including non-existent)
  • Deleting configs (including non-existent and already deleted)
  • Full integration testing across all service layers

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured, follows existing patterns from email/file service configs, includes comprehensive test coverage (all tests passing), and properly handles edge cases with appropriate error handling
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/proto/definitions/analytics_config.proto 5/5 Added new proto definitions for Analytics Config CRUD operations with proper message types and service definition
packages/db-service/prisma/schema.prisma 5/5 Added AnalyticsServiceConfig model with composite primary key (id, environment) matching email/file service patterns
packages/db-service/src/modules/analytics_config/analytics_config.controller.ts 5/5 gRPC controller with proper error handling for Prisma errors (P2002 for duplicates, P2025 for not found)
packages/analytics-service/src/modules/analytics/analytics.service.ts 5/5 Integrated analytics config lookup for authentication, replacing hardcoded API keys with dynamic config retrieval
packages/api-gateway/src/modules/analytics_config/analytics_config.controller.ts 5/5 REST API endpoints for analytics config CRUD with proper validation, Swagger docs, and auth integration
packages/proto/definitions/analytics.proto 5/5 Replaced hardcoded API keys with projectId and environment fields for dynamic analytics config lookup

Sequence Diagram

sequenceDiagram
    participant Client
    participant APIGateway
    participant AnalyticsService
    participant AnalyticsConfigService
    participant DBService
    participant Database

    Note over Client,Database: Create Analytics Config Flow
    Client->>APIGateway: POST /analytics/config<br/>{analyticsKey}
    APIGateway->>APIGateway: Extract projectId & environment from API key
    APIGateway->>DBService: createAnalyticsConfig(projectId, environment, analyticsKey)
    DBService->>Database: INSERT INTO AnalyticsServiceConfig
    Database-->>DBService: Return config
    DBService-->>APIGateway: AnalyticsServiceConfig
    APIGateway-->>Client: 201 Created

    Note over Client,Database: Log Event with Analytics Config Flow
    Client->>AnalyticsService: logClickEvent(projectId, environment, ...)
    AnalyticsService->>AnalyticsConfigService: getAnalyticsKey(projectId, environment)
    AnalyticsConfigService->>DBService: readAnalyticsConfig(id, environment)
    DBService->>Database: SELECT FROM AnalyticsServiceConfig<br/>WHERE id=projectId AND environment
    Database-->>DBService: config.analyticsKey
    DBService-->>AnalyticsConfigService: analyticsKey
    AnalyticsConfigService-->>AnalyticsService: analyticsKey
    AnalyticsService->>AnalyticsService: authenticate(analyticsKey)
    AnalyticsService->>AnalyticsService: logClickEvent to bog-analytics
    AnalyticsService-->>Client: Event logged

    Note over Client,Database: Update Analytics Config Flow
    Client->>APIGateway: PUT /analytics/config/:projectId<br/>{analyticsKey}
    APIGateway->>DBService: updateAnalyticsConfig(id, environment, analyticsKey)
    DBService->>Database: UPDATE AnalyticsServiceConfig<br/>WHERE id AND environment
    Database-->>DBService: Updated config
    DBService-->>APIGateway: AnalyticsServiceConfig
    APIGateway-->>Client: 200 OK

    Note over Client,Database: Delete Analytics Config Flow
    Client->>APIGateway: DELETE /analytics/config/:projectId
    APIGateway->>DBService: deleteAnalyticsConfig(id, environment)
    DBService->>Database: DELETE FROM AnalyticsServiceConfig<br/>WHERE id AND environment
    Database-->>DBService: Deleted config
    DBService-->>APIGateway: AnalyticsServiceConfig
    APIGateway-->>Client: 200 OK
Loading

29 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@UZ9

UZ9 commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

LGTM, thanks!

@UZ9
UZ9 merged commit 2ee995b into main Oct 21, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants