# trillyai/backend-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/trillyai/backend-microservices
- Repository: https://github.com/trillyai/backend-microservices

## Overview

##### Main Components Identification
- Core Infrastructure: This includes the common, foundational packages in the “core” directory (like auth, automapper, bootstrap, database, env, logger, middleware, etc.). These modules provide shared functionality and lower-level utilities for the overall system.
- Microservices: The individual services represent distinct functional domains:
- Auth Service (services/auth)
- Feed Service (services/feed)
- Interaction Service (services/interaction)
- Profile Service (services/profile)
- Trip Service (services/trip)
- Database: The project interfaces with a PostgreSQL database (see “core/database/postgres”) with table definitions under “core/database/tables”. It’s crucial to denote secure and optimized database interactions.
- Deployment and Containerization: The “deployment” and “docker” directories indicate that Dockerfiles exist for each service and Kubernetes configurations handle deployments, namespace isolation, secrets, ingress routing, etc.
- External/Supporting Services: Although not explicitly listed as “external” services, you may indicate other infrastructure (like load balancers or external API integrations in the future) as placeholders.

##### Relationships & Interactions
- Each microservice communicates with the shared core modules for configurations, logging, and middleware, ensuring consistency across the system.
- The database component serves as a centralized datastore accessed by the core’s database package, with each service possibly having its repository layer interacting with table-specific functions.
- Deployment layer (Docker and Kubernetes) that manages container orchestration, networking, secrets, and configuration management.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates concerns into “core” modules and domain-specific “services”. Each service further distinguishes its responsibilities into contracts, handlers, repositories, service logic, and shared utilities.
- Stateless Design: Emphasize that services are stateless to enable horizontal scaling, with persistent state managed through secure database interactions.
- Containerization & Orchestration: Illustrate the use of Docker (with individual Dockerfiles) and Kubernetes (with configurations for deployments, services, ingress, secrets, etc.) to manage application lifecycle.

##### Technologies, Frameworks, and Libraries to Highlight
- Language: Go (use of Go concurrency and error handling)
- Database: PostgreSQL with ORM/SQL optimizations in its database layer
- Containerization: Docker (individual Dockerfiles for each service)
- Orchestration: Kubernetes (multiple YAML configuration files for deployments, services, ingress, etc.)
- Logging and Middleware: Custom implementations under “core/logger” and “core/middleware”
- Automated tools: Possibly integrated testing and CI/CD practices based on the standard deployment practices mentioned

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer - Client
    Client["Client API"]:::client

    %% Application Services Layer
    subgraph "Application Services"
        AuthService["Auth Service"]:::service
        FeedService["Feed Service"]:::service
        InteractionService["Interaction Service"]:::service
        ProfileService["Profile Service"]:::service
        TripService["Trip Service"]:::service
    end

    %% Shared Core Layer
    Core["Shared Core Modules"]:::core

    %% Database Layer
    subgraph "Database"
        DB["PostgreSQL Database"]:::database
        DBSchema["DB Schema"]:::database
    end

    %% Deployment & Infrastructure Layer
    subgraph "Deployment & Infrastructure"
        Containerization["Containerization"]:::deployment
        Kubernetes["Kubernetes Orchestration"]:::deployment
    end

    %% Connections - Client to Services
    Client -->|"requests"| AuthService
    Client -->|"requests"| FeedService
    Client -->|"requests"| InteractionService
    Client -->|"requests"| ProfileService
    Client -->|"requests"| TripService

    %% Connections - Services to Shared Core and Database
    AuthService -->|"uses"| Core
    FeedService -->|"uses"| Core
    InteractionService -->|"uses"| Core
    ProfileService -->|"uses"| Core
    TripService -->|"uses"| Core

    AuthService -->|"queries"| DB
    FeedService -->|"queries"| DB
    InteractionService -->|"queries"| DB
    ProfileService -->|"queries"| DB
    TripService -->|"queries"| DB

    DB -->|"defines"| DBSchema

    %% Connections - Deployment Flow
    AuthService -->|"containerized"| Containerization
    FeedService -->|"containerized"| Containerization
    InteractionService -->|"containerized"| Containerization
    ProfileService -->|"containerized"| Containerization
    TripService -->|"containerized"| Containerization

    Containerization -->|"orchestrated by"| Kubernetes

    %% Click Events for Component Mapping
    click Core "https://github.com/trillyai/backend-microservices/tree/main/core"
    click AuthService "https://github.com/trillyai/backend-microservices/tree/main/services/auth"
    click FeedService "https://github.com/trillyai/backend-microservices/tree/main/services/feed"
    click InteractionService "https://github.com/trillyai/backend-microservices/tree/main/services/interaction"
    click ProfileService "https://github.com/trillyai/backend-microservices/tree/main/services/profile"
    click TripService "https://github.com/trillyai/backend-microservices/tree/main/services/trip"
    click DB "https://github.com/trillyai/backend-microservices/tree/main/core/database/postgres"
    click DBSchema "https://github.com/trillyai/backend-microservices/tree/main/core/database/tables"
    click Containerization "https://github.com/trillyai/backend-microservices/tree/main/docker"
    click Kubernetes "https://github.com/trillyai/backend-microservices/tree/main/deployment/kubernetes"

    %% Styles
    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef service fill:#ccf2ff,stroke:#333,stroke-width:2px;
    classDef core fill:#b3ffb3,stroke:#333,stroke-width:2px;
    classDef database fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ccccff,stroke:#333,stroke-width:2px;
```
