# allenxuxu/mogutouerp architecture

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

- Interactive diagram: https://gitdiagram.com/allenxuxu/mogutouerp
- Repository: https://github.com/allenxuxu/mogutouerp

## Overview

##### Main Components
- Backend Service:
- Main.go as the entry point.
- Packages such as:
∘ api (handling RESTful endpoints for commodity, customer orders, finance, purchase orders, and user operations)
∘ middleware (e.g., auth for JWT or other authentication mechanisms)
∘ models (representing data models: commodity, customer order, finance, purchase order, and user)
∘ pkg/token (for token generation and handling)
∘ utils (for response handling, validation, etc.)
- Router.go that likely connects the endpoints with controllers and middleware.
- That configuration files in the conf directory (conf.json and jwt.json) are used to set up database connections and JWT keys.
- Frontend Application:
- Web folder, noting its Vue-based structure.
- Subcomponents like:
∘ src/base components (e.g., layout components, views such as commodity, finance, order, staff pages)
∘ src/api directory which communicates with the backend endpoints.
∘ The build configuration and development tools (Webpack, Babel, ESLint, etc.) demonstrating a standard Vue.js SPA.
- Database:
- MySQL as the chosen data storage, with Gorm auto-mapping models to tables.
- Deployment and Containerization:
- Dockerfile and related deployment instructions (Docker container deployment with mounted configuration, Nginx reverse proxy on the frontend side, etc.)

##### Relationships and Data Flow
- Frontend ↔ Backend Interaction:
- Vue.js client making HTTP API calls to the backend endpoints.
- Where Vue’s API (in web/src/api) calls align with endpoints defined in the api folder.
- Backend Components Interaction:
- That the API layer invokes business logic in models and uses middleware for authentication (JWT based from pkg/token and middleware/auth).
- Configuration reading from the conf folder.
- Backend ↔ Database:
- That Gorm is used to automatically generate table schemas.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The project is clearly divided into frontend and backend, emphasizing loose coupling between presentation and business logic.
- RESTful API Design:
- The backend API endpoints in the api directory imply a RESTful design.
- Modularization:
- The clear separation into directories (models, middleware, utils, pkg, router) suggests modular design.
- Security:
- Use of JWT authentication (with configuration in jwt.json and token package) should be highlighted.
- DevOps and Deployment:
- The presence of .github workflows, Dockerfile, and Makefile indicate a CI/CD integration and containerized deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Vue Application (web)"]:::frontend
        FE_API["Frontend API Layer (web/src/api)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        MAIN["main.go Entry Point"]:::backend
        ROUTER["router.go (Router)"]:::backend
        API["API Endpoints (api)"]:::backend
        MW["Middleware (JWT)"]:::backend
        MODELS["Data Models (models)"]:::backend
        TOKEN["Token Handling (pkg/token)"]:::backend
        UTILS["Utility Functions (utils)"]:::backend
        CONFIG["Configuration Files (conf)"]:::backend
        BE["Gin-based API Server"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB[(MySQL Database)]:::database
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        DOCKER["Dockerfile"]:::deployment
        WORKFLOWS["CI/CD (.github/workflows)"]:::deployment
        MAKEFILE["Makefile"]:::deployment
        NGINX["Nginx Reverse Proxy"]:::deployment
    end

    %% Frontend Interactions
    FE -->|"API_requests"| FE_API
    FE -->|"requests_via"| NGINX
    NGINX -->|"proxies_to"| BE

    %% Backend Component Interactions
    MAIN -->|"initializes"| ROUTER
    ROUTER -->|"routes_to"| API
    API -->|"utilizes"| UTILS
    API -->|"invokes"| MODELS
    API -->|"secured_by"| MW
    MW -->|"uses"| TOKEN
    CONFIG -->|"configures"| BE
    BE -->|"handles"| API
    MODELS -->|"maps_to"| DB

    %% Deployment Relationships
    DOCKER -->|"deploys"| BE
    DOCKER -->|"deploys"| FE
    WORKFLOWS -->|"triggers_build"| DOCKER
    MAKEFILE -->|"builds_project"| DOCKER

    %% Click Events
    click MAIN "https://github.com/allenxuxu/mogutouerp/blob/master/main.go"
    click API "https://github.com/allenxuxu/mogutouerp/tree/master/api/"
    click MW "https://github.com/allenxuxu/mogutouerp/blob/master/middleware/auth.go"
    click MODELS "https://github.com/allenxuxu/mogutouerp/tree/master/models/"
    click TOKEN "https://github.com/allenxuxu/mogutouerp/blob/master/pkg/token/token.go"
    click UTILS "https://github.com/allenxuxu/mogutouerp/blob/master/utils/response/response.go"
    click CONFIG "https://github.com/allenxuxu/mogutouerp/tree/master/conf/"
    click FE "https://github.com/allenxuxu/mogutouerp/tree/master/web/"
    click FE_API "https://github.com/allenxuxu/mogutouerp/tree/master/web/src/api/"
    click DOCKER "https://github.com/allenxuxu/mogutouerp/tree/master/Dockerfile"
    click WORKFLOWS "https://github.com/allenxuxu/mogutouerp/blob/master/.github/workflows/build.yml"
    click MAKEFILE "https://github.com/allenxuxu/mogutouerp/tree/master/Makefile"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef deployment fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
