How mgbq/nx-admin works
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)