How mizhexiaoxiao/vue-fastapi-admin works
1. This repository is a split front-end/back-end admin platform. The backend is a FastAPI service under app/, and the frontend is a separate Vue 3 + Vite application under web/. The codebase is organized around an RBAC-driven system admin domain rather than a general-purpose web app.
2. The backend entry point is run.py, with application setup concentrated in app/core/init_app.py. Request handling is versioned under app/api/v1, so the public API boundary is explicitly /api/v1/.... Core middleware, dependency injection, and exception handling live in app/core, shaping the global request lifecycle before control reaches business logic.
3. The backend follows a layered flow: API routers in app/api/v1/* call controllers in app/controllers/*, which then use shared CRUD helpers in app/core/crud.py, data models in app/models/*, and Pydantic schemas in app/schemas/*. This keeps transport, business rules, and persistence concerns separated.
4. The main backend domains are administrative and permission-centric: users, roles, menus, departments, API permissions, and audit logs. The presence of app/api/v1/apis, users, roles, menus, depts, auditlog, plus matching controllers and schemas, indicates the system manages both page/menu access and fine-grained interface access.
5. Authentication is JWT-based. app/utils/jwt_utils.py and app/utils/password.py handle token creation/verification and password processing, while app/core/dependency.py likely wires authenticated/current-user context into protected endpoints. This is the security boundary that gates both data access and permission checks.
6. Operational concerns are first-class on the backend: app/log/log.py provides logging, app/core/exceptions.py centralizes error handling, app/core/ctx.py suggests request-scoped context propagation, and app/core/bgtask.py covers asynchronous background work. These pieces sit horizontally across all domains rather than belonging to one feature.
7. The frontend is a single-page admin console built with Vue 3, Naive UI, Pinia, and Vite. Its shell is defined in web/src/layout, with reusable header/sidebar/tabs components and page containers, while feature pages live in web/src/views for login, workbench, profile, and system management screens.
8. Frontend routing is not static. web/src/router/guard/* plus the permission store in web/src/store/modules/permission indicate the app builds or filters routes based on the authenticated user’s roles/menus. This matches the backend RBAC model and is the key data flow that turns permissions into visible navigation and accessible pages.
9. State and identity are managed on the client through Pinia modules for app state, user state, tags, and permissions, with token persistence in web/src/utils/auth and browser storage helpers in web/src/utils/storage. Route guards enforce login, page loading state, title updates, and access control before a view renders.
10. Feature pages are built on a shared admin UI toolkit: generic CRUD table/modal components, query bars, icon pickers, and common page wrappers under web/src/components. These abstractions let system pages for users, roles, menus, departments, APIs, and audit logs follow the same interaction pattern and keep the UI consistent.
11. The frontend talks to the backend through a centralized HTTP layer in web/src/utils/http, with API modules under web/src/api. That separation means views depend on stable client wrappers rather than calling the backend directly, making auth headers, error handling, and response interception uniform across the app.
12. Deployment is container-aware. The repo includes a Dockerfile, deploy/entrypoint.sh, and deploy/web.conf, suggesting production packaging with an HTTP server/reverse proxy in front of the built frontend and API service. Local development remains split: python run.py for the backend and pnpm dev for the frontend.
Main entry points: controllers Controllers · main.js main.js · init_app.py App init · core Core
Components 22
Backend
FastAPI service and RBAC domain logic
- run.py · Backend process entry
run.py - App init · Builds the FastAPI application and wires core setup
app/core/init_app.py - Core · Middleware, dependencies, context, exceptions, background tasks
app/core - API v1 · Versioned public API boundary
app/api/v1 - Controllers · Domain orchestration between routes and data access
app/controllers - CRUD · Shared persistence helpers
app/core/crud.py - Models · Database entities and enums
app/models - Schemas · Request and response contracts
app/schemas - Auth utils · JWT and password helpers
app/utils - Admin domains · Users, roles, menus, departments, APIs, and audit logs
app/api/v1/users - Logging · Application logging setup
app/log/log.py
Frontend
Vue 3 admin console and client state
- main.js · Frontend bootstrap
web/src/main.js - Layout shell · Header, sidebar, tags, and app container
web/src/layout - Router · Route definitions and guards
web/src/router - Pinia stores · App, user, tags, and permission state
web/src/store/modules - Permission flow · Builds visible routes from user roles and menus
web/src/store/modules/permission - HTTP client · Centralized request layer and interceptors
web/src/utils/http - API modules · Feature-specific backend client modules
web/src/api - Views · Login, workbench, profile, and system management pages
web/src/views - UI kit · CRUD tables, modals, query bars, icons, and page wrappers
web/src/components
Deployment
Container and reverse-proxy packaging
- Deploy files · Entrypoint and reverse-proxy configuration
deploy - Dockerfile · Container image definition
Dockerfile
Connections 23
- run.py → App init: starts · Entry point creates the application
- App init → Core: wires · Registers middleware, dependencies, and error handling
- App init → API v1: mounts · Attaches versioned routes
- API v1 → Controllers: calls · Routers delegate to domain controllers
- Controllers → CRUD: uses · Controllers share persistence helpers
- Controllers → Models: reads/writes · Business logic works with ORM entities
- Controllers → Schemas: validates · Input and output data shaped by schemas
- Controllers → Auth utils: secures · Authentication and password handling support protected actions
- Admin domains → Controllers: implemented by · Domain routes map to controller modules
- Core → Logging: logs · Cross-cutting logging support
- Core → Auth utils: auth context · Dependencies expose current-user and token context
- main.js → Layout shell: renders · App bootstraps the shell
- main.js → Router: registers · Router is installed at startup
- main.js → Pinia stores: initializes · Pinia state is created on launch
- Router → Permission flow: guards · Route access is filtered by permissions
- Permission flow → Pinia stores: uses · Permission store drives navigation state
- Pinia stores → HTTP client: uses · Client state relies on backend requests
- API modules → HTTP client: wraps · API modules share the HTTP layer
- Views → API modules: calls · Pages use stable client wrappers
- Views → UI kit: composes · Pages are built from reusable admin UI
- Layout shell → Views: hosts · Shell contains routed pages
- Deploy files → Dockerfile: packages · Deployment artifacts support container builds
- Deploy files → run.py: serves · Entrypoint launches backend in production