# alvidofaisal/internal-transfers-api architecture

> Architecture diagram of the GitHub repository alvidofaisal/internal-transfers-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alvidofaisal/internal-transfers-api
- Repository: https://github.com/alvidofaisal/internal-transfers-api

## Overview

##### Project type and purpose
- This is a standalone Go microservice (“Internal Transfers API”) for handling account management and money transfers with PostgreSQL, designed to run in Docker.
- It exposes a REST HTTP API (health checks, account CRUD, single & bulk transactions) and guarantees ACID semantics at SERIALIZABLE isolation.

##### File structure
Top-level artifacts:
- cmd/server/main.go – the entrypoint HTTP server
- internal/… – hexagonal architecture layers:
– config/config.go
– handler/*.go (HTTP adapters)
– service/*.go (business logic)
– repository/*.go (DB adapters)
– model/*.go (domain/data structures)
- migrations/ – SQL schema definitions
- Dockerfile, docker-compose.yml, Makefile – container build & orchestration
- .github/workflows/ci.yml – CI pipeline

##### README for additional insights
- Confirms hexagonal pattern: Handler → Service → Repository → PostgreSQL
- Highlights key features: ACID, row-level locking, SERIALIZABLE, NUMERIC precision
- Shows runtime stack: Go 1.21, Postgres, Docker
- Provides environment variables, API endpoints, testing commands

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    APIClient["API Client (curl/other services)"]:::external

    %% Docker Compose Network
    subgraph "Docker Compose Network"
        direction TB
        subgraph "HTTP Server Container\n(Internal Transfers API)" 
            direction TB
            mainEntrypoint["Entrypoint: cmd/server/main.go"]:::infra
            configLoader["Config Loader\ninternal/config/config.go"]:::infra
            subgraph "Handler Layer\n(HTTP Adapters)"
                direction TB
                healthHandler["health.go"]:::http
                accountHandler["account.go"]:::http
                transactionHandler["transaction.go"]:::http
            end
            subgraph "Service Layer\n(Business Logic)"
                direction TB
                accountService["account.go"]:::business
                transactionService["transaction.go"]:::business
            end
            subgraph "Repository Layer\n(DB Adapters)"
                direction TB
                accountRepo["account.go"]:::db
                transactionRepo["transaction.go"]:::db
                idempotencyRepo["idempotency.go"]:::db
                errorsRepo["errors.go"]:::db
            end
            subgraph "Domain Models"
                direction TB
                modelAccount["account.go"]:::model
                modelTransaction["transaction.go"]:::model
                modelResponse["response.go"]:::model
            end
            migrations["DB Migrations\nmigrations/001_create_schema.sql"]:::infra
        end
        postgres["PostgreSQL DB"]:::db
    end

    %% Connections
    APIClient -->|"HTTP/JSON"| mainEntrypoint
    mainEntrypoint --> configLoader
    configLoader --> healthHandler
    configLoader --> accountHandler
    configLoader --> transactionHandler
    healthHandler --> accountService
    accountHandler --> accountService
    transactionHandler --> transactionService
    accountService --> accountRepo
    transactionService --> transactionRepo
    accountRepo --> postgres
    transactionRepo --> postgres
    idempotencyRepo --> postgres
    migrations --> postgres

    %% Click Events
    click mainEntrypoint "https://github.com/alvidofaisal/internal-transfers-api/blob/main/cmd/server/main.go"
    click configLoader "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/config/config.go"
    click healthHandler "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/handler/health.go"
    click accountHandler "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/handler/account.go"
    click transactionHandler "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/handler/transaction.go"
    click accountService "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/service/account.go"
    click transactionService "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/service/transaction.go"
    click accountRepo "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/repository/account.go"
    click transactionRepo "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/repository/transaction.go"
    click idempotencyRepo "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/repository/idempotency.go"
    click errorsRepo "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/repository/errors.go"
    click modelAccount "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/model/account.go"
    click modelTransaction "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/model/transaction.go"
    click modelResponse "https://github.com/alvidofaisal/internal-transfers-api/blob/main/internal/model/response.go"
    click migrations "https://github.com/alvidofaisal/internal-transfers-api/blob/main/migrations/001_create_schema.sql"
    click .githubCI "https://github.com/alvidofaisal/internal-transfers-api/blob/main/.github/workflows/ci.yml"
    click demo "https://github.com/alvidofaisal/internal-transfers-api/blob/main/demo.sh"
    click dockerfile "https://github.com/alvidofaisal/internal-transfers-api/tree/main/Dockerfile"
    click compose "https://github.com/alvidofaisal/internal-transfers-api/blob/main/docker-compose.yml"
    click makefile "https://github.com/alvidofaisal/internal-transfers-api/tree/main/Makefile"
    click gomod "https://github.com/alvidofaisal/internal-transfers-api/blob/main/go.mod"
    click gosum "https://github.com/alvidofaisal/internal-transfers-api/blob/main/go.sum"

    %% Styles
    classDef external fill:#87CEEB,stroke:#000,stroke-width:1px
    classDef http fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef business fill:#90EE90,stroke:#000,stroke-width:1px
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef model fill:#FFFACD,stroke:#000,stroke-width:1px
```
