# mgbq/nx-admin architecture

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

- Interactive diagram: https://gitdiagram.com/mgbq/nx-admin
- Repository: https://github.com/mgbq/nx-admin

## Overview

##### Project type and purpose
- This is a front-end Single Page Application (SPA) boilerplate / admin dashboard built with Vue 2.x and Element-UI.
- It provides a set of pre-built business components (tables, forms, charts, editors), dynamic theming, i18n, routing, permission control, mock data, and a typical Vuex + Vue-Router architecture to accelerate enterprise-grade back-office prototypes.

##### Top-level architectural view
- The project is purely client-side; after building it produces static assets (HTML/CSS/JS) that you serve from any static host (Nginx, CDN, S3, etc.).
- It relies on environment configs (`.env.*`) to switch between mock, staging or real API endpoints.
- Build toolchain: Webpack (via `vue.config.js` & `babel.config.js`), ESLint/Prettier, Jest unit tests, CI via Travis.

##### Main components and their relationships
A. Presentation Layer (Components & Views)
– `public/index.html`: application shell with loader wrapper and root `
`.
– `src/main.js`: bootstraps Vue, installs plugins (Vue-Router, Vuex, Element-UI, i18n).
– `src/App.vue`: root component, lays out `Navbar`, `Sidebar`, `TagsView`, and `router-view`.
– `src/views/*`: page‐level views (dashboard, charts, forms, tables, error pages, etc.).
– `src/components/*`: reusable, self-contained Vue components (breadcrumbs, widgets, data cards, markdown editors, kanban, upload, etc.).

B. Client-side Routing & Navigation
– `src/router/index.js`: defines dynamic routes (permission-based, multi-level).
– `vue-router` guards enforce auth and roles before navigation.
– Routes map to `src/views/*` and load components on demand (`import(...)`).

C. State Management
– `src/store/index.js`: root Vuex store, aggregates modules.
– `src/store/modules/*`: app settings, user, tagsView, permission, errorLog, fullScreen.
– Components dispatch actions / commit mutations to share state (theme, user info, menu collapse, etc.).

D. API / Service Layer
– `src/api/*.js`: Axios wrappers for remote data (`article.js`, `user.js`, `transaction`, `qiniu`, etc.).
– `src/utils/request.js`: Axios instance with interceptors (attach tokens, error handling).
– `src/mock/*.js`: Mock.js definitions to simulate backend for development.
– Environment configuration (`src/config/env.js`) selects real vs. mock endpoints.

E. Theming & Assets
– `public/static/theme/{blue,default,green,...}`: raw CSS files for dynamic skinning.
– `src/assets/style/*.scss`: shared variables, mixins, component-level styling.
– `src/assets/library/*`: third-party assets (FontAwesome, highlight.js).

F. Build & Deployment Pipeline
– `package.json` scripts: `dev`, `build:sit`, `build:prod`, `lint`, `test`.
– Uses multiple `.env` files to inject host URLs and feature flags.
– CI (Travis) runs linter and unit tests on push.
– Output directory `dist/` (or `build/`) contains minified static assets.

G. External Services
– Real backend REST API or Qiniu file upload service.
– Optionally a separate micro-service for remoteSearch.

##### Architectural patterns and design principles
- Component-based UI: break UI into self-contained, reusable Vue components.
- Flux / Redux-style state management: Vuex for single source of truth, predictable updates.
- Dynamic & permission-driven routing: routes are generated after login based on roles.
- Mock-first development: use Mock.js to prototype UI without a live backend.
- Theming support: CSS variables + multiple theme CSS bundles, loaded at runtime.
- Separation of concerns:
- Presentation (`views` + `components`)
- Business logic & state (`store`)
- Data access (`api`, `utils/request`)
- Configuration (`config`, `.env`)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Build & CI Pipeline"
        Sc["Source Code"]:::build
        Webpack["Webpack & Babel"]:::build
        LintTest["ESLint/Prettier & Jest"]:::build
        Travis["Travis CI"]:::build
        BuildArtifacts["dist/ (Static Assets)"]:::build

        Sc --> Webpack --> BuildArtifacts
        Sc --> LintTest --> Travis --> BuildArtifacts
    end

    subgraph "Client Runtime"
        index["Application Shell<br>public/index.html"]:::client
        mainjs["Bootstrap<br>src/main.js"]:::client
        App["Root Component<br>src/App.vue"]:::client
        Router["Router Configuration<br>src/router/index.js"]:::client
        Env["Environment Config<br>src/config/env.js"]:::client
        Store["Vuex Store Root<br>src/store/index.js"]:::client
        StoreMod["Store Modules<br>src/store/modules/"]:::client
        Views["Page Views<br>src/views/"]:::client
        Comp["Reusable Components<br>src/components/"]:::client
        Request["Axios Instance & Interceptors<br>src/utils/request.js"]:::client
        Mock["Mock Data Definitions<br>src/mock/"]:::client
        Themes["Theme Assets<br>public/static/theme/"]:::client
        Styles["Shared Styles<br>src/assets/style/"]:::client
        Lib["3rd-party Assets<br>src/assets/library/"]:::client
    end

    subgraph "External Services"
        APIsrv["REST API Server"]:::external
        Qiniu["Qiniu File Upload"]:::external
        Search["Search Microservice"]:::external
    end

    User["User"]:::external
    Host["Static Hosting (CDN/Nginx/S3)"]:::external

    User --> Host
    BuildArtifacts --> Host

    Host --> index
    index --> mainjs
    mainjs --> App
    mainjs --> Router
    mainjs --> Store
    mainjs --> Env

    App --> Themes
    App --> Styles
    App --> Lib
    App --> Views
    App --> Comp

    Router --> Views
    Comp --> Store
    StoreMod --> Store
    Store --> Comp
    Store --> Views

    Comp -->|HTTP REST via Axios| Request
    Env --> Request
    Request --> Mock
    Request --> APIsrv
    APIsrv <-->|REST API Calls| Request
    Request --> Qiniu
    Request --> Search

    classDef build fill:#ffe4b5,stroke:#333,stroke-width:1px;
    classDef client fill:#e0ffff,stroke:#333,stroke-width:1px;
    classDef external fill:#f0e68c,stroke:#333,stroke-width:1px;

    click index "https://github.com/mgbq/nx-admin/blob/master/public/index.html"
    click mainjs "https://github.com/mgbq/nx-admin/blob/master/src/main.js"
    click App "https://github.com/mgbq/nx-admin/blob/master/src/App.vue"
    click Views "https://github.com/mgbq/nx-admin/tree/master/src/views/"
    click Comp "https://github.com/mgbq/nx-admin/tree/master/src/components/"
    click Router "https://github.com/mgbq/nx-admin/blob/master/src/router/index.js"
    click Store "https://github.com/mgbq/nx-admin/blob/master/src/store/index.js"
    click StoreMod "https://github.com/mgbq/nx-admin/tree/master/src/store/modules/"
    click Request "https://github.com/mgbq/nx-admin/blob/master/src/utils/request.js"
    click Mock "https://github.com/mgbq/nx-admin/tree/master/src/mock/"
    click Env "https://github.com/mgbq/nx-admin/blob/master/src/config/env.js"
    click Themes "https://github.com/mgbq/nx-admin/tree/master/public/static/theme/"
    click Styles "https://github.com/mgbq/nx-admin/tree/master/src/assets/style/"
    click Lib "https://github.com/mgbq/nx-admin/tree/master/src/assets/library/"
    click Webpack "https://github.com/mgbq/nx-admin/blob/master/vue.config.js"
    click Webpack "https://github.com/mgbq/nx-admin/blob/master/babel.config.js"
    click Sc "https://github.com/mgbq/nx-admin/blob/master/package.json"
    click Travis "https://github.com/mgbq/nx-admin/blob/master/.travis.yml"
    click LintTest "https://github.com/mgbq/nx-admin/blob/master/jest.config.js"
```
