# nurashi/aiforge architecture

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

- Interactive diagram: https://gitdiagram.com/nurashi/aiforge
- Repository: https://github.com/nurashi/aiforge

## Overview

##### Project type and purpose
- This is a Go-based, Dockerized microservices system comprising an API Gateway plus two backend services (Auth Service and User Service).
- The API Gateway exposes a unified HTTP interface to clients, forwarding requests to the appropriate microservice.
- The Auth Service handles OAuth login flows, session management (Redis), and user authentication.
- The User Service manages user profiles and project entities.

##### File structure
- Top-level folders:
- api-gateway – reverse proxy, routing, auth middleware
- auth-service – OAuth callbacks, session store, user repository
- user-service – CRUD handlers for user data and projects
- scripts/init-db.sql – initial database schema
- docker-compose.yml – service definitions and networking
- Common sub-folders in each service: config, database, handlers, middleware, internal/app, repository, models, main.go and Dockerfile.
- Services use Redis (session), likely PostgreSQL or MySQL for persistent storage (see init-db.sql).
- Each service reads config.yml via a config.go loader.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["Clients\n(Web/Mobile)"]:::external

    %% Docker-Compose Network Boundary
    subgraph "Docker-Compose Network"
        direction TB

        %% API Gateway Service
        subgraph "API Gateway Service"
            direction TB
            APIGW["API Gateway\n(Port: 8000)"]:::gateway
            GWMain["main.go"]:::gateway
            ConfigGW["config/config.go"]:::gateway
            ConfigYMLGW["config/config.yml"]:::gateway
            Routes["handlers/routes.go"]:::gateway
            Proxy["handlers/proxy.go"]:::gateway
            AuthMW["middleware/auth.go"]:::gateway
            DockerfileGW["Dockerfile"]:::gateway
        end

        %% Auth Service
        subgraph "Auth Service"
            direction TB
            AuthSvc["Auth Service\n(Port: 8001)"]:::auth
            AuthMain["main.go"]:::auth
            ConfigAuth["config/config.go"]:::auth
            ConfigYMLAuth["config/config.yml"]:::auth
            DBLayerAuth["database/database.go"]:::auth
            OAuthHandler["handlers/oauth.go"]:::auth
            CallbackHandler["handlers/callback.go"]:::auth
            LogoutHandler["handlers/logout.go"]:::auth
            GoogleOAuth["oauth/google.go"]:::auth
            TokenVal["oauth/tokenValidator.go"]:::auth
            UserRepoAuth["repository/userRepo.go"]:::auth
            SessionMgr["session/manager.go"]:::auth
            SessionRedis["session/redis.go"]:::auth
            AppLogicAuth["internal/app/app.go"]:::auth
            DockerfileAuth["Dockerfile"]:::auth
        end

        %% User Service
        subgraph "User Service"
            direction TB
            UserSvc["User Service\n(Port: 8002)"]:::user
            UserMain["main.go"]:::user
            ConfigUser["config/config.go"]:::user
            ConfigYMLUser["config/config.yml"]:::user
            DBLayerUser["database/database.go"]:::user
            RoutesUser["handlers/routes.go"]:::user
            ProjectHandler["handlers/project.go"]:::user
            ProjectRepo["repository/project.go"]:::user
            UserModel["models/user_profile.go"]:::user
            AuthMWUser["middleware/auth.go"]:::user
            AppLogicUser["internal/app/app.go"]:::user
            DockerfileUser["Dockerfile"]:::user
        end

        %% Shared Infrastructure
        subgraph "Infrastructure"
            direction TB
            AuthDB((Auth DB)):::infra
            UserDB((User DB)):::infra
            Redis((Redis Session Store)):::infra
        end
    end

    %% External OAuth Provider
    OAuth["OAuth Provider\n(e.g., Google)"]:::external

    %% Data Flows
    Clients -->|HTTP| APIGW
    APIGW -->|HTTP| AuthSvc
    APIGW -->|HTTP| UserSvc
    AuthSvc -->|OAuth Token Exchange| OAuth
    AuthSvc -->|SQL| AuthDB
    AuthSvc -->|Redis| Redis
    UserSvc -->|SQL| UserDB

    %% Click Events for API Gateway
    click APIGW "https://github.com/nurashi/aiforge/tree/main/api-gateway/"
    click GWMain "https://github.com/nurashi/aiforge/blob/main/api-gateway/main.go"
    click ConfigGW "https://github.com/nurashi/aiforge/blob/main/api-gateway/config/config.go"
    click ConfigYMLGW "https://github.com/nurashi/aiforge/blob/main/api-gateway/config/config.yml"
    click Routes "https://github.com/nurashi/aiforge/blob/main/api-gateway/handlers/routes.go"
    click Proxy "https://github.com/nurashi/aiforge/blob/main/api-gateway/handlers/proxy.go"
    click AuthMW "https://github.com/nurashi/aiforge/blob/main/api-gateway/middleware/auth.go"
    click DockerfileGW "https://github.com/nurashi/aiforge/tree/main/api-gateway/Dockerfile"

    %% Click Events for Auth Service
    click AuthSvc "https://github.com/nurashi/aiforge/tree/main/auth-service/"
    click AuthMain "https://github.com/nurashi/aiforge/blob/main/auth-service/main.go"
    click ConfigAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/config/config.go"
    click ConfigYMLAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/config/config.yml"
    click DBLayerAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/database/database.go"
    click OAuthHandler "https://github.com/nurashi/aiforge/blob/main/auth-service/handlers/oauth.go"
    click CallbackHandler "https://github.com/nurashi/aiforge/blob/main/auth-service/handlers/callback.go"
    click LogoutHandler "https://github.com/nurashi/aiforge/blob/main/auth-service/handlers/logout.go"
    click GoogleOAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/oauth/google.go"
    click TokenVal "https://github.com/nurashi/aiforge/blob/main/auth-service/oauth/tokenValidator.go"
    click UserRepoAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/repository/userRepo.go"
    click SessionMgr "https://github.com/nurashi/aiforge/blob/main/auth-service/session/manager.go"
    click SessionRedis "https://github.com/nurashi/aiforge/blob/main/auth-service/session/redis.go"
    click AppLogicAuth "https://github.com/nurashi/aiforge/blob/main/auth-service/internal/app/app.go"
    click DockerfileAuth "https://github.com/nurashi/aiforge/tree/main/auth-service/Dockerfile"

    %% Click Events for User Service
    click UserSvc "https://github.com/nurashi/aiforge/tree/main/user-service/"
    click UserMain "https://github.com/nurashi/aiforge/blob/main/user-service/main.go"
    click ConfigUser "https://github.com/nurashi/aiforge/blob/main/user-service/config/config.go"
    click ConfigYMLUser "https://github.com/nurashi/aiforge/blob/main/user-service/config/config.yml"
    click DBLayerUser "https://github.com/nurashi/aiforge/blob/main/user-service/database/database.go"
    click RoutesUser "https://github.com/nurashi/aiforge/blob/main/user-service/handlers/routes.go"
    click ProjectHandler "https://github.com/nurashi/aiforge/blob/main/user-service/handlers/project.go"
    click ProjectRepo "https://github.com/nurashi/aiforge/blob/main/user-service/repository/project.go"
    click UserModel "https://github.com/nurashi/aiforge/blob/main/user-service/models/user_profile.go"
    click AuthMWUser "https://github.com/nurashi/aiforge/blob/main/user-service/middleware/auth.go"
    click AppLogicUser "https://github.com/nurashi/aiforge/blob/main/user-service/internal/app/app.go"
    click DockerfileUser "https://github.com/nurashi/aiforge/tree/main/user-service/Dockerfile"

    %% Click Events for Shared Infra
    click AuthDB "https://github.com/nurashi/aiforge/blob/main/scripts/init-db.sql"
    click Redis "https://github.com/nurashi/aiforge/blob/main/docker-compose.yml"
    click UserDB "https://github.com/nurashi/aiforge/blob/main/scripts/init-db.sql"

    %% Styles
    classDef external fill:#FFD700,stroke:#333,stroke-width:1px;
    classDef gateway fill:#89CFF0,stroke:#333,stroke-width:1px;
    classDef auth fill:#FFB6C1,stroke:#333,stroke-width:1px;
    classDef user fill:#98FB98,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
