# wesionaryteam/go_clean_architecture architecture

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

- Interactive diagram: https://gitdiagram.com/wesionaryteam/go_clean_architecture
- Repository: https://github.com/wesionaryteam/go_clean_architecture

## Overview

This project is a web server application built following Clean Architecture principles in Go. It uses the Gin Web Framework for API handling, uber-go/fx for dependency injection, and GORM for ORM support. The architecture is deliberately segmented into well-defined layers and modules to promote separation of concerns and testability.

##### Main Components Identification
- Entry Point & Bootstrapping: The starting point is main.go, which initializes the application. The bootstrap/ directory contains modules needed for application startup (e.g., dependency setup and service/module initialization).
- API Layer (Presentation Layer): Built with the Gin framework, this includes routing, controllers, and HTTP-related logic. For instance, files in domain/user (controller.go, route.go) handle user-specific API endpoints.
- Domain Layer (Business Logic): Located in domain/, this holds the business entities (models), constants, and domain-specific functionalities like user business logic including repositories and services.
- Infrastructure Layer: Housed in pkg/infrastructure, this layer covers connections to external systems such as databases (db.go) and AWS services—and integrates third-party services (Firebase, S3, SES, etc.).
- Services & Utilities: The pkg/services directory encapsulates core functionalities (like cognito, s3, ses service) that support the business logic, whereas pkg/utils and pkg/types offer helper functions and shared data type definitions.
- Middlewares: Found in pkg/middlewares, these components intercept HTTP requests to provide cross-cutting functionalities like authentication, rate limiting, and request uploads.
- Console & CLI Tools: The console/ directory includes entry points for running server commands, which can be used for tasks beyond the typical API serving.
- Database & Migrations: Migrations are located under migrations/, and database configuration is defined in dbconfig.yml, aligning with the overall persistence strategy.
- Docker & Deployment: Docker-related files (docker/, docker-compose.yml) indicate containerization support, which can be modeled as an external boundary for deployment, ensuring proper environment isolation.

##### Relationships & Interactions
- The Client (or API consumer) sends HTTP requests to the server.
- The API Gateway (Gin) receives these requests, passing them through a chain of middlewares (authentication, rate limiting, etc.) before routing to the appropriate domain layer.
- Within the Domain layer, controllers invoke services (defined in domain/user and pkg/services) that encapsulate business logic.
- Services interact with repositories that handle database operations using GORM models found in domain/models.
- Infrastructure components (from pkg/infrastructure) facilitate external service integration (e.g., AWS connectivity, Firebase).
- Bootstrap modules initialize and wire dependencies (using uber-go/fx) ensuring loose coupling across layers.
- Console commands provide alternative entry points to run server commands, maintenance tasks, or seed initial data.

##### Architectural Patterns & Key Technologies
- Clean Architecture Layering: Separation into API/presentation, domain, and infrastructure layers.
- Dependency Injection: Uber’s fx is used for wiring modules and managing life cycles.
- MVC-like Structure: Controllers, services, and repository patterns for domain-related functionalities.
- External Services: Integration with AWS modules, Firebase, and third-party libraries like Gin, GORM.
- Containerization: Docker files and docker-compose setup show that the application is designed with deployment in isolated environments in mind.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry & Bootstrap
    subgraph "Entry & Bootstrap"
        A["Main Application (main.go)"]
        B["Bootstrap Initialization"]
    end

    %% External Client
    C["HTTP Client"]

    %% API / Presentation Layer
    subgraph "API / Presentation Layer"
        D["API Server (Gin)"]
        E["Middlewares"]
        F["User Controller (domain/user)"]
    end

    %% Domain / Business Logic Layer
    subgraph "Domain Layer"
        G["User Service (domain/user)"]
        H["User Repository (domain/user)"]
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        I["Database (GORM)"]
        J["Infrastructure Services (AWS, Firebase)"]
    end

    %% Services & Utilities
    subgraph "Services & Utilities"
        K["Services & Utilities"]
    end

    %% Console & CLI Tools
    subgraph "Console & CLI Tools"
        L["Console Commands"]
    end

    %% Database & Migrations
    subgraph "Database & Migrations"
        M["Database Config & Migrations"]
    end

    %% Docker & Deployment
    subgraph "Docker & Deployment"
        N["Docker & Deployment"]
    end

    %% Connections
    C --> D
    D --> E
    E --> F
    F --> G
    G --> H
    H --> I
    G --> K
    K --> J

    %% Dependency Injection / Bootstrapping flows
    B --> D
    B --> F
    B --> G
    B --> H
    B --> K
    B --> L
    N --> B
    L --> B

    %% Class Definitions for Color Styling
    class A entry;
    class B bootstrap;
    class C external;
    class D api;
    class E middle;
    class F api;
    class G domain;
    class H domain;
    class I db;
    class J infra;
    class K services;
    class L cli;
    class M db;
    class N docker;

    %% Styles
    classDef entry fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef bootstrap fill:#ffebcc,stroke:#333,stroke-width:2px;
    classDef external fill:#e3f2fd,stroke:#333,stroke-width:2px;
    classDef api fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef middle fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef domain fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef infra fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef services fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef cli fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef db fill:#e6ffe6,stroke:#333,stroke-width:2px;
    classDef docker fill:#d1c4e9,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/main.go"
    click B "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/bootstrap/app.go"
    click D "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/pkg/infrastructure/router.go"
    click F "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/domain/user/controller.go"
    click G "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/domain/user/service.go"
    click H "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/domain/user/repository.go"
    click I "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/pkg/infrastructure/db.go"
    click J "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/pkg/infrastructure/aws.go"
    click K "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/pkg/services/cognito.go"
    click E "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/pkg/middlewares/auth_middleware.go"
    click L "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/console/console.go"
    click M "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/dbconfig.yml"
    click N "https://github.com/wesionaryteam/go_clean_architecture/blob/develop/docker/docker-compose.yml"
```
