# takuma123-type/go-api-study architecture

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

- Interactive diagram: https://gitdiagram.com/takuma123-type/go-api-study
- Repository: https://github.com/takuma123-type/go-api-study

## Overview

##### Project type and purpose
- This is a Go-based backend service implementing a RESTful API.
- It follows a Clean/Onion/Hexagonal architecture with clearly separated layers: domain, use cases, interface adapters, and infrastructure.
- It manages entities such as users, mentors, plans, contract requests, and contract approvals and persists them in MySQL via Docker.

##### File structure
- Top-level Docker configuration for Go and MySQL.
- src/domain: core entities, factories, IDs, repositories, and value objects (pure business logic).
- src/usecase: application/business rules (input DTOs → use case logic → output DTOs).
- src/interface: adapters
- controller: HTTP handlers
- database: repository implementations
- presenter: translates use case outputs to response models
- src/infra: framework & infrastructure
- router: HTTP routing layer
- middleware: error handling, transactions
- rdb: DB connection
- datamodel: ORM/DB schema models
- src/cmd/main.go: application entrypoint
- Tests and mocks under domain and mock.

##### Key architectural insights (from README/file tree)
- Clean Architecture: each layer depends only inward (interface → usecase → domain).
- Dependency inversion: controllers and repository impls depend on domain contracts.
- Dockerized deployment: service + MySQL companion container.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External
    HTTPClient(("API Gateway / HTTP Client")):::external
    DockerCompose(["Docker Compose"]):::infra
    GolangContainer(["Go App Container"]):::infra
    MySQLContainer(["MySQL Container"]):::external

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph "Router"
            Router["Router"]:::infra
        end
        subgraph "Middleware"
            Middleware["DB Transaction\nError Handling"]:::infra
        end
        RDB["RDB Connector"]:::infra
        Datamodels["Datamodels"]:::infra
    end

    %% Interface Adapters
    subgraph "Interface Adapters"
        Controllers["Controllers"]:::controller
        Presenters["Presenters"]:::controller
        RepoImpl["Repository Implementations"]:::controller
    end

    %% Application Layer
    subgraph "Use Case Interactors"
        UseCases["Use Case Interactors"]:::usecase
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DomainEntities["Entities & Repositories Interfaces"]:::domain
    end

    %% Connections
    HTTPClient -->|requests| Router
    Router -->|passes through| Middleware
    Middleware -->|invokes| Controllers
    Controllers -->|calls| UseCases
    UseCases -->|depends on| DomainEntities
    UseCases -->|uses| RepoImpl
    RepoImpl -->|uses| RDB
    RDB -->|reads/writes| Datamodels
    Datamodels -->|persistence| MySQLContainer

    %% Docker orchestration
    DockerCompose --> GolangContainer
    DockerCompose --> MySQLContainer
    GolangContainer -->|runs| Router

    %% Click Events
    click Router "https://github.com/takuma123-type/go-api-study/tree/main/src/infra/router"
    click Middleware "https://github.com/takuma123-type/go-api-study/tree/main/src/infra/middleware"
    click Controllers "https://github.com/takuma123-type/go-api-study/tree/main/src/interface/controller"
    click Presenters "https://github.com/takuma123-type/go-api-study/tree/main/src/interface/presenter"
    click RepoImpl "https://github.com/takuma123-type/go-api-study/tree/main/src/interface/database"
    click UseCases "https://github.com/takuma123-type/go-api-study/tree/main/src/usecase"
    click DomainEntities "https://github.com/takuma123-type/go-api-study/tree/main/src/domain"
    click RDB "https://github.com/takuma123-type/go-api-study/blob/main/src/infra/rdb/db.go"
    click Datamodels "https://github.com/takuma123-type/go-api-study/tree/main/src/infra/datamodel"
    click GolangContainer "https://github.com/takuma123-type/go-api-study/blob/main/docker/docker-compose.yml"

    %% Styles
    classDef external fill:#ffe599,stroke:#333,stroke-width:1px
    classDef infra fill:#d9d9d9,stroke:#333,stroke-width:1px
    classDef controller fill:#f4cccc,stroke:#333,stroke-width:1px
    classDef usecase fill:#d9ead3,stroke:#333,stroke-width:1px
    classDef domain fill:#c9daf8,stroke:#333,stroke-width:1px
```
