# insistence/dash-fastapi-admin architecture

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

- Interactive diagram: https://gitdiagram.com/insistence/dash-fastapi-admin
- Repository: https://github.com/insistence/dash-fastapi-admin

## Overview

##### Project Type and Purpose
- This is a full‑stack, front‑end/back‑end‑separated Python rapid‑development admin platform (“Dash‑FastAPI‑Admin”).
- Frontend uses Dash + feffery‑antd‑components; backend uses FastAPI + SQLAlchemy + MySQL/PostgreSQL + Redis + OAuth2/JWT.

##### High‑Level Architecture Components
a. Client (Browser)
b. Frontend Server (Dash Application)
c. Backend Server (FastAPI Application)
d. Data Store (MySQL or PostgreSQL)
e. Cache / Message Broker (Redis)
f. Scheduler (APScheduler or similar)
g. External Proxy / Load Balancer (e.g., Nginx)

##### Component Relationships & Data Flow
- Browser sends HTTP/WebSocket requests to the Dash frontend over port (e.g., 8088).
- Dash handles routing, renders React‑style UI components, and triggers Python callbacks.
- Dash callbacks that need data invoke REST API calls (via fetch or internal router) to FastAPI on port (e.g., 9099).
- FastAPI exposes endpoints in “module_admin” and “module_task” controllers.
- Controllers → call Services → call DAOs → interact with database.
- FastAPI uses OAuth2/JWT for authentication; tokens stored/checked against Redis.
- Services may cache or rate‑limit using Redis (get_redis).
- Scheduled tasks in module_task/​scheduler_test use the same database + Redis via the scheduler component.
- All long‑running or background jobs are managed by the scheduler service.
- Database holds persistent entities (DO: data objects, VO: view objects).
- Redis holds session tokens, rate‑limit data, scheduler metadata.
- Nginx or similar proxies incoming traffic, routes “/prod-api” to FastAPI and “/” to Dash.

##### Architectural Patterns & Design Principles
- Layered (Controller → Service → DAO → Database)
- Modular (“module_admin”, “module_task”, “sub_applications”)
- Dependency injection for DB, Redis, Scheduler via get_db, get_redis, get_scheduler
- Aspect‑oriented hooks (data_scope, interface_auth)
- Middleware pipeline (CORS, GZip, error handling)
- Clear separation of concerns: config, exceptions, utils.

##### Technologies & Frameworks to Call Out
- Dash, feffery‑antd‑components, feffery‑utils‑components
- FastAPI, SQLAlchemy ORM
- MySQL / PostgreSQL (config/database.py)
- Redis (config/get_redis.py)
- OAuth2 & JWT (module_admin/aspect/interface_auth.py)
- APScheduler or built‑in scheduler (config/get_scheduler.py)
- Nginx proxy (README nginx snippet)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    Browser["Client (Browser)"]:::client
    Nginx["Nginx Proxy"]:::infra

    %% Frontend Layer
    subgraph "Frontend Server (Dash Application)"
        direction TB
        FE_ROOT["dash-fastapi-frontend/"]:::frontend
        AppPY["app.py"]:::frontend
        ServerPY["server.py / wsgi.py"]:::frontend
        Assets["assets/"]:::frontend
        Callbacks["callbacks/"]:::frontend
        API_Router["api/router.py"]:::frontend
        API_Endpoints["api/**/*.py"]:::frontend
        FE_Config["config/"]:::frontend
        Store["store/store.py"]:::frontend
        Utils_FE["utils/"]:::frontend
        Env_FE[".env.dev/.env.prod"]:::frontend

        FE_ROOT --> AppPY
        FE_ROOT --> ServerPY
        FE_ROOT --> Assets
        FE_ROOT --> Callbacks
        FE_ROOT --> API_Router
        FE_ROOT --> API_Endpoints
        FE_ROOT --> FE_Config
        FE_ROOT --> Store
        FE_ROOT --> Utils_FE
        FE_ROOT --> Env_FE
    end

    %% Backend Layer
    subgraph "Backend Server (FastAPI Application)"
        direction TB
        BE_ROOT["dash-fastapi-backend/"]:::backend
        AppPY_BE["app.py"]:::backend
        ServerPY_BE["server.py"]:::backend
        ConfigBE["config/"]:::backend
        DatabaseCFG["database.py"]:::backend
        RedisCFG["get_redis.py"]:::backend
        SchedulerCFG["get_scheduler.py"]:::backend
        DBInjector["get_db.py"]:::backend
        Middlewares["middlewares/"]:::crosscut
        Exceptions["exceptions/"]:::crosscut
        SubApps["sub_applications/"]:::backend
        ModuleAdminCtrl["module_admin/controller/"]:::backend
        ModuleAdminSvc["module_admin/service/"]:::backend
        ModuleAdminDAO["module_admin/dao/"]:::backend
        ModuleAdminDO["module_admin/entity/do/"]:::backend
        ModuleAdminVO["module_admin/entity/vo/"]:::backend
        AdminAnnot["module_admin/annotation/"]:::crosscut
        AdminAspect["module_admin/aspect/"]:::crosscut
        InterfaceAuth["interface_auth.py"]:::crosscut
        ModuleTaskSch["module_task/scheduler_test.py"]:::backend
        SQLScripts["sql/"]:::infra
        Utils_BE["utils/"]:::backend
        Env_BE[".env.dev/.env.prod"]:::backend

        BE_ROOT --> AppPY_BE
        BE_ROOT --> ServerPY_BE
        BE_ROOT --> ConfigBE
        ConfigBE --> DatabaseCFG
        ConfigBE --> RedisCFG
        ConfigBE --> SchedulerCFG
        ConfigBE --> DBInjector
        BE_ROOT --> Middlewares
        BE_ROOT --> Exceptions
        BE_ROOT --> SubApps
        BE_ROOT --> ModuleAdminCtrl
        BE_ROOT --> ModuleAdminSvc
        BE_ROOT --> ModuleAdminDAO
        BE_ROOT --> ModuleAdminDO
        BE_ROOT --> ModuleAdminVO
        BE_ROOT --> AdminAnnot
        BE_ROOT --> AdminAspect
        BE_ROOT --> InterfaceAuth
        BE_ROOT --> ModuleTaskSch
        BE_ROOT --> SQLScripts
        BE_ROOT --> Utils_BE
        BE_ROOT --> Env_BE
    end

    %% Infrastructure
    DB["Database (MySQL/PostgreSQL)"]:::infra
    Redis["Redis (Cache/Message Broker)"]:::infra
    Scheduler["APScheduler Scheduler"]:::crosscut

    %% Data Flows
    Browser -->|HTTP/WebSocket| Nginx
    Nginx -->|/ →| FE_ROOT
    Nginx -->|/prod-api →| BE_ROOT
    FE_ROOT -->|REST API Calls| BE_ROOT
    ModuleAdminCtrl -->|calls| ModuleAdminSvc
    ModuleAdminSvc -->|uses| ModuleAdminDAO
    ModuleAdminDAO -->|SQLAlchemy| DB
    ModuleAdminSvc -->|cache| Redis
    InterfaceAuth -->|OAuth2/JWT| Redis
    Scheduler -->|runs tasks in| ModuleTaskSch
    Scheduler -->|DB/Redis access| DB
    Scheduler -->|DB/Redis access| Redis

    %% Click Events - Frontend
    click FE_ROOT "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/"
    click AppPY "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-frontend/app.py"
    click ServerPY "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-frontend/server.py"
    click ServerPY "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-frontend/wsgi.py"
    click Assets "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/assets/"
    click Callbacks "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/callbacks/"
    click API_Router "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-frontend/api/router.py"
    click API_Endpoints "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/api/"
    click FE_Config "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/config/"
    click Store "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-frontend/store/store.py"
    click Utils_FE "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-frontend/utils/"

    %% Click Events - Backend
    click BE_ROOT "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/"
    click AppPY_BE "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/app.py"
    click ServerPY_BE "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/server.py"
    click ConfigBE "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/config/"
    click DatabaseCFG "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/config/database.py"
    click RedisCFG "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/config/get_redis.py"
    click SchedulerCFG "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/config/get_scheduler.py"
    click DBInjector "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/config/get_db.py"
    click Middlewares "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/middlewares/"
    click Exceptions "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/exceptions/"
    click SubApps "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/sub_applications/"
    click ModuleAdminCtrl "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/controller/"
    click ModuleAdminSvc "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/service/"
    click ModuleAdminDAO "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/dao/"
    click ModuleAdminDO "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/entity/do/"
    click ModuleAdminVO "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/entity/vo/"
    click AdminAnnot "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/annotation/"
    click AdminAspect "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/module_admin/aspect/"
    click InterfaceAuth "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/module_admin/aspect/interface_auth.py"
    click ModuleTaskSch "https://github.com/insistence/dash-fastapi-admin/blob/master/dash-fastapi-backend/module_task/scheduler_test.py"
    click SQLScripts "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/sql/"
    click Utils_BE "https://github.com/insistence/dash-fastapi-admin/tree/master/dash-fastapi-backend/utils/"

    %% Styles
    classDef client fill:#D0E6F7,stroke:#2D64A2,color:#0B2A5A;
    classDef frontend fill:#D3E5FF,stroke:#3B70E3,color:#1A3D8F;
    classDef backend fill:#D4F8D4,stroke:#3BAF3B,color:#1A5A1A;
    classDef infra fill:#FFE8B2,stroke:#E39A00,color:#7A5600;
    classDef crosscut fill:#E5D4FF,stroke:#A35BE3,color:#462A5A;
```
