# milkfrogge/coffee-store architecture

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

- Interactive diagram: https://gitdiagram.com/milkfrogge/coffee-store
- Repository: https://github.com/milkfrogge/coffee-store

## Overview

##### High-Level Architecture Overview

a) External Layer:
- API Gateway (HTTP:8000)
- Client Applications (Flutter UI)

b) Service Layer (with ports):
- ProductService (gRPC:5000) - Currently implemented
- AuthService (gRPC:5001)
- RoyaltyService (gRPC:5002)
- OrderService (gRPC:5003)
- StorageService (S3Minio:5004)
- BaristaService (HTTP:5005)
- KitchenService (HTTP:5006)

c) Infrastructure Layer:
- Message Brokers (for SAGA pattern)
- Individual Databases per service
- Observability Stack (Prometheus, Grafana, Jaeger, Graylog)

##### Detailed ProductService Architecture

a) API Layer:
- gRPC Service (product.proto, category.proto)
- Interceptors (timeout, tracing)

b) Internal Structure:
- Service Layer (internal/service/product)
- CRUD operations
- Validation
- Repository Layer (internal/repository/product)
- Postgres implementation
- Models (internal/model)
- Converters (internal/converter)

c) Database:
- PostgreSQL with migrations
- SQL queries for product operations

##### Observability Components

a) Monitoring:
- Prometheus metrics collection
- Grafana dashboards

b) Tracing:
- Jaeger client integration
- Trace flow through interceptors

c) Logging:
- Graylog integration

##### Important Details to Highlight

- SAGA pattern implementation
- Transactional outbox pattern
- Database-per-service architecture
- gRPC communication between services
- Observability integration points
- Role-based access control flow
- Message broker interaction points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "External Layer"
        Client["Client Applications\n(Flutter UI)"]:::client
        Gateway["API Gateway\n(HTTP:8000)"]:::gateway
    end

    subgraph "Service Layer"
        PS["ProductService\n(gRPC:5000)"]:::implemented
        click PS "https://github.com/milkfrogge/coffee-store/tree/develop/internal/service/product"
        AS["AuthService\n(gRPC:5001)"]:::planned
        RS["RoyaltyService\n(gRPC:5002)"]:::planned
        OS["OrderService\n(gRPC:5003)"]:::planned
        SS["StorageService\n(S3Minio:5004)"]:::planned
        BS["BaristaService\n(HTTP:5005)"]:::planned
        KS["KitchenService\n(HTTP:5006)"]:::planned
    end

    subgraph "ProductService Details"
        direction TB
        subgraph "API Layer"
            GRPC["gRPC Service"]:::api
            click GRPC "https://github.com/milkfrogge/coffee-store/tree/develop/api/product_v1"
            INT["Interceptors"]:::component
            click INT "https://github.com/milkfrogge/coffee-store/tree/develop/pkg/interceptors"
        end

        subgraph "Core Components"
            SVC["Service Layer"]:::component
            click SVC "https://github.com/milkfrogge/coffee-store/tree/develop/internal/service/product"
            REPO["Repository Layer"]:::component
            click REPO "https://github.com/milkfrogge/coffee-store/tree/develop/internal/repository/product/postgres"
            MOD["Models"]:::component
            click MOD "https://github.com/milkfrogge/coffee-store/blob/develop/internal/model/product.go"
            CONV["Converters"]:::component
            click CONV "https://github.com/milkfrogge/coffee-store/blob/develop/internal/converter/product.go"
        end

        subgraph "Database"
            PG["PostgreSQL"]:::database
            MIG["Migrations"]:::component
            click MIG "https://github.com/milkfrogge/coffee-store/tree/develop/db/migrations/product"
            SQL["SQL Queries"]:::component
            click SQL "https://github.com/milkfrogge/coffee-store/tree/develop/db/sql"
        end
    end

    subgraph "Observability Stack"
        PROM["Prometheus"]:::observability
        click PROM "https://github.com/milkfrogge/coffee-store/blob/develop/config/prometheus/prometheus.yml"
        GRAF["Grafana"]:::observability
        JAEG["Jaeger"]:::observability
        click JAEG "https://github.com/milkfrogge/coffee-store/blob/develop/pkg/jaeger/client.go"
        GRAY["Graylog"]:::observability
        click GRAY "https://github.com/milkfrogge/coffee-store/blob/develop/pkg/logger/graylog.go"
    end

    subgraph "Infrastructure"
        MB["Message Brokers\n(SAGA Pattern)"]:::infrastructure
        DB["Service Databases"]:::database
    end

    %% Connections
    Client --> Gateway
    Gateway --> PS
    Gateway --> AS
    Gateway --> RS
    Gateway --> OS
    Gateway --> SS
    Gateway --> BS
    Gateway --> KS

    PS --> MB
    AS --> MB
    RS --> MB
    OS --> MB
    SS --> MB
    BS --> MB
    KS --> MB

    PS -.-> PG
    GRPC --> SVC
    SVC --> REPO
    REPO --> PG
    REPO --> SQL
    PG --> MIG

    %% Observability Connections
    PS --> PROM
    PS --> JAEG
    PS --> GRAY
    PROM --> GRAF

    %% Styles
    classDef client fill:#E1F5FE,stroke:#0288D1
    classDef gateway fill:#E8F5E9,stroke:#388E3C
    classDef implemented fill:#C8E6C9,stroke:#388E3C
    classDef planned fill:#FFECB3,stroke:#FFA000
    classDef api fill:#E8EAF6,stroke:#3F51B5
    classDef component fill:#F3E5F5,stroke:#7B1FA2
    classDef database fill:#FFEBEE,stroke:#D32F2F
    classDef infrastructure fill:#FFF3E0,stroke:#E65100
    classDef observability fill:#F3E5F5,stroke:#7B1FA2
```
