# zjutjh/wejh-go architecture

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

- Interactive diagram: https://gitdiagram.com/zjutjh/wejh-go
- Repository: https://github.com/zjutjh/wejh-go

## Overview

##### Project Type Analysis
This is a backend service application written in Go, specifically for the "WeJH" (微精弘) system. It follows a typical MVC-like architecture with additional service layers.

##### Main Components

A. Core Layers (Vertical Layers):
- Controllers Layer (app/controllers/*)
- Services Layer (app/services/*)
- Models Layer (app/models/*)
- Middleware Layer (app/midwares/*)

B. Infrastructure Components (Horizontal Layers):
- Configuration Management (config/*)
- Database Layer
- Redis Cache
- Session Management
- WeChat Integration
- API Interfaces

**┌─ External Clients ─────────────────────────────┐**
- (WeChat, API Consumers)                        │
- ┬───────────────────────┘
- ↓
**┌─ Router Layer ────────────────────────────────┐**
- (config/router/*)                             │
- ┬───────────────────────┘
- ↓
**┌─ Middleware Layer ────────────────────────────┐**
- Authentication      - Error Handling        │
- Admin Checks        - Init Checks           │
- ┬───────────────────────┘
- ↓
**┌─ Controllers Layer ───────────────────────────┐**
- Admin Controllers   - User Controllers      │
- System Controllers  - Function Controllers  │
- ┬───────────────────────┘
- ↓
**┌─ Services Layer ──────────────────────────────┐**
- User Services      - Admin Services         │
- Theme Services     - School Bus Services    │
- YXY Services       - Funnel Services        │
- ┬───────────────────────┘
- ↓
**┌─ Models Layer ────────────────────────────────┐**
- (Database Entities and Business Objects)      │
- ┬───────────────────────┘
- ↓
**┌─ Infrastructure Layer ────────────────────────┐**
- ┌─────────┐ ┌──────┐ ┌───────┐ ┌──────────┐  │
- Database │ │Redis │ │Session│ │WeChat API│  │
- ┘ └──────┘ └───────┘ └──────────┘  │
- ┘

##### Important Details

a. Controller Groups:
- Admin Controllers
- User Controllers
- System Controllers
- Functional Controllers (canteen, library, etc.)

b. Service Categories:
- User Services
- Admin Services
- Functional Services (school bus, supplies, etc.)
- Integration Services (YXY, funnel)

c. Infrastructure Components:
- Configuration Management
- Database Connections
- Redis Cache
- Session Management
- WeChat Integration

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Layer
    subgraph External["External Layer"]
        Client["External Clients"]:::external
        WeChatAPI["WeChat API"]:::external
    end

    %% Router Layer
    subgraph RouterLayer["Router Layer"]
        Router["API Router"]:::router
    end
    click Router "https://github.com/zjutjh/WeJH-Go/tree/main/config/router/"

    %% Middleware Layer
    subgraph MiddlewareLayer["Middleware Layer"]
        AuthMiddleware["Authentication"]:::middleware
        AdminCheck["Admin Checks"]:::middleware
        ErrorHandler["Error Handling"]:::middleware
    end
    click AuthMiddleware "https://github.com/zjutjh/WeJH-Go/blob/main/app/midwares/checkLogin.go"
    click AdminCheck "https://github.com/zjutjh/WeJH-Go/blob/main/app/midwares/checkAdmin.go"
    click ErrorHandler "https://github.com/zjutjh/WeJH-Go/blob/main/app/midwares/errHandler.go"
    click MiddlewareLayer "https://github.com/zjutjh/WeJH-Go/tree/main/app/midwares/"

    %% Controllers Layer
    subgraph ControllersLayer["Controllers Layer"]
        AdminControllers["Admin Controllers"]:::controller
        UserControllers["User Controllers"]:::controller
        SystemControllers["System Controllers"]:::controller
        FuncControllers["Function Controllers"]:::controller
    end
    click ControllersLayer "https://github.com/zjutjh/WeJH-Go/tree/main/app/controllers/"
    click AdminControllers "https://github.com/zjutjh/WeJH-Go/tree/main/app/controllers/adminController/"
    click UserControllers "https://github.com/zjutjh/WeJH-Go/tree/main/app/controllers/userController/"
    click SystemControllers "https://github.com/zjutjh/WeJH-Go/tree/main/app/controllers/systemController/"
    click FuncControllers "https://github.com/zjutjh/WeJH-Go/tree/main/app/controllers/funcControllers/"

    %% Services Layer
    subgraph ServicesLayer["Services Layer"]
        UserServices["User Services"]:::service
        AdminServices["Admin Services"]:::service
        ThemeServices["Theme Services"]:::service
        SchoolBusServices["School Bus Services"]:::service
        YXYServices["YXY Services"]:::service
        FunnelServices["Funnel Services"]:::service
    end
    click ServicesLayer "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/"
    click UserServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/userServices/"
    click AdminServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/adminServices/"
    click ThemeServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/themeServices/"
    click SchoolBusServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/schoolBusServices/"
    click YXYServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/yxyServices/"
    click FunnelServices "https://github.com/zjutjh/WeJH-Go/tree/main/app/services/funnelServices/"

    %% Models Layer
    subgraph ModelsLayer["Models Layer"]
        Models["Database Entities"]:::model
    end
    click ModelsLayer "https://github.com/zjutjh/WeJH-Go/tree/main/app/models/"

    %% Infrastructure Layer
    subgraph InfrastructureLayer["Infrastructure Layer"]
        Config["Configuration"]:::infra
        Database["Database"]:::infra
        Redis["Redis Cache"]:::infra
        Session["Session Management"]:::infra
        APIException["API Exception"]:::infra
        Utils["Utilities"]:::infra
    end
    click Config "https://github.com/zjutjh/WeJH-Go/tree/main/config/config/"
    click Database "https://github.com/zjutjh/WeJH-Go/tree/main/config/database/"
    click Redis "https://github.com/zjutjh/WeJH-Go/tree/main/config/redis/"
    click Session "https://github.com/zjutjh/WeJH-Go/tree/main/config/session/"
    click APIException "https://github.com/zjutjh/WeJH-Go/tree/main/app/apiException/"
    click Utils "https://github.com/zjutjh/WeJH-Go/tree/main/app/utils/"

    %% API Interfaces
    subgraph APILayer["API Interfaces"]
        FunnelAPI["Funnel API"]:::api
        UserCenterAPI["User Center API"]:::api
        YXYAPI["YXY API"]:::api
    end
    click FunnelAPI "https://github.com/zjutjh/WeJH-Go/tree/main/config/api/funnelApi/"
    click UserCenterAPI "https://github.com/zjutjh/WeJH-Go/tree/main/config/api/userCenterApi/"
    click YXYAPI "https://github.com/zjutjh/WeJH-Go/tree/main/config/api/yxyApi/"

    %% Connections
    Client --> Router
    WeChatAPI --> Router
    Router --> MiddlewareLayer
    MiddlewareLayer --> ControllersLayer
    ControllersLayer --> ServicesLayer
    ServicesLayer --> ModelsLayer
    ModelsLayer --> InfrastructureLayer
    ServicesLayer --> APILayer
    APILayer --> InfrastructureLayer

    %% Styles
    classDef external fill:#68B5E8,stroke:#333,stroke-width:2px
    classDef router fill:#95DAC1,stroke:#333,stroke-width:2px
    classDef middleware fill:#FD6F96,stroke:#333,stroke-width:2px
    classDef controller fill:#6EDB6E,stroke:#333,stroke-width:2px
    classDef service fill:#7FD1B9,stroke:#333,stroke-width:2px
    classDef model fill:#B4E4AA,stroke:#333,stroke-width:2px
    classDef infra fill:#FFD93D,stroke:#333,stroke-width:2px
    classDef api fill:#FF8B8B,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend["Legend"]
        L1["External Systems"]:::external
        L2["Router Components"]:::router
        L3["Middleware"]:::middleware
        L4["Controllers"]:::controller
        L5["Services"]:::service
        L6["Models"]:::model
        L7["Infrastructure"]:::infra
        L8["API Interfaces"]:::api
    end
```
