# lybbn/django-vue-lyadmin architecture

> Architecture diagram of the GitHub repository lybbn/django-vue-lyadmin, 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/lybbn/django-vue-lyadmin
- Repository: https://github.com/lybbn/django-vue-lyadmin

## Overview

##### Project Components
- Backend: A Django application managing business logic, authentication (using JWT via drf-simplejwt), and a set of well‐organized Django “apps” (e.g., address, logins, lymessages, mall, oauth, etc.). It integrates Celery tasks, web socket communications (via channels), and RESTful APIs.
- Frontend: A Vue-based interface implemented in two versions – one based on webpack (the “frontend” directory) and one using Vite (“frontend_vite”). These provide the user interface for the admin dashboard, low-code form and CRUD generation as well as various interactive pages.
- Third-Party Services & Integrations: The system integrates with external payment gateways (e.g., Alipay, WeChat, and more), SMS providers, and possibly other external APIs.
- Supporting Infrastructure: Docker-compose is used to deploy containers for the Django server, MySQL, Redis, and Nginx. Static file serving and deployment orchestration are also covered.

##### File Structure for Architectural Cues
- The backend folder contains:
- A main Django project (application) with configuration files including asgi.py, wsgi.py, settings.py, which indicate support for both synchronous and asynchronous workflows.
- An “apps” folder that segments various functional modules such as “lyusers”, “lymonitor”, “mall”, “oauth”, etc. This modular structure suggests a clean separation of concerns.
- Utility modules and extra apps (e.g., an Alipay SDK), migration scripts, and management commands.
- Celery integration (celery.py in the application folder) and periodic task definitions.
- The frontend and frontend_vite directories contain a modern Vue3 project with components, views, API configurations, and asset management. They use standard Vue ecosystem libraries like elementplus.
- Docker-related files (docker-compose.yml, docker_env) denote a containerized deployment with individual services (MySQL, Redis, Django, nginx).

a. Main Components:
- Frontend Client(s): Represented by both the traditional Vue project and the Vite variant.
- API Gateway / Backend Server: Django server exposing REST APIs and serving web socket endpoints, handling authentication, business logic, and admin functionalities.
- Task Scheduler: A dedicated Celery worker (and beat scheduler) handling asynchronous tasks and periodic jobs.
- Database: MySQL (with designated migrations and SQL scripts) that stores user data, system configurations, and transactional records.
- Cache & Message Queue: Redis is used for caching and possibly as a broker (for Celery) or session storage.
- Web Server / Reverse Proxy: Nginx (as configured in the Docker environment) handling static file serving, SSL termination, and proxying requests to the backend.
- External Services: Represent integrations like payment gateways (Alipay, WeChat), SMS services, and third-party APIs.

b. Relationships and Data Flow:
- Celery Workers (Task Scheduler) are triggered by the Backend to execute asynchronous or scheduled tasks and may also write results back to the Database.
- The Nginx component functions as a reverse proxy routing external client requests to the appropriate internal service (static frontend files, Django API, and web socket endpoints).
- Interactions with External Services (e.g., Payment, SMS, etc.) should be illustrated as outbound connections from the Backend.

c. Architectural Patterns & Design Principles:
- Modular Architecture: Break down the backend into multiple Django apps, each with a clear purpose.
- Separation of Concerns: Distinct separation between frontend (presentation) and backend (business logic & APIs).
- Asynchronous Processing: Use of Celery for background task processing, indicating separation between synchronous request/response flows and background job processing.
- Containerization: Docker-compose deployment demonstrates separation of infrastructure (database, cache, web server) into individual isolated services.
- Security and Authentication: Use of JWT for authentication and permissions control.

d. Relevant Technologies:
- Frontend: Vue 3, ElementPlus, Tinymce, Vite/Webpack.
- Backend: Python, Django, Django REST Framework (drf), Celery, Channels.
- Infrastructure: MySQL, Redis, Nginx, Docker/Docker Compose.
- Additional libraries: Payment SDKs, SMS utilities, and other integration utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Infrastructure
    Nginx["Nginx: Reverse Proxy"]:::infra

    %% Frontend Clients Subgraph
    subgraph "Frontend Clients"
        FWebpack["Vue (Webpack)"]:::frontend
        FVite["Vue (Vite)"]:::frontend
    end

    %% Backend Server and internal modules Subgraph
    subgraph "Backend System"
        Backend["Django Server"]:::backend
        Apps["Django Apps (Modular)"]:::backend
        JWT["JWT Auth & BusinessLogic"]:::backend
        Celery["Celery Task Scheduler"]:::worker
        CeleryTasks["Periodic Tasks"]:::worker
        WS["WebSocket Services"]:::backend
        CodeGen["Code Generation & Management"]:::backend
        ExtPayment["Alipay SDK"]:::backend
        PaymentKeys["Payment Key Files"]:::backend
        Utility["Utility Modules"]:::backend
    end

    %% Infrastructure Services Subgraph
    subgraph "Infrastructure"
        DB["MySQL Database"]:::db
        Redis["Redis Cache/Broker"]:::db
    end

    %% External Services Node
    External["External Services<br/>(Payment, SMS, APIs)"]:::external

    %% Connections from Nginx
    Nginx -->|"serves"| FWebpack
    Nginx -->|"serves"| FVite
    Nginx -->|"routes"| Backend

    %% Connections within Backend System
    Backend -->|"invokes"| Apps
    Apps -->|"handles"| JWT
    Backend -->|"triggers"| Celery
    Celery -->|"schedules"| CeleryTasks
    Backend -->|"manages"| WS
    Backend -->|"executes"| CodeGen
    Backend -->|"integrates"| ExtPayment
    Backend -->|"integrates"| PaymentKeys
    Backend -->|"utilizes"| Utility

    %% Backend interactions with Infrastructure
    Backend -->|"queries"| DB
    Backend -->|"caches"| Redis

    %% Celery updates DB
    CeleryTasks -->|"updates"| DB

    %% Backend external integrations
    Backend -->|"calls"| External

    %% Frontend to Backend communication
    FWebpack -->|"API calls"| Backend
    FVite -->|"API calls"| Backend

    %% Click Events
    click Nginx "https://github.com/lybbn/django-vue-lyadmin/tree/master/docker_env/nginx"
    click FWebpack "https://github.com/lybbn/django-vue-lyadmin/tree/master/frontend"
    click FVite "https://github.com/lybbn/django-vue-lyadmin/tree/master/frontend_vite"
    click Backend "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/application"
    click Apps "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/apps"
    click JWT "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/apps"
    click Celery "https://github.com/lybbn/django-vue-lyadmin/blob/master/backend/application/celery.py"
    click CeleryTasks "https://github.com/lybbn/django-vue-lyadmin/blob/master/backend/apps/lycrontab/tasks.py"
    click WS "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/apps/lywebsocket"
    click CodeGen "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/mysystem/management/commands"
    click ExtPayment "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/extra_apps/python_alipay_sdk"
    click PaymentKeys "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/key"
    click Utility "https://github.com/lybbn/django-vue-lyadmin/tree/master/backend/utils"
    click DB "https://github.com/lybbn/django-vue-lyadmin/tree/master/docker_env/mysql"
    click Redis "https://github.com/lybbn/django-vue-lyadmin/tree/master/docker_env/redis"

    %% Styles
    classDef frontend fill:#CCFFCC,stroke:#008000,stroke-width:2px;
    classDef backend fill:#FFCCCC,stroke:#800000,stroke-width:2px;
    classDef worker fill:#FFE4B5,stroke:#CD853F,stroke-width:2px;
    classDef db fill:#CCCCFF,stroke:#0000FF,stroke-width:2px;
    classDef external fill:#FFFFCC,stroke:#CCCC00,stroke-width:2px;
    classDef infra fill:#E0FFFF,stroke:#008B8B,stroke-width:2px;
```
