How insistence/ruoyi-vue3-fastapi works
Project Type and Purpose
• This is a full-stack, front-end/back-end-separated rapid-development framework based on Vue3/Element Plus (SPA) and FastAPI (Python).
• Frontend: Single-page application for user interface, routing, state management, and API calls.
• Backend: FastAPI monolith structured by modules (admin, generator, task), providing RESTful APIs, authentication (OAuth2+JWT), scheduling, caching, and code generation.
Analyzing the File Structure
• Top level:
• ruoyi-fastapi-frontend – Vue3 SPA with src (views, components, router, store, api), public/index.html, assets, Vite config.
• ruoyi-fastapi-backend – FastAPI app.py/server.py, modules, config, middlewares, exceptions, utils, SQL scripts, requirements.
• Backend layers:
• app.py & server.py – bootstrap and sub_applications registration (static, exception, middleware).
• config – environment, DB (SQLAlchemy), Redis, scheduler, constants, enums.
• middlewares – CORS, GZip, tracing.
• exceptions – error handlers.
• module_admin, module_generator, module_task – each with controller → service → dao → entity (DO/VO).
• utils – common helpers, cron, excel, template (Jinja2), logging, response formatting.
• sql – DDL scripts for MySQL and PostgreSQL.
• Frontend layers:
• src/views – pages by domain (login, dashboard, system, monitor, tool).
• src/api – HTTP wrappers for each backend module.
• src/store – Vuex modules (user, permission, settings).
• src/router – route definitions, permission guards.
• src/components, src/layout, src/plugins, src/utils – reusable UI & logic.
Insights from README
• Tech stack: Vue3, Element Plus, FastAPI, SQLAlchemy, MySQL/PostgreSQL, Redis, OAuth2+JWT.
• Core features: user/role/menu/dept/post/dict/config/notice logs, online users, scheduler tasks, system & cache monitoring, code gen via database introspection & Jinja2 templates.
• Deployment: separate build for front (npm/vite) and back (Python app with env files).
a. Main Components
• End User & Browser (Client)
• Frontend SPA (Vue3, Element Plus, Vite)
• HTTP(S) API Gateway (FastAPI server.py/app.py)
• Middleware Layer (CORS, GZip, tracing)
• Authentication & Authorization (OAuth2 + JWT)
• Module Routers & Controllers (admin, generator, task)
• Service Layer (business logic)
• Data Access Layer (DAO, SQLAlchemy)
• Relational Database (MySQL/PostgreSQL)
• Cache & Session Store (Redis)
• Scheduler (APScheduler via get_scheduler)
• Utilities & Templates (Jinja2 for code generation)
• Static File Server (sub_applications/staticfiles)
b. Relationships & Data Flows
1. Browser → SPA assets (HTML/CSS/JS) served by web server or CDN.
2. User actions in SPA → AJAX calls to FastAPI endpoints.
3. FastAPI receives request → passes through global middlewares (CORS, GZip, trace).
4. Authentication middleware checks OAuth2/JWT tokens → injects user context.
5. Router dispatch → Controller method for specific module.
6. Controller calls Service → Service calls DAO → DAO uses SQLAlchemy to execute SQL on RDS.
7. On read/write: DB persistent operations; on cacheable operations: Service may read/write Redis.
8. Scheduler triggers periodic tasks (module_task) via APScheduler → tasks may call services or utils.
9. Generator module uses Jinja2 templates to produce code artifacts (Python, SQL, Vue, JS) on-the-fly.
10. Responses (JSON) returned back to SPA, UI updates accordingly.
c. Architectural Patterns & Principles
• Layered (Controller → Service → DAO → Database)
• Modular Monolith: modules grouped by domain (admin, generator, task)
• Dependency Injection for DB/Redis/Scheduler via get_db, get_redis, get_scheduler
• Middleware pipeline for cross-cutting concerns (CORS, tracing, exception handling)
• Token-based stateless auth (OAuth2 + JWT)
• Template-based code generation (Jinja2)
d. Key Technologies
• Frontend: Vue3, Element Plus, Vue Router, Vuex, Vite
• Backend: FastAPI, SQLAlchemy, Pydantic, Redis, APScheduler, Jinja2
• Data Stores: MySQL/PostgreSQL, Redis
• Auth: OAuth2, JWT
• Build & Deployment: npm, Python scripts, .env files
Diagramming Conventions
• Labels: show protocol (HTTP/HTTPS, SQL, Redis CLI, JWT).