# songquanpeng/gin-template architecture

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

- Interactive diagram: https://gitdiagram.com/songquanpeng/gin-template
- Repository: https://github.com/songquanpeng/gin-template

## Overview

##### Project Type Analysis
This is a full-stack web application template built with:
- Backend: Go (Gin framework)
- Frontend: React
- Database: Supports both SQLite and other SQL databases
- Additional Services: Redis (optional), Email service, GitHub OAuth, WeChat OAuth

##### Main Components

A. Frontend Layer:
- React Single Page Application
- Key components:
- Authentication components (LoginForm, RegisterForm)
- User management components (UsersTable)
- File management components (FilesTable)
- Settings components

B. Backend Layer:
- Gin Web Server
- Controllers (user, file, github, wechat, etc.)
- Middleware components (auth, cache, cors, rate-limit)
- Models layer (user, file, option)

C. External Services:
- Redis (optional, for rate limiting)
- SQL Database (SQLite/MySQL)
- Email Service
- OAuth Providers (GitHub, WeChat)
- Cloudflare Turnstile

**[Client Layer]**
- ↕️
**[API Gateway/Router Layer]**
- ↕️
**[Middleware Layer]**
- ↕️
**[Controller Layer]**
- ↕️
**[Model Layer]**
- ↕️
**[Data Storage Layer]**

##### Key Elements to Highlight

a. Security Features:
- Token-based authentication flow
- Rate limiting mechanism
- CORS handling
- Turnstile verification

b. Data Flow:
- User authentication paths
- File management operations
- API request/response flow
- Cache mechanisms

##### Implementation Details

- Rectangles: Core components
- Clouds: External services
- Hexagons: Middleware components

- Component types
- Environment configurations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        React["React SPA"]:::frontend
        Auth["Authentication Components"]:::frontend
        UserMgmt["User Management"]:::frontend
        FileMgmt["File Management"]:::frontend
        Settings["Settings Components"]:::frontend
        StateContext["State Context"]:::frontend
        AuthHelpers["Auth Helpers"]:::frontend
    end

    subgraph API_Gateway
        Router["API Router"]:::backend
        WebRouter["Web Router"]:::backend
    end

    subgraph Middleware
        AuthMW["Authentication"]:::middleware
        CacheMW["Cache"]:::middleware
        CorsMW["CORS"]:::middleware
        RateLimitMW["Rate Limit"]:::middleware
        TurnstileMW["Turnstile Check"]:::middleware
    end

    subgraph Controllers
        UserCtrl["User Controller"]:::backend
        FileCtrl["File Controller"]:::backend
        GithubCtrl["GitHub Controller"]:::backend
        WeChatCtrl["WeChat Controller"]:::backend
        OptionCtrl["Option Controller"]:::backend
    end

    subgraph Models
        UserModel["User Model"]:::backend
        FileModel["File Model"]:::backend
        OptionModel["Option Model"]:::backend
    end

    subgraph Services
        EmailSvc["Email Service"]:::service
        RedisSvc["Redis Service"]:::service
        RateLimitSvc["Rate Limit Service"]:::service
        VerifySvc["Verification Service"]:::service
    end

    subgraph External
        DB[(SQL Database)]:::database
        Redis[(Redis Cache)]:::database
        GitHub["GitHub OAuth"]:::external
        WeChat["WeChat OAuth"]:::external
        Turnstile["Cloudflare Turnstile"]:::external
    end

    %% Relationships
    React --> Auth
    React --> UserMgmt
    React --> FileMgmt
    React --> Settings
    React --> StateContext
    React --> AuthHelpers

    Auth --> Router
    UserMgmt --> Router
    FileMgmt --> Router
    Settings --> Router

    Router --> WebRouter
    Router --> |API Requests| Middleware

    Middleware --> Controllers
    Controllers --> Models
    Models --> DB
    
    RateLimitMW --> RedisSvc
    RedisSvc --> Redis
    
    Controllers --> Services
    Services --> External

    %% Click Events
    click Auth "https://github.com/songquanpeng/gin-template/blob/main/web/src/components/LoginForm.js"
    click UserMgmt "https://github.com/songquanpeng/gin-template/tree/main/web/src/pages/User"
    click FileMgmt "https://github.com/songquanpeng/gin-template/blob/main/web/src/pages/File/index.js"
    click Settings "https://github.com/songquanpeng/gin-template/blob/main/web/src/components/SystemSetting.js"
    click StateContext "https://github.com/songquanpeng/gin-template/tree/main/web/src/context"
    click AuthHelpers "https://github.com/songquanpeng/gin-template/tree/main/web/src/helpers"
    click Router "https://github.com/songquanpeng/gin-template/blob/main/router/api-router.go"
    click WebRouter "https://github.com/songquanpeng/gin-template/blob/main/router/web-router.go"
    click AuthMW "https://github.com/songquanpeng/gin-template/blob/main/middleware/auth.go"
    click CacheMW "https://github.com/songquanpeng/gin-template/blob/main/middleware/cache.go"
    click CorsMW "https://github.com/songquanpeng/gin-template/blob/main/middleware/cors.go"
    click RateLimitMW "https://github.com/songquanpeng/gin-template/blob/main/middleware/rate-limit.go"
    click TurnstileMW "https://github.com/songquanpeng/gin-template/blob/main/middleware/turnstile-check.go"
    click UserCtrl "https://github.com/songquanpeng/gin-template/blob/main/controller/user.go"
    click FileCtrl "https://github.com/songquanpeng/gin-template/blob/main/controller/file.go"
    click GithubCtrl "https://github.com/songquanpeng/gin-template/blob/main/controller/github.go"
    click WeChatCtrl "https://github.com/songquanpeng/gin-template/blob/main/controller/wechat.go"
    click OptionCtrl "https://github.com/songquanpeng/gin-template/blob/main/controller/option.go"
    click UserModel "https://github.com/songquanpeng/gin-template/blob/main/model/user.go"
    click FileModel "https://github.com/songquanpeng/gin-template/blob/main/model/file.go"
    click OptionModel "https://github.com/songquanpeng/gin-template/blob/main/model/option.go"
    click EmailSvc "https://github.com/songquanpeng/gin-template/blob/main/common/email.go"
    click RedisSvc "https://github.com/songquanpeng/gin-template/blob/main/common/redis.go"
    click RateLimitSvc "https://github.com/songquanpeng/gin-template/blob/main/common/rate-limit.go"
    click VerifySvc "https://github.com/songquanpeng/gin-template/blob/main/common/verification.go"

    %% Styles
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef middleware fill:#9E9E9E,stroke:#616161,color:white
    classDef service fill:#FF9800,stroke:#EF6C00,color:white
    classDef database fill:#673AB7,stroke:#4527A0,color:white
    classDef external fill:#FFC107,stroke:#FFA000,color:black
```
