# codetheuri/poster-gen architecture

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

- Interactive diagram: https://gitdiagram.com/codetheuri/poster-gen
- Repository: https://github.com/codetheuri/poster-gen

## Overview

##### Project type and purpose
- Tusk is a Go-based starter template for building RESTful APIs.
- It follows a clean-architecture style: distinct layers for handlers (HTTP), services (business logic), repositories (data access), and models.
- It also ships with CLI tools (database migrations, seeders, module generator) and a set of shared packages (logging, middleware, validation, mailing).

##### File structure
- Top-level “cmd” directory
- cmd/main.go → launches the HTTP server
- cmd/migrate → database migrations & seeding CLI
- cmd/genmodule → scaffolds new API modules
- internal/bootstrap/app.go → application startup, wiring modules and middleware
- internal/app/… → per‐module folders (auth, posters) each with handlers, models, repositories, services, module.go
- internal/app/routers/router.go → central Chi router assembling module routes
- internal/platform/database/gorm.go → GORM setup, connection pooling
- database/… → actual SQLite data file (for dev), migration source, seeder definitions
- pkg/… → cross-cutting utilities: logging, errors, middleware, pagination, validation, web response helpers, mailer, token interface
- config/config.go → environment variable loading, global settings

##### Key insights from the README
- Uses Go-Chi for routing and middleware
- Uses GORM for ORM and auto-migrations
- JWT + Bcrypt for authentication
- Clean architecture enforced by layered modules
- CLI tools for migrations, seeding, module scaffolding

##### Final checklist
- All major components: Router, Middleware, Handlers, Services, Repositories, Database, CLI tools, Shared pkg libs
- Annotations for external systems (DB, mail server) and environment/config entry points

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Client
    Client["External Client"]:::external

    %% Configuration & Bootstrap
    subgraph "Configuration & Bootstrap"
        Main["API Server Entrypoint\n(cmd/main.go)"]:::infra
        Config["Configuration Loader\n(config/config.go)"]:::infra
        Bootstrap["Application Bootstrap\n(internal/bootstrap/app.go)"]:::infra
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        Router["HTTP Router (Chi)\n(internal/app/routers/router.go)"]:::frontend
        AuthMW["Authentication Middleware\n(pkg/middleware/auth_middleware.go)"]:::frontend
        LogMW["Logging Middleware\n(pkg/middleware/logger.go)"]:::frontend
        RecMW["Recovery Middleware\n(pkg/middleware/recovery.go)"]:::frontend
        ReqIDMW["RequestID Middleware\n(pkg/middleware/requestid.go)"]:::frontend
        subgraph "Handlers"
            AuthHandler["Auth Handler\n(internal/app/auth/handlers/handler.go)"]:::frontend
            PostersHandler["Posters Handler\n(internal/app/posters/handlers/handler.go)"]:::frontend
        end
    end

    %% Business Layer
    subgraph "Business Layer"
        AuthService["Auth Service\n(internal/app/auth/services/service.go)"]:::business
        PostersService["Posters Service\n(internal/app/posters/services/service.go)"]:::business
    end

    %% Data Layer
    subgraph "Data Layer"
        AuthRepo["Auth Repository\n(internal/app/auth/repositories/repository.go)"]:::data
        PostersRepo["Posters Repository\n(internal/app/posters/repositories/repository.go)"]:::data
        DBConnector["Database Connector\n(internal/platform/database/gorm.go)"]:::data
        Database[(Relational Database)]:::external
        Migrations["Migration Source Files\n(database/migrations)"]:::data
        Seeders["Seeder Definitions\n(database/seeders/seeder.go)"]:::data
    end

    %% CLI Tools
    subgraph "CLI Tools"
        MigrateCLI["Migration CLI Tool\n(cmd/migrate/main.go)"]:::cli
        GenModuleCLI["Module Generator CLI Tool\n(cmd/genmodule/main.go)"]:::cli
    end

    %% Shared Utilities
    subgraph "Shared Utilities (pkg)"
        LoggerUtil["Logger Utility\n(pkg/logger/logger.go)"]:::util
        ErrorsUtil["Errors Package\n(pkg/errors/errors.go)"]:::util
        MailerUtil["Mailer Utility\n(pkg/mailer/mailer.go)"]:::util
        PaginationUtil["Pagination Utility\n(pkg/pagination/pagination.go)"]:::util
        ValidatorUtil["Validator Utility\n(pkg/validators/validator.go)"]:::util
        WebUtil["Web Response Helpers\n(pkg/web/web.go)"]:::util
        TokenInterface["JWT Token Interface & Models\n(pkg/auth/token/interface.go, models.go)"]:::util
    end

    %% External Services
    MailService["SMTP / Mail Service"]:::external

    %% Data Flow & Dependencies
    Client --> Router
    Router --> AuthMW --> LogMW --> RecMW --> ReqIDMW
    ReqIDMW --> AuthHandler
    ReqIDMW --> PostersHandler

    AuthHandler --> AuthService
    PostersHandler --> PostersService

    AuthService --> AuthRepo
    PostersService --> PostersRepo

    AuthRepo --> DBConnector
    PostersRepo --> DBConnector
    DBConnector --> Database

    AuthService --> MailerUtil
    AuthService --> TokenInterface

    %% Startup Flow
    Main --> Config
    Main --> Bootstrap
    Bootstrap --> Router
    Bootstrap --> DBConnector
    Bootstrap --> LoggerUtil
    Bootstrap --> ErrorsUtil

    %% CLI Flows
    MigrateCLI --> Migrations
    MigrateCLI --> Seeders
    MigrateCLI --> DBConnector
    GenModuleCLI --> Bootstrap

    %% Shared Utils Dependencies
    AuthHandler --> ValidatorUtil
    PostersHandler --> ValidatorUtil
    AuthHandler --> ErrorsUtil
    PostersHandler --> ErrorsUtil
    Router --> WebUtil
    AuthMW --> TokenInterface
    AuthMW --> ErrorsUtil

    MailerUtil --> MailService

    %% Click Events
    click Main "https://github.com/codetheuri/poster-gen/blob/main/cmd/main.go"
    click Config "https://github.com/codetheuri/poster-gen/blob/main/config/config.go"
    click Bootstrap "https://github.com/codetheuri/poster-gen/blob/main/internal/bootstrap/app.go"
    click Router "https://github.com/codetheuri/poster-gen/blob/main/internal/app/routers/router.go"
    click AuthMW "https://github.com/codetheuri/poster-gen/blob/main/pkg/middleware/auth_middleware.go"
    click LogMW "https://github.com/codetheuri/poster-gen/blob/main/pkg/middleware/logger.go"
    click RecMW "https://github.com/codetheuri/poster-gen/blob/main/pkg/middleware/recovery.go"
    click ReqIDMW "https://github.com/codetheuri/poster-gen/blob/main/pkg/middleware/requestid.go"
    click AuthHandler "https://github.com/codetheuri/poster-gen/blob/main/internal/app/auth/handlers/handler.go"
    click AuthService "https://github.com/codetheuri/poster-gen/blob/main/internal/app/auth/services/service.go"
    click AuthRepo "https://github.com/codetheuri/poster-gen/blob/main/internal/app/auth/repositories/repository.go"
    click PostersHandler "https://github.com/codetheuri/poster-gen/blob/main/internal/app/posters/handlers/handler.go"
    click PostersService "https://github.com/codetheuri/poster-gen/blob/main/internal/app/posters/services/service.go"
    click PostersRepo "https://github.com/codetheuri/poster-gen/blob/main/internal/app/posters/repositories/repository.go"
    click DatabaseConnector "https://github.com/codetheuri/poster-gen/blob/main/internal/platform/database/gorm.go"
    click Migrations "https://github.com/codetheuri/poster-gen/tree/main/database/migrations"
    click Seeders "https://github.com/codetheuri/poster-gen/blob/main/database/seeders/seeder.go"
    click MigrateCLI "https://github.com/codetheuri/poster-gen/blob/main/cmd/migrate/main.go"
    click GenModuleCLI "https://github.com/codetheuri/poster-gen/blob/main/cmd/genmodule/main.go"
    click LoggerUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/logger/logger.go"
    click ErrorsUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/errors/errors.go"
    click MailerUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/mailer/mailer.go"
    click PaginationUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/pagination/pagination.go"
    click ValidatorUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/validators/validator.go"
    click WebUtil "https://github.com/codetheuri/poster-gen/blob/main/pkg/web/web.go"
    click TokenInterface "https://github.com/codetheuri/poster-gen/blob/main/pkg/auth/token/interface.go"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#5DADE2
    classDef business fill:#D5F5E3,stroke:#52BE80
    classDef data fill:#FDEBD0,stroke:#F5B041
    classDef infra fill:#E5E7E9,stroke:#566573
    classDef cli fill:#EBDEF0,stroke:#8E44AD
    classDef util fill:#FCF3CF,stroke:#F4D03F
    classDef external fill:#F2F3F4,stroke:#A6ACAF
```
