# stunext/goboilterplate architecture

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

- Interactive diagram: https://gitdiagram.com/stunext/goboilterplate
- Repository: https://github.com/stunext/goboilterplate

## Overview

##### Main Components

a. HTTP Layer:
- Router component (from app/router)
- Middleware chain (from app/middlewares):
- CORS
- GZIP
- JWT
- Logger
- Recovery
- Security
- Redirect

b. Application Layer:
- Controllers (from app/controllers)
- Home Controller
- Users Controller
- Helpers (from app/helpers)
- Auth Helper
- Validator Helper

c. Data Layer:
- Models (from app/models)
- User Model
- Profile Model
- Auth Model
- UserProfile Model
- Database Configuration (from config/database.go)
- Cache Configuration (from config/cache.go)

d. Additional Components:
- Console/Scheduler (from app/console)
- Documentation (Swagger)
- Test Suite

##### Relationship Flows

- Blue: HTTP/External Interface Layer
- Green: Application/Business Logic Layer
- Orange: Data/Persistence Layer
- Gray: Support Services

**[Client Requests] → [Echo HTTP Server]**
- ↓
**[Middleware Chain] → [Router Layer]**
- ↓
**[Controllers] ←→ [Helpers]**
- ↓
**[Models Layer] ←→ [GORM]**
- ↓
**[Database/Cache]**

##### Component Descriptions

Use these symbols and notations:
- Rectangles: Main components
- Hexagons: External services/interfaces
- Diamonds: Decision points (middleware)

##### Additional Elements

Supporting elements:
- Version information
- Environment configurations (.env)
- API endpoints grouping
- Middleware order of execution

##### Technical Details

- Echo framework integration points
- GORM database connections and pooling
- Middleware chain sequence
- Authentication flow
- Request/Response cycle
- Error handling paths

- The HTTP request lifecycle
- Authentication and authorization flow
- Data persistence patterns
- API structure and grouping
- Middleware functionality
- Testing boundaries

Remember to include a clear indication of:
- Entry points (HTTP, Console)
- Security boundaries
- Data flow directions
- Component dependencies
- Integration points

This will provide a comprehensive view of the system while maintaining clarity and usefulness for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CR[Client Requests]
    end

    subgraph "HTTP Layer"
        ES[Echo HTTP Server]
        RT["Router"]:::router

        subgraph "Middleware Chain"
            MW_CORS["CORS"]:::middleware
            MW_GZIP["GZIP"]:::middleware
            MW_JWT["JWT"]:::middleware
            MW_LOG["Logger"]:::middleware
            MW_REC["Recovery"]:::middleware
            MW_SEC["Security"]:::middleware
            MW_RED["Redirect"]:::middleware
        end
    end

    subgraph "Application Layer"
        subgraph "Controllers"
            HC["Home Controller"]:::controller
            UC["Users Controller"]:::controller
        end

        subgraph "Helpers"
            AH["Auth Helper"]:::helper
            VH["Validator Helper"]:::helper
        end
    end

    subgraph "Data Layer"
        subgraph "Models"
            UM["User Model"]:::model
            PM["Profile Model"]:::model
            AM["Auth Model"]:::model
            UPM["UserProfile Model"]:::model
        end

        DB[(Database)]
        CACHE[(Cache)]
        GORM["GORM ORM"]
    end

    subgraph "Support Services"
        CON["Console/Scheduler"]:::console
        DOC["Swagger Documentation"]:::docs
        TEST["Test Suite"]:::test
    end

    %% Connections
    CR --> ES
    ES --> RT
    RT --> MW_CORS
    MW_CORS --> MW_GZIP
    MW_GZIP --> MW_JWT
    MW_JWT --> MW_LOG
    MW_LOG --> MW_REC
    MW_REC --> MW_SEC
    MW_SEC --> MW_RED
    MW_RED --> HC
    MW_RED --> UC

    HC -.-> AH
    HC -.-> VH
    UC -.-> AH
    UC -.-> VH

    HC --> UM
    UC --> UM
    UC --> PM
    UC --> UPM
    AH --> AM

    UM --> GORM
    PM --> GORM
    AM --> GORM
    UPM --> GORM

    GORM --> DB
    GORM --> CACHE

    %% Click Events
    click RT "https://github.com/Stunext/goBoilterplate/blob/master/app/router/router.go"
    click MW_CORS "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/cors.go"
    click MW_GZIP "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/gzip.go"
    click MW_JWT "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/jwt.go"
    click MW_LOG "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/logger.go"
    click MW_REC "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/recover.go"
    click MW_SEC "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/secure.go"
    click MW_RED "https://github.com/Stunext/goBoilterplate/blob/master/app/middlewares/redirect.go"
    click HC "https://github.com/Stunext/goBoilterplate/blob/master/app/controllers/home.go"
    click UC "https://github.com/Stunext/goBoilterplate/blob/master/app/controllers/users.go"
    click AH "https://github.com/Stunext/goBoilterplate/blob/master/app/helpers/auth.go"
    click VH "https://github.com/Stunext/goBoilterplate/blob/master/app/helpers/validator.go"
    click UM "https://github.com/Stunext/goBoilterplate/blob/master/app/models/user.go"
    click PM "https://github.com/Stunext/goBoilterplate/blob/master/app/models/profile.go"
    click AM "https://github.com/Stunext/goBoilterplate/blob/master/app/models/auth.go"
    click UPM "https://github.com/Stunext/goBoilterplate/blob/master/app/models/userProfile.go"
    click CON "https://github.com/Stunext/goBoilterplate/blob/master/app/console/schedule.go"
    click DOC "https://github.com/Stunext/goBoilterplate/blob/master/docs/swagger.json"
    click TEST "https://github.com/Stunext/goBoilterplate/blob/master/tests/default_test.go"

    %% Styles
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef router fill:#b8d4ff,stroke:#333
    classDef middleware fill:#ffcdb2,stroke:#333
    classDef controller fill:#b5e48c,stroke:#333
    classDef helper fill:#98c1d9,stroke:#333
    classDef model fill:#ffd6a5,stroke:#333
    classDef console fill:#caffbf,stroke:#333
    classDef docs fill:#a0c4ff,stroke:#333
    classDef test fill:#bdb2ff,stroke:#333
```
