# zhashkevych/todo-app architecture

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

- Interactive diagram: https://gitdiagram.com/zhashkevych/todo-app
- Repository: https://github.com/zhashkevych/todo-app

## Overview

##### Main Components

A. External Layer (Client Interface)
- REST API Endpoints (using Gin Framework)
- Swagger Documentation (noted from docs/ directory)

B. Application Layers (following Clean Architecture):
1. Handler Layer (Controllers)
- Auth Handler
- Item Handler
- Handler
- Middleware

2. Service Layer (Business Logic)
- Auth Service
- Todo Item Service
- Todo List Service

3. Repository Layer (Data Access)
- PostgreSQL Repositories
- Auth Repository
- Todo Item Repository
- Todo List Repository

C. Infrastructure
- PostgreSQL Database
- JWT Authentication
- Configuration Management (Viper)

**[Client/External Requests] (Top)**
- ↓
**[API Layer (Gin Framework + Middleware)]**
- ↓
**[Service Layer]**
- ↓
**[Repository Layer]**
- ↓
**[Database Layer] (Bottom)**

##### Specific Elements

a) API Layer:
- Main endpoint groups (/auth, /items, /lists)
- Middleware placement
- Swagger integration

b) Service Layer:
- Separation of concerns between auth, items, and lists
- Service interfaces and implementations
- Where business logic resides

c) Repository Layer:
- PostgreSQL connection handling
- Database models (user.go, todo.go)
- Migration handling

d) Infrastructure:
- Configuration management (configs/config.yml)
- Docker container relationships
- Graceful Shutdown handling

##### Technical Details to Highlight

- Gin Framework as the HTTP router
- JWT for authentication
- SQLx for database operations
- Viper for configuration
- Docker for containerization
- Migration handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#388E3C,color:white
    classDef repo fill:#FFC107,stroke:#FFA000,color:black
    classDef infra fill:#9E9E9E,stroke:#616161,color:white
    classDef security fill:#F44336,stroke:#D32F2F,color:white
    classDef test fill:#673AB7,stroke:#512DA8,color:white
    classDef config fill:#795548,stroke:#5D4037,color:white

    %% External Layer
    Client([Client Requests])
    SwaggerDocs["Swagger Documentation"]:::api
    click SwaggerDocs "https://github.com/zhashkevych/todo-app/blob/master/docs/swagger.json"

    %% Main Application
    MainApp["Main Application"]:::api
    click MainApp "https://github.com/zhashkevych/todo-app/blob/master/cmd/main.go"
    ServerConfig["Server Configuration"]:::config
    click ServerConfig "https://github.com/zhashkevych/todo-app/blob/master/server.go"

    %% API Layer
    subgraph API
        GinRouter["Gin Router"]
        AuthHandler["Auth Handler"]:::api
        ItemHandler["Item Handler"]:::api
        ListHandler["List Handler"]:::api
        Middleware["Middleware"]:::security
        
        click AuthHandler "https://github.com/zhashkevych/todo-app/blob/master/pkg/handler/auth.go"
        click ItemHandler "https://github.com/zhashkevych/todo-app/blob/master/pkg/handler/item.go"
        click ListHandler "https://github.com/zhashkevych/todo-app/blob/master/pkg/handler/list.go"
        click Middleware "https://github.com/zhashkevych/todo-app/blob/master/pkg/handler/middleware.go"
    end

    %% Service Layer
    subgraph Services
        AuthService["Auth Service"]:::service
        ItemService["Todo Item Service"]:::service
        ListService["Todo List Service"]:::service
        
        click AuthService "https://github.com/zhashkevych/todo-app/blob/master/pkg/service/auth.go"
        click ItemService "https://github.com/zhashkevych/todo-app/blob/master/pkg/service/todo_item.go"
        click ListService "https://github.com/zhashkevych/todo-app/blob/master/pkg/service/todo_list.go"
    end

    %% Repository Layer
    subgraph Repositories
        AuthRepo["Auth Repository"]:::repo
        ItemRepo["Item Repository"]:::repo
        ListRepo["List Repository"]:::repo
        DBConn["Database Connection"]:::repo
        
        click AuthRepo "https://github.com/zhashkevych/todo-app/blob/master/pkg/repository/auth_postgres.go"
        click ItemRepo "https://github.com/zhashkevych/todo-app/blob/master/pkg/repository/todo_item_postgres.go"
        click ListRepo "https://github.com/zhashkevych/todo-app/blob/master/pkg/repository/todo_list_postgres.go"
        click DBConn "https://github.com/zhashkevych/todo-app/blob/master/pkg/repository/postgres.go"
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        PostgresDB[(PostgreSQL)]:::infra
        Config["Configuration"]:::config
        Migrations["DB Migrations"]:::infra
        Docker["Docker Container"]:::infra
        
        click Config "https://github.com/zhashkevych/todo-app/blob/master/configs/config.yml"
        click Migrations "https://github.com/zhashkevych/todo-app/blob/master/schema/000001_init.up.sql"
        click Docker "https://github.com/zhashkevych/todo-app/blob/master/docker-compose.yml"
    end

    %% Testing Components
    subgraph Testing
        HandlerTests["Handler Tests"]:::test
        RepoTests["Repository Tests"]:::test
        ServiceMocks["Service Mocks"]:::test
        
        click HandlerTests "https://github.com/zhashkevych/todo-app/blob/master/pkg/handler/auth_test.go"
        click RepoTests "https://github.com/zhashkevych/todo-app/blob/master/pkg/repository/auth_postgres_test.go"
        click ServiceMocks "https://github.com/zhashkevych/todo-app/blob/master/pkg/service/mocks/mock.go"
    end

    %% Relationships
    Client --> SwaggerDocs
    Client --> MainApp
    MainApp --> GinRouter
    GinRouter --> Middleware
    Middleware --> AuthHandler & ItemHandler & ListHandler
    
    AuthHandler --> AuthService
    ItemHandler --> ItemService
    ListHandler --> ListService
    
    AuthService --> AuthRepo
    ItemService --> ItemRepo
    ListService --> ListRepo
    
    AuthRepo & ItemRepo & ListRepo --> DBConn
    DBConn --> PostgresDB
    
    Config --> MainApp
    Migrations --> PostgresDB
    Docker --> PostgresDB
    
    %% Legend
    subgraph Legend
        API_Legend["API Component"]:::api
        Service_Legend["Service Component"]:::service
        Repo_Legend["Repository Component"]:::repo
        Infra_Legend["Infrastructure Component"]:::infra
        Security_Legend["Security Component"]:::security
        Test_Legend["Test Component"]:::test
    end
```
