# amisadmin/fastapi-amis-admin architecture

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

- Interactive diagram: https://gitdiagram.com/amisadmin/fastapi-amis-admin
- Repository: https://github.com/amisadmin/fastapi-amis-admin

## Overview

##### Main Components Identification

- FastAPI Application: At the top level, the project relies on FastAPI for handling HTTP requests, routing, and auto-generating OpenAPI documentation.

- Admin Module: The “admin” directory (inside fastapi_amis_admin/admin) contains components for building the admin dashboard. It registers ModelAdmin, FormAdmin, and related classes to control the UI behavior and business logic.

- Amis Module: In the “amis” submodule (fastapi_amis_admin/amis), the project provides functions to generate and parse Pydantic-based data models that define the UI components and their presentation.

- CRUD Module: Found in fastapi_amis_admin/crud, this module handles the Create, Read, Update, and Delete operations. It supports integration with SQLAlchemy, SQLModel, or SQLAlchemy 2.0 models so that backend data manipulation is abstracted.

- Global Utilities and Configurations: The “globals” directory defines global elements such as database connections and site-wide dependencies, while the “models” directory provides field definitions and model enhancements for ORM integration.

- Extensions and Utilities: Look at directories like “admin/extensions” and “utils” where additional administrative extensions, parsing utilities, and translation support reside.

- External Dependencies: Label external tools/frameworks like FastAPI, SQLModel/SQLAlchemy, Amis, and Pydantic that the project leverages.

##### Relationships and Data Flow

- User/Client Interface: Clients interact with the system via web browsers. The client-side UI is generated using Amis templates.

- FastAPI Backend: The FastAPI server receives client requests and routes them through the AdminSite instance. Within this, requests are managed by the admin module – which in turn coordinates with the CRUD module to perform data operations.

- API Documentation: FastAPI automatically generates API documentation endpoints – these should be indicated as part of the overall system accessible to developers.

- Extensions and Custom Logic: Clearly mark paths for handling registration of custom ModelAdmin and FormAdmin classes, representing how the admin module extends the system’s capabilities.

##### Architectural Patterns and Design Principles

- Modular Design: Emphasize how the project is divided into discrete, interchangeable modules (amis, crud, and admin) each handling specific responsibilities.

- Separation of Concerns: Highlight the clean separation between UI generation (amis), business logic CRUD operations (crud), and admin-level routing and integrations (admin).

- Reusability and Extensibility: Make note of patterns for easy registration of new admin pages (using decorators like @site.register_admin) and how extensions support additional functionality.

##### Detailed Component Inclusion

- AdminSite (under the admin module): Show that it acts as an orchestrator by registering ModelAdmin and FormAdmin classes and mounting FastAPI routes.

- CRUD Module: Link this with both the admin module and the models/database to indicate where data operations are performed.

- Amis Module: Illustrate the flow from generated or parsed UI JSON (templates like app.html and page.html) to the rendered frontend.

- Configuration/Global Module: Indicate configuration sources (e.g., settings, pre-commit hooks, GitHub workflows) that support continuous integration and static analysis.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        CB["Client Browser (User Interface)"]:::frontend
        AM["Amis Module (UI Templates/Components)"]:::frontend
    end

    %% Backend
    subgraph "Backend"
        FA["FastAPI Application (API Server)"]:::backend
        AD["Admin Dashboard (Admin Module)"]:::backend
        CR["CRUD Operations Module"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        OM["ORM Models (Models)"]:::database
    end

    %% Support Modules
    subgraph "Support Modules"
        GC["Global Configs (Globals)"]:::utilities
        EXA["Admin Extensions"]:::extensions
        UTIL["Utilities"]:::utilities
        ED["External Dependencies"]:::external
    end

    %% Flow Connections
    CB -->|"HTTP_Request"| FA
    FA -->|"Routes"| AD
    AD -->|"DataOps"| CR
    AD -->|"GeneratesUI"| AM
    CR -->|"CRUDQueries"| OM

    ED -->|"Uses"| FA
    ED -->|"ORM"| CR
    ED -->|"UIFramework"| AM

    GC -->|"ProvidesConfig"| FA
    GC -->|"ProvidesConfig"| CR

    EXA -->|"CustomExt"| AD
    UTIL -->|"Parsing/Translation"| AD

    %% Click Events
    click FA "https://github.com/amisadmin/fastapi-amis-admin/blob/master/fastapi_amis_admin/__init__.py"
    click AD "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/admin/"
    click AM "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/amis/"
    click CR "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/crud/"
    click GC "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/globals/"
    click OM "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/models/"
    click EXA "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/admin/extensions/"
    click UTIL "https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/utils/"
    
    %% Styles
    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef utilities fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef extensions fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef database fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
