# apconw/sanic-web architecture

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

- Interactive diagram: https://gitdiagram.com/apconw/sanic-web
- Repository: https://github.com/apconw/sanic-web

## Overview

##### Main System Components
- Frontend: The “web” directory contains a Vue3 + TypeScript application built on Vite. It comprises components, assets, views, routing, state management, and utilities for interacting with backend APIs.
- Backend Server: The root-level Python files (serv.py, config, controllers, services, common, constants) indicate that the backend is built on Sanic (a high-performance asynchronous framework). Controllers manage different API endpoints (e.g., common_chat_api, db_chat_api, dify_chat_api, ta_assistant_api, user_service_api) while services implement business logic.
- Docker & Middleware: The “docker” directory contains multiple docker-compose files and Dockerfile setups for components such as Dify, MySQL, Minio, Couchbase, Elasticsearch, and other middleware (e.g., tidb, pgvector, nginx, certbot). This demonstrates a containerized environment.
- External Services: Integration points are apparent for large model APIs (via Dify and third-party services), as well as for MinIO (object storage) and MySQL (data storage) with initialization scripts in “initialize_mysql.py” and “init.sh”.
- Components / Libraries: The presence of “common”, “component”, and “config” directories shows shared utilities (date_util, pdf_util, redis_tool, token_decorator, etc.) that are used across the backend.

##### Relationships & Interactions
- Backend Internal Flow: Within the backend, controllers call services which in turn might use utility functions from “common” and configuration files from the “config” directory. Services include logic for handling chat API endpoints, data processing, and integration with Text2SQL.
- Integration with External Models: The backend interacts with large model providers (Dify, Ollama, DeepSeek) via the configured APIs and docker-compose services. Represent these external services as separate components connected via secure API calls.
- Data Flow: Demonstrate how data flows from incoming client requests from the frontend, processed by controllers, utilizing service logic and storage (MySQL, Minio), and then responses returned to the client. Likewise, show the processing flow for CSV uploads and PDF processing.

##### Architectural Patterns and Design Principles
- Extensibility: The README emphasizes “易于二次开发” (easy to extend). Indicate extensibility points such as additional controllers or services, as well as integration nodes for adding further large model providers.

##### Specific Elements to Incorporate

- Optionally, include schematic representations of the workflow for key features (e.g., “数据问答” – data Q&A via Text2SQL and ECharts) to illustrate how a client query is processed end-to-end.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    Browser["Web Browser (Client)"]:::client
    FE["Frontend – Vue3 + TS"]:::frontend

    %% Backend Layer
    subgraph "Backend Layer"
        BS["Backend – Sanic API Server"]:::backend
        CTRLS["API Controllers"]:::backend
        SERVS["Business Logic Services"]:::backend
        UTILS["Shared Utility Libraries"]:::backend
        CONF["Configuration Files"]:::backend
        CONST["Constants"]:::backend
    end

    %% Deployment / Infrastructure Layer
    subgraph "Deployment / Infrastructure"
        Docker["Docker & Containerized Deployment"]:::docker
        MySQL["MySQL Database"]:::db
        MySQLConf["MySQL Config"]:::db
        Minio["MinIO Object Storage"]:::db
        Elastic["Elasticsearch Service"]:::docker
        Nginx["Nginx Reverse Proxy"]:::docker
        ExternalModels["Large Model Providers (Dify, Ollama, DeepSeek)"]:::external
    end

    %% Extended Functionality
    subgraph "Extended Functionality"
        Components["Components & Libraries"]:::extended
    end

    %% Connections
    Browser -->|"sendsRequest"| FE
    FE -->|"REST_API_Call"| BS
    BS -->|"routesTo"| CTRLS
    CTRLS -->|"invokes"| SERVS
    SERVS -->|"uses_UTILS"| UTILS
    SERVS -->|"reads_Config"| CONF
    SERVS -->|"uses_CONST"| CONST
    SERVS -->|"DB_Operations"| MySQL
    MySQL -->|"configuredBy"| MySQLConf
    SERVS -->|"objectStorage"| Minio
    SERVS -->|"integratesAPI"| ExternalModels
    FE -->|"servedVia"| Nginx
    Docker -->|"hosts_Backend"| BS
    Docker -->|"hosts_Database"| MySQL
    Docker -->|"hosts_Storage"| Minio
    Docker -->|"hosts_Search"| Elastic
    Docker -->|"hosts_Proxy"| Nginx

    %% Click Events
    click FE "https://github.com/apconw/sanic-web/tree/master/web/"
    click BS "https://github.com/apconw/sanic-web/blob/master/serv.py"
    click CTRLS "https://github.com/apconw/sanic-web/tree/master/controllers/"
    click SERVS "https://github.com/apconw/sanic-web/tree/master/services/"
    click UTILS "https://github.com/apconw/sanic-web/tree/master/common/"
    click CONF "https://github.com/apconw/sanic-web/tree/master/config/"
    click CONST "https://github.com/apconw/sanic-web/tree/master/constants/"
    click Docker "https://github.com/apconw/sanic-web/tree/master/docker/"
    click MySQL "https://github.com/apconw/sanic-web/blob/master/docker/init_sql.sql"
    click MySQLConf "https://github.com/apconw/sanic-web/blob/master/docker/my.cnf"
    click Minio "https://github.com/apconw/sanic-web/blob/master/common/minio_util.py"
    click Components "https://github.com/apconw/sanic-web/tree/master/component/"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef docker fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef db fill:#F08080,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef extended fill:#D8BFD8,stroke:#000,stroke-width:2px;
```
