# saenthanp/pricey architecture

> Architecture diagram of the GitHub repository saenthanp/pricey, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saenthanp/pricey
- Repository: https://github.com/saenthanp/pricey

## Overview

##### Main Components
- Authentication Service – Manages logins, registrations, and OAuth 2.0 (Google Strategy) authentication.
- Link Service – Handles user-submitted links, sending messages to the Scrape Service via Kafka Streams, and also has GRPC endpoints.
- Jobs Service – Monitors and triggers scraping jobs; uses GRPC calls to notify the Link Service when a job is activated.
- Scrape Service – Implements a worker pool to perform scraping tasks concurrently, receiving work via Kafka streams.
- External/Supporting Components – Include Postgres databases for users, links, and job tracking; Kafka for asynchronous messaging; Nginx Ingress Controller for load-balancing and routing; and Kubernetes for container orchestration.

##### Relationships and Interactions
- Users interact with the system (likely via an API gateway exposed through Nginx) and authenticate using the Authentication Service.
- Once authenticated, users can submit links via the Link Service.
- Submitted links are pushed to the Scrape Service using Kafka streams for processing.
- The Jobs Service periodically checks the jobs database and, when a scraping trigger is due, sends a GRPC request to the Link Service.
- The Scrape Service uses a worker pool and Go concurrency (channels, go routines) to process the received jobs.
- All services are containerized (Docker) and orchestrated with Kubernetes, and configuration/deployment is managed via k8s YAML files.

##### Architectural Patterns and Principles
- Microservices architecture with clearly separated services, enabling scalability and independent deployment.
- Messaging-driven communication using Kafka for asynchronous tasks and GRPC for synchronous job triggering.
- Use of containerization (Docker) with orchestration through Kubernetes.
- A clear separation of concerns in the codebase (with distinct directories for configuration, service logic, models, repositories, etc.).

##### Technologies, Frameworks, and Libraries
- Language: Golang
- Messaging: Kafka Streams, GRPC
- Containerization: Docker and Kubernetes (with specific deployment YAMLs shown in the k8s directory)
- Authentication: OAuth 2.0 (Google Strategy)
- Database: Postgres
- Concurrency: Go built-in concurrency mechanisms (go routines, channels, wait groups)

##### Elements
- From users through the Ingress Controller to the Authentication Service.
- Between Authentication Service and other services (if applicable, e.g., secure token propagation).
- From the Link Service to Kafka and, in turn, from Kafka to the Scrape Service.
- From the Jobs Service, showing GRPC calls to the Link Service when jobs are triggered.
- Additional labels or legends:
- Annotations to call out elements like “OAuth 2.0,” “GRPC,” “Kafka Streams,” etc., to ensure clarity on the communication mechanisms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["Users"]:::external
    I["Nginx Ingress Controller"]:::external
    P["PostgreSQL Database"]:::database
    K["Kafka"]:::messaging
    D["Deployment Config"]:::external

    U -->|"HTTP"| I
    I -->|"HTTP"| A1
    I -->|"HTTP"| A2

    subgraph "Kubernetes Cluster"
        A1["Authentication Service"]:::microservice
        A2["Link Service"]:::microservice
        A3["Jobs Service"]:::microservice
        A4["Scrape Service"]:::microservice
    end

    A2 -->|"KafkaStream"| K
    K -->|"KafkaStream"| A4
    A3 -->|"GRPC"| A2

    A1 -->|"DBAccess"| P
    A2 -->|"DBAccess"| P
    A3 -->|"DBAccess"| P

    D --> A1
    D --> A2
    D --> A3
    D --> A4

    click A1 "https://github.com/saenthanp/pricey/tree/main/AuthenticationService"
    click A2 "https://github.com/saenthanp/pricey/tree/main/LinkService"
    click A3 "https://github.com/saenthanp/pricey/tree/main/JobsService"
    click A4 "https://github.com/saenthanp/pricey/tree/main/ScrapeService"
    click D "https://github.com/saenthanp/pricey/tree/main/k8s"

    classDef microservice fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef messaging fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
