# senqi-666/fastapi-vue-admin architecture

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

- Interactive diagram: https://gitdiagram.com/senqi-666/fastapi-vue-admin
- Repository: https://github.com/senqi-666/fastapi-vue-admin

## Overview

##### Main Components
- Backend API Server – Highlight its layered structure:
- API layer (FastAPI routes grouped under “api/system/…” for auth, dept, menu, etc.)
- Core functionality (configuration, database connections, middlewares, security, logging)
- Business logic (services in “services/system/…”) and CRUD operations (under “crud/system/…”)
- Data models and schemas (organized in “models/”, “schemas/system/…”)
- Initialization scripts (for seeding the database)
- Frontend Client – Represent the Vue application:
- Components, layouts, and views (in “web/src/components”, “layouts”, “views”)
- API integrations (in “web/src/api/…”)
- Routing, state management (using Vue Router and Vuex/store)
- Infrastructure Components:
- Database (PostgreSQL as configured in “app/core/config.py”)
- Caching/Session store (Redis)
- API Documentation (Swagger UI, with static assets in “backend/app/static/swagger”)
- External dependencies such as authentication using JWT and OAuth2

- Inside the backend block, illustrate the separation:
- The API endpoints layer that communicates with the service layer.
- The service layer (handling business logic) which interacts with the CRUD and database layers.
- A connection line between the service/CRUD layers and the Database & Redis.
- Optionally, include a separate element for API documentation (Swagger/Redoc) that the frontend developers might use.

##### Architectural Patterns and Design Principles
- Separation of concerns within the backend layers:
- The use of controllers (FastAPI endpoints), services, and data access (CRUD, models).
- RBAC design that informs how services and CRUD operations handle permissions.
- For the frontend, note the component-based architecture of Vue3 (components, layouts, routing, state management).
- Integration of third-party libraries (Pydantic for data validation, SQLAlchemy for ORM, and Ant Design Vue for UI components).

##### Relevant Technologies and Frameworks
- Backend: FastAPI, SQLAlchemy 2.0, Pydantic, Swagger, Python (≥3.10).
- Frontend: Vue3, Ant Design Vue, TypeScript, Vite, NodeJS (≥20).
- Infrastructure: PostgreSQL and Redis.

- Incoming HTTP requests to FastAPI.
- API calls from the Vue frontend to backend endpoints.
- Rectangle for physical components (servers, databases).
- Rounded rectangles or circles for logical layers (API, services).
- Annotations where necessary (like “RBAC Logic”, “Authentication (JWT + OAuth2)”) to emphasize key aspects.
- Be sure to include initialization scripts and static API docs since they contribute to the project’s operability.

- The Frontend layer (Vue3) with its API integrations, routing, and state management.
- The Backend layer subdivided into API (routes, middlewares), Business (services & RBAC), Data (CRUD models, schemas), and configuration.
- Infrastructure elements such as PostgreSQL, Redis, and API documentation interfaces.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FEApp["Frontend Application (Vue3)"]:::frontend
        FEIntegrations["API Integrations"]:::frontend
        FEAxios["Axios Configuration"]:::frontend
        FEApp -->|"triggers"| FEIntegrations
        FEIntegrations -->|"utilizes"| FEAxios
    end

    %% Backend Layer
    subgraph "Backend Layer"
        APIEndpoints["API Endpoints (FastAPI)"]:::backend
        CoreFunc["Core Functionality (Config, Middlewares, Security, Logging)"]:::backend
        Services["Services (Business Logic & RBAC)"]:::backend
        CRUD["CRUD Operations"]:::backend
        DataModels["Data Models"]:::backend
        DataSchemas["Data Schemas"]:::backend
        InitScripts["Initialization Scripts"]:::backend
        APIDocs["API Documentation (Swagger UI)"]:::backend

        APIEndpoints -->|"routes to"| CoreFunc
        APIEndpoints -->|"delegates to"| Services
        CoreFunc -->|"supports"| Services
        Services -->|"invokes"| CRUD
        CRUD -->|"operates on"| DataModels
        CRUD -->|"validates with"| DataSchemas
        Services -->|"caches data"| Cache
        CRUD -->|"manages sessions"| Cache
        InitScripts ---|"seeds"| DataModels
        APIEndpoints ---|"provides docs via"| APIDocs
    end

    %% Infrastructure Components
    subgraph "Infrastructure"
        Database["PostgreSQL Database"]:::infra
        Cache["Redis Cache/Session"]:::infra
    end

    %% Connections between Frontend and Backend/Infra
    FEApp -->|"HTTP Requests/REST_API_Calls"| APIEndpoints
    Services -->|"reads/writes"| Database
    CRUD -->|"reads/writes"| Database

    %% Class Definitions for coloring
    classDef frontend fill:#D0E6A5,stroke:#333,stroke-width:2px;
    classDef backend fill:#fefbd8,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFDFD3,stroke:#333,stroke-width:2px;

    %% Click Events
    click APIEndpoints "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/api/system"
    click CoreFunc "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/core"
    click Services "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/services/system"
    click CRUD "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/crud/system"
    click DataModels "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/models"
    click DataSchemas "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/schemas/system"
    click InitScripts "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/scripts/initialize"
    click APIDocs "https://github.com/senqi-666/fastapi-vue-admin/tree/main/backend/app/static/swagger"
    click FEApp "https://github.com/senqi-666/fastapi-vue-admin/tree/main/web/src"
    click FEIntegrations "https://github.com/senqi-666/fastapi-vue-admin/tree/main/web/src/api"
    click FEAxios "https://github.com/senqi-666/fastapi-vue-admin/blob/main/web/src/utils/axios.js"
```
