# evrone/go-clean-template architecture

> Architecture diagram of the GitHub repository evrone/go-clean-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evrone/go-clean-template
- Repository: https://github.com/evrone/go-clean-template

## Overview

##### Main Components

a) External Layer (Infrastructure):
- HTTP Server (Gin Framework)
- RabbitMQ RPC Server
- PostgreSQL Database
- External Web APIs (Google Translation)

b) Controller Layer:
- HTTP Controllers (v1)
- AMQP RPC Controllers

c) Business Logic Layer:
- Use Cases
- Interfaces
- Repositories

d) Entity Layer (Core):
- Domain Models/Entities

##### Connection and Flow Representation

a) Dependencies:
- All dependencies should point inward towards the core
- Use interface boundaries between layers

b) Data Flow:
- How data travels through layers:
- HTTP Request → Controller → UseCase → Repository → Database
- RPC Request → AMQP Controller → UseCase → External API

##### Specific Implementation Details

a) HTTP Flow:
**External → HTTP Server → v1.Router → Translation Controller →**
**Translation UseCase → Repository Interface → Postgres Repository**

b) RPC Flow:
**External → RabbitMQ Server → AMQP Router → Translation Controller →**
**Translation UseCase → Repository Interface → Postgres Repository**

##### Additional Elements

- Configuration Components
- Logger Service
- Migration Tools
- Integration Test Components

##### Notes for Implementation

- Dependency inversion principle
- Clear separation between layers
- Interface boundaries between components
- Configuration flow
- Error handling paths

Remember to include the key packages from the project structure:
- cmd/app
- internal/controller (http/v1 and amqp_rpc)
- internal/usecase
- internal/entity
- pkg/* (infrastructure components)

This will provide a comprehensive view of the system's architecture while maintaining the clean architecture principles evident in the project structure.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Client(["Client"])
        ExtAPI["Google Translate API"]:::external
    end

    subgraph Infrastructure
        HTTP["HTTP Server"]:::infra
        RMQ["RabbitMQ RPC Server"]:::infra
        DB[(PostgreSQL)]:::db
        Logger["Logger Service"]:::infra
        Config["Configuration"]:::infra
    end

    subgraph Controllers
        HTTPCtrl["HTTP Controller v1"]:::controller
        RPCCtrl["AMQP RPC Controller"]:::controller
    end

    subgraph "Business Logic"
        UseCase["Translation UseCase"]:::usecase
        RepoInterface["Repository Interface"]:::interface
        WebAPIInterface["WebAPI Interface"]:::interface
    end

    subgraph "Core Domain"
        Entity["Translation Entity"]:::entity
    end

    subgraph Implementation
        RepoImpl["PostgreSQL Repository"]:::impl
        WebAPIImpl["Google Translation API Client"]:::impl
    end

    %% Connections
    Client --> HTTP
    Client --> RMQ
    HTTP --> HTTPCtrl
    RMQ --> RPCCtrl
    HTTPCtrl --> UseCase
    RPCCtrl --> UseCase
    UseCase --> RepoInterface
    UseCase --> WebAPIInterface
    UseCase --> Entity
    RepoInterface --> RepoImpl
    WebAPIInterface --> WebAPIImpl
    RepoImpl --> DB
    WebAPIImpl --> ExtAPI
    Config -.-> HTTP
    Config -.-> RMQ
    Config -.-> DB
    Logger -.-> HTTP
    Logger -.-> RMQ
    Logger -.-> UseCase

    %% Click Events
    click HTTP "https://github.com/evrone/go-clean-template/blob/master/pkg/httpserver/server.go"
    click RMQ "https://github.com/evrone/go-clean-template/blob/master/pkg/rabbitmq/rmq_rpc/server/server.go"
    click DB "https://github.com/evrone/go-clean-template/blob/master/pkg/postgres/postgres.go"
    click WebAPIImpl "https://github.com/evrone/go-clean-template/blob/master/internal/usecase/webapi/translation_google.go"
    click HTTPCtrl "https://github.com/evrone/go-clean-template/blob/master/internal/controller/http/v1/translation.go"
    click RPCCtrl "https://github.com/evrone/go-clean-template/blob/master/internal/controller/amqp_rpc/translation.go"
    click UseCase "https://github.com/evrone/go-clean-template/blob/master/internal/usecase/translation.go"
    click RepoInterface "https://github.com/evrone/go-clean-template/blob/master/internal/usecase/interfaces.go"
    click RepoImpl "https://github.com/evrone/go-clean-template/blob/master/internal/usecase/repo/translation_postgres.go"
    click Entity "https://github.com/evrone/go-clean-template/blob/master/internal/entity/translation.go"
    click Config "https://github.com/evrone/go-clean-template/blob/master/config/config.go"
    click Logger "https://github.com/evrone/go-clean-template/blob/master/pkg/logger/logger.go"

    %% Styles
    classDef infra fill:#2374ab
    classDef controller fill:#48a9a6
    classDef usecase fill:#e4cc37
    classDef interface fill:#d3d3d3,stroke-dasharray: 5 5
    classDef entity fill:#d64933
    classDef impl fill:#4caf50
    classDef external fill:#9c27b0
    classDef db fill:#1a73e8,stroke:#0d47a1

    %% Legend
    subgraph Legend
        L1["Infrastructure"]:::infra
        L2["Controllers"]:::controller
        L3["Use Cases"]:::usecase
        L4["Interfaces"]:::interface
        L5["Core Entities"]:::entity
        L6["Implementation"]:::impl
        L7["External Services"]:::external
        L8[(Database)]:::db
    end
```
