# vanthen60hz/thinkflow-service architecture

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

- Interactive diagram: https://gitdiagram.com/vanthen60hz/thinkflow-service
- Repository: https://github.com/vanthen60hz/thinkflow-service

## Overview

##### Main Components Identification
- API Gateway – Found in the “gateway” directory with its JSON configuration files and tyk.standalone.conf. This component manages routing and possibly load-balancing between external clients and the backend services.
- Microservices – There are at least five major microservices:
– auth-service: Handles user authentication and authorization, including login, register, password reset, and related operations.
– gen-service: Likely handles “generation” functionality (e.g., mindmap, summary, transcript), given the clearly separated services under it.
– media-service: Manages media content processing. It includes sub-services for audio and image handling and even upload functionalities (with S3 uploader included).
– note-service: Manages notes and text content, supporting create, update, delete, and read operations.
– user-service: Manages user data and profiles.
- Shared Infrastructure – Look for a common database component (as indicated by presence of a “data.sql” file and MySQL repository implementations in each service) and a possible caching system (evidence via Redis usage in some services’ common code).
- External Integrations – Although not explicitly detailed, observe that each service defines both API (HTTP) and RPC (via gRPC) structures using their “proto” folders and the corresponding generated code. This indicates internal communications across services through gRPC.

##### Relationships and Interactions
- The API Gateway serves as the front door (exposed via http://localhost or port 8080 per README) that routes incoming external requests to the appropriate service.
– External (client-to-gateway) interaction.
– Internal (service-to-service) communication, emphasizing gRPC calls.
- Services might interact with each other (for instance, media-service’s audio repository calling out to client services in mindmap, summary, transcript, or even user interactions) using RPC clients (visible in composer folders and repository subdirectories).
- Docker and Docker Compose orchestration imply containerized deployments. Show that each service (and the gateway, databases, and supporting services like Redis) are deployed in their own container.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Emphasize that each service (auth, gen, media, note, user) is independently deployed and encapsulated with its own business logic, repository (MySQL/RPC), and transport layers (HTTP API and gRPC).
- Separation of Concerns: The structure—dividing the business logic, entity definitions, repositories, and transports—demonstrates adherence to a layered approach.
- Use of gRPC and Protocol Buffers: This explicitly shows an emphasis on inter-service communication efficiency and contract-first design.
- Containerization with Docker: The presence of Dockerfiles in every service and a docker-compose configuration signals a container orchestration design.

##### Technical Stack Components to Annotate
- Go (Golang) as the base language for development.
- Docker & Docker Compose for containerization.
- gRPC & Protocol Buffers for service-to-service RPC.
- MySQL (implied by “mysql” directories and “data.sql”) as the primary datastore.
- API Gateway (potentially Tyk, as indicated by the tyk.standalone.conf file) to manage routing and external API policies.
- Possibly Redis, as mentioned in some helper modules (common/redis.go).

##### Ensuring Clearer Seams
- Inter-service boundaries by placing the services in grouped sections, so that the separations between their responsibilities are visually apparent.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        Client["Client (Browser/External)"]:::client
        Gateway["API Gateway"]:::gateway
    end

    %% Application/Service Layer
    subgraph "Application/Service Layer"
        Auth["Auth-Service"]:::service
        Generation["Gen-Service"]:::service
        Media["Media-Service"]:::service
        Note["Note-Service"]:::service
        User["User-Service"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        Database["MySQL Database"]:::database
        Cache["Redis Cache"]:::cache
    end

    %% Client to Gateway (External HTTP Traffic)
    Client -->|"HTTP"| Gateway

    %% Gateway routing to Microservices via HTTP API calls
    Gateway -->|"HTTP"| Auth
    Gateway -->|"HTTP"| Generation
    Gateway -->|"HTTP"| Media
    Gateway -->|"HTTP"| Note
    Gateway -->|"HTTP"| User

    %% Inter-service communication using gRPC (Bidirectional)
    Generation <-->|"gRPC"| Auth
    Generation <-->|"gRPC"| User
    Media <-->|"gRPC"| Auth
    Note <-->|"gRPC"| User

    %% Microservices interactions with the Data Layer
    Auth -->|"DBQuery"| Database
    Generation -->|"DBQuery"| Database
    Media -->|"DBQuery"| Database
    Note -->|"DBQuery"| Database
    User -->|"DBQuery"| Database

    %% Services optionally using Cache
    Auth -->|"Cache"| Cache
    Generation -->|"Cache"| Cache
    Media -->|"Cache"| Cache
    Note -->|"Cache"| Cache
    User -->|"Cache"| Cache

    %% Click Events (Component Mapping)
    click Gateway "https://github.com/vanthen60hz/thinkflow-service/blob/main/gateway/tyk.standalone.conf"
    click Auth "https://github.com/vanthen60hz/thinkflow-service/tree/main/auth-service/"
    click Generation "https://github.com/vanthen60hz/thinkflow-service/tree/main/gen-service/"
    click Media "https://github.com/vanthen60hz/thinkflow-service/tree/main/media-service/"
    click Note "https://github.com/vanthen60hz/thinkflow-service/tree/main/note-service/"
    click User "https://github.com/vanthen60hz/thinkflow-service/tree/main/user-service/"
    click Database "https://github.com/vanthen60hz/thinkflow-service/blob/main/data.sql"

    %% Styles (Color Coding for Clearer Seams)
    classDef client fill:#f4a261,stroke:#e76f51,stroke-width:2px;
    classDef gateway fill:#2a9d8f,stroke:#264653,stroke-width:2px;
    classDef service fill:#e9c46a,stroke:#f4a261,stroke-width:2px;
    classDef database fill:#e76f51,stroke:#264653,stroke-width:2px;
    classDef cache fill:#8ab17d,stroke:#2a9d8f,stroke-width:2px;
```
