# zhyi-source/zhouyi-admin architecture

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

- Interactive diagram: https://gitdiagram.com/zhyi-source/zhouyi-admin
- Repository: https://github.com/zhyi-source/zhouyi-admin

## Overview

##### Project type and purpose
- This is a pure‑front‑end single‑page application (SPA) admin template (“ZHOUYI·ADMIN”) built with Vue 3 + ElementPlus + JavaScript + Pinia + Vite.

##### High‑level architecture
- **Developer Environment**
- Node.js + npm/Yarn for dependency management
- Vite as dev/build tool and local server
- **Deployment**
- Production build → static assets (HTML/CSS/JS) → served via any static host (Nginx/CDN)
- **Runtime (Browser)**
- Vue 3 application loaded in the browser
- Vue Router drives view transitions
- Pinia manages application state
- Axios‑based API modules communicate with external REST endpoints

##### Main components
a. **Developer Tooling Layer** (outside the browser)
- Node.js & Vite dev server (npm run dev)
- Build step (npm run build) → outputs `/dist`
b. **Static Hosting Layer**
- Web server or CDN serving the built assets
c. **Client (Browser) Layer** – group as one large container labelled “Vue 3 SPA”
1. **Entry Point** (`index.html` + `main.js`)
2. **Routing** (`src/router`)
3. **UI Layer** (`src/components`, `src/layout`, `src/views`)
4. **State Management** (`src/stores` via Pinia)
5. **API Service Layer** (`src/api`)
– `server.js` configures Axios (base URL, interceptors)
– `modules/api.*.js` define REST calls (login, users, roles)
6. **Assets & Styles** (`src/assets`, SCSS abstracts, themes)
d. **External Services**
- Backend REST API (authentication, user/role management, logs)
- (Optionally) Third‑party services—analytics, SSO, CDN for fonts/images

##### Relationships & data flows
- Developer → (npm run dev) → Vite dev server → Browser
- Browser loads SPA → Router navigates → Views composed from Components
- Components dispatch actions to Pinia stores → commit/mutate state
- Store or Components invoke API modules → Axios → External REST API → JSON responses → back through Axios → update store/UI
- Built assets → deployed to Static Hosting → consumed by end users

##### Architectural patterns & design principles
- **Component‑based UI**: reusable Vue single‑file components
- **MVVM‑like separation**: Views/Components (View), Pinia (ViewModel), API modules (Model)
- **Layered architecture**: presentation (components), application logic (store/routes), integration (API layer)
- **Theming & abstraction**: SCSS partials for variables, mixins, themes

##### Essential elements
- **Clear labels** for: Dev Machine, Vite Dev Server, Build Output, Static Host, Browser (SPA), External REST API
- Grouped modules inside containers with titles (e.g., “src/components”, “src/stores”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Tooling Layer
    subgraph "Developer Tooling Layer"
        direction TB
        PM["package.json"]:::dev
        VC["vite.config.js"]:::dev
        DEV["npm run dev"]:::dev
        BUILD["npm run build"]:::dev
        VITE_DEV["Vite Dev Server"]:::dev
        DIST["Build Output (/dist)"]:::dev
        PM -->|run dev| DEV
        DEV --> VITE_DEV
        PM -->|run build| BUILD
        BUILD --> DIST
    end

    %% Static Hosting Layer
    subgraph "Static Hosting Layer"
        direction TB
        PUBLIC["public/"]:::host
        DIST --> PUBLIC
    end

    %% Browser Layer
    subgraph "Vue 3 SPA (Browser)"    
        direction TB
        %% Entry Point
        subgraph "Entry Point" 
            direction TB
            HTML["index.html"]:::browser
            MAIN["src/main.js"]:::browser
        end

        %% Routing
        subgraph "Routing"
            direction TB
            ROUTER1["src/router/index.js"]:::browser
            ROUTER2["src/router/routes.js"]:::browser
        end

        %% UI Layer
        subgraph "UI Layer"
            direction TB
            CMPS["src/components/"]:::browser
            LAYOUT["src/layout/"]:::browser
            VIEWS["src/views/"]:::browser
        end

        %% State Management
        subgraph "State Management (Pinia Stores)"
            direction TB
            S1["src/stores/AppSetting.js"]:::browser
            S2["src/stores/Menus.js"]:::browser
            S3["src/stores/SearchPanel.js"]:::browser
            S4["src/stores/TagsView.js"]:::browser
            S5["src/stores/Users.js"]:::browser
        end

        %% API Service Layer
        subgraph "API Service Layer"
            direction TB
            SERVER["src/api/server.js"]:::browser
            API1["src/api/modules/api.login.js"]:::browser
            API2["src/api/modules/api.users.js"]:::browser
            API3["src/api/modules/api.roles.js"]:::browser
        end

        %% Assets & Styles
        subgraph "Assets & Styles"
            direction TB
            ASSETS["src/assets/"]:::browser
            FONTS["src/assets/fonts/"]:::browser
            IMGS["src/assets/img/"]:::browser
            STYLES["src/assets/styles/"]:::browser
        end

        %% Utilities
        subgraph "Utilities"
            direction TB
            U1["src/utils/util.common.js"]:::browser
            U2["src/utils/util.cookie.js"]:::browser
            U3["src/utils/util.log.js"]:::browser
            U4["src/utils/util.strotage.js"]:::browser
            U5["src/utils/util.time.js"]:::browser
            U6["src/utils/util.toast.js"]:::browser
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        REST["External REST API"]:::external
        THIRD["Third‑Party Services"]:::external
    end

    %% Relationships
    VITE_DEV -->|serves SPA| HTML
    PUBLIC -->|serves static assets| HTML
    HTML -->|bootstraps| MAIN
    MAIN --> ROUTER1
    ROUTER1 --> ROUTER2
    ROUTER2 --> VIEWS
    VIEWS --> CMPS
    CMPS --> S1
    CMPS --> S2
    CMPS --> S3
    CMPS --> S4
    CMPS --> S5
    S1 -->|dispatch actions| SERVER
    SERVER -->|GET /api/login| API1
    SERVER -->|GET /api/users| API2
    SERVER -->|GET /api/roles| API3
    API1 --> REST
    API2 --> REST
    API3 --> REST
    REST -->|JSON response| SERVER
    SERVER --> S1
    S1 --> CMPS
    CMPS --> VIEWS
    MAIN --> ASSETS
    MAIN --> STYLES
    CMPS --> U1
    CMPS --> U2
    CMPS --> U3
    CMPS --> U4
    CMPS --> U5
    CMPS --> U6

    %% Click Events
    click PM "https://github.com/zhyi-source/zhouyi-admin/blob/master/package.json"
    click VC "https://github.com/zhyi-source/zhouyi-admin/blob/master/vite.config.js"
    click DIST "https://github.com/zhyi-source/zhouyi-admin/tree/master//dist"
    click PUBLIC "https://github.com/zhyi-source/zhouyi-admin/tree/master/public/"
    click HTML "https://github.com/zhyi-source/zhouyi-admin/blob/master/index.html"
    click MAIN "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/main.js"
    click ROUTER1 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/router/index.js"
    click ROUTER2 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/router/routes.js"
    click CMPS "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/components/"
    click LAYOUT "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/layout/"
    click VIEWS "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/views/"
    click S1 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/stores/AppSetting.js"
    click S2 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/stores/Menus.js"
    click S3 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/stores/SearchPanel.js"
    click S4 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/stores/TagsView.js"
    click S5 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/stores/Users.js"
    click SERVER "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/api/server.js"
    click API1 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/api/modules/api.login.js"
    click API2 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/api/modules/api.users.js"
    click API3 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/api/modules/api.roles.js"
    click ASSETS "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/assets/"
    click FONTS "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/assets/fonts/"
    click IMGS "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/assets/img/"
    click STYLES "https://github.com/zhyi-source/zhouyi-admin/tree/master/src/assets/styles/"
    click U1 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.common.js"
    click U2 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.cookie.js"
    click U3 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.log.js"
    click U4 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.strotage.js"
    click U5 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.time.js"
    click U6 "https://github.com/zhyi-source/zhouyi-admin/blob/master/src/utils/util.toast.js"

    %% Styles
    classDef dev fill:#a2f5a2,stroke:#333,stroke-width:1px
    classDef host fill:#dddddd,stroke:#333,stroke-width:1px
    classDef browser fill:#a2daf5,stroke:#333,stroke-width:1px
    classDef external fill:#f5cfa2,stroke:#333,stroke-width:1px
```
