# pridejoy/malusadmin architecture

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

- Interactive diagram: https://gitdiagram.com/pridejoy/malusadmin
- Repository: https://github.com/pridejoy/malusadmin

## Overview

##### Project type and purpose
- This is a full-stack, front-end/back-end-separated administration system called **Malus Admin**, built on .NET 7/8 + SqlSugar for the back end and Vue3 + Vite4 + TypeScript + NaiveUI for the front end.
- It provides user authentication (JWT), role-based permissions, system configuration, logging, real-time online-user monitoring (SignalR), scheduled backup jobs (Quartz), and a WeChat mini-service endpoint.

##### File structure
Top-level split into:
- **MalusApi/** – Back-end solution with multiple projects:
- **Common** – shared components (DI, config, cache, JWT auth, RabbitMQ, Swagger, dynamic API controllers).
- **Repository** – data models, SqlSugar repository layers.
- **Servers** – business logic services, subdivided into BackStageManager (system management features) and BusinessManager (domain features like gallery, customer, Bing wallpaper).
- **WebApi** – ASP.NET Core Web API host, controllers organized per feature, custom filters/middleware, SignalR hub for online user.
- **BackUpServices** – a console/Quartz service for scheduled tasks (init data, daily Bing image fetch, word jobs).
- **ConsoleApp1** – one-time data initialization scripts.
- **Wechat.Servers** + **Wechat.WebApi** – separate back-end and API layers to support WeChat-specific endpoints.
- **MalusWeb/** – Front-end monorepo (pnpm workspace)
- **src/** – Vue3 Single-Page App: components, layouts, views, router, store (Pinia), service layer invoking back-end APIs (axios), SignalR plugin.
- **doc/dbsql/** – database dump scripts (MySQL, SQL Server).
- Root also has LICENSE, README in multiple languages, and solution files.

##### README
- Confirms front-end/back-end separation, JWT auth, deployment instructions, highlights .NET7 + SqlSugar, Vue3 + NaiveUI.
- Mentions three “ends” (web, mobile, mini-program) but code mainly covers admin web and WeChat API.

##### Main components
a. **User Interfaces**
- **Admin Web UI** (Vue3/NaiveUI SPA)
- **WeChat Mini/Service UI** (calls WeChat.WebApi)
b. **API Gateway / Web API Hosts**
- **MalusAdmin.WebApi** – main HTTP/REST API, JWT authentication
- **Wechat.WebApi** – WeChat-specific endpoints
c. **Business Services** (class-library services)
- **BackStageManager** – system management logic (config, cache, menu, role, user, logging)
- **BusinessManager** – domain entities (gallery, customer, Bing wallpaper, weather forecast)
d. **Infrastructure Components**
- **Common** – DI, config, cache (Memory/Redis), JWT, Swagger, RabbitMQ integration
- **Repository** – SqlSugar repositories mapping to MySQL/SQL Server DB
- **SignalR Hub** – real-time online user notifications
- **Quartz Scheduler** – scheduled jobs (BackupServices)
- **Console Data Init** – one-time seeding JSON into DB
e. **Data Stores**
- **Relational Database** (MySQL/SQL Server)
- **Redis** (optional cache)
- **RabbitMQ** (optional message broker)

##### Relationships and data flows
- **Admin Web UI** → HTTP(S) calls → **MalusAdmin.WebApi** → DI/Config → Business Services → Repository → Database
- **Wechat UI** → HTTP(S) calls → **Wechat.WebApi** → Wechat.Servers logic → Repository → Database
- **MalusAdmin.WebApi** publishes/subscribes via RabbitMQ (through Common) for asynchronous events.
- **SignalR Hub** (inside WebApi) → bi-directional live online-user updates to Admin Web UI.
- **Quartz Jobs** (BackUpServices) and **ConsoleApp1** seed data directly access Repository → Database on schedule or manual run.
- **Cache Layer** (MemoryCacheService/RedisCacheService) sits between Services and Repo for hot data.

##### Architectural patterns and principles
- **Layered Architecture**: UI → API → Services → Repository → Database
- **Dependency Injection** for loose coupling (Common/DI)
- **Configuration-First** via Options pattern
- **Attribute-Driven** auth and permission checks (CustomAuthorizationAttribute)
- **Dynamic API Controllers** for rapid expansion
- **CQRS-Style Separation**: simple DTO inputs/outputs for each service
- **Event-Driven** (RabbitMQ) and **Real-Time** (SignalR) for asynchronous features
- **Scheduled Tasks** (Quartz) for background processing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AdminWebUI["Admin Web UI"]:::frontend
        WeChatUI["WeChat Mini UI"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        MalusWebApi["MalusAdmin.WebApi"]:::api
        WechatWebApi["Wechat.WebApi"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        BackStageManager["BackStageManager Services"]:::service
        BusinessManager["BusinessManager Services"]:::service
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        Common["Shared Infrastructure (Common)"]:::infra
        Repository["Data Repository Layer"]:::infra
        JWTAuth["JWT Authentication Setup"]:::infra
        SwaggerDocs["Swagger & API Docs"]:::infra
        RabbitMqIntegration["RabbitMQ Integration"]:::infra
        SqlSugarComponents["SqlSugar Configuration & Repositories"]:::infra
        SignalRHub["SignalR Hub (OnlineUserHub)"]:::infra
        QuartzJobs["Scheduled Jobs (Quartz Scheduler)"]:::infra
        ConsoleApp1["Backup & Init Service (ConsoleApp1)"]:::infra
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RelationalDB["Relational Database"]:::db
        RedisCache["Redis Cache"]:::db
    end

    %% Connections
    AdminWebUI -->|HTTP/REST| MalusWebApi
    WeChatUI -->|HTTP/REST| WechatWebApi
    MalusWebApi -->|Inject/Config| Common
    MalusWebApi -->|Calls| BackStageManager
    MalusWebApi -->|Calls| BusinessManager
    WechatWebApi -->|Inject/Config| Common
    WechatWebApi -->|Calls| BusinessManager
    BackStageManager -->|Uses| Common
    BusinessManager -->|Uses| Common
    Common -->|Data Access| Repository
    Repository -->|SQL| RelationalDB
    Common -->|Cache| RedisCache
    Common -->|AMQP| RabbitMqIntegration
    Common -->|Auth| JWTAuth
    Common -->|Docs| SwaggerDocs
    MalusWebApi -->|WebSocket| SignalRHub
    SignalRHub -->|WebSocket| AdminWebUI
    QuartzJobs -->|SQL| Repository
    ConsoleApp1 -->|SQL| Repository

    %% Click Events
    click AdminWebUI "https://github.com/pridejoy/malusadmin/tree/master/MalusWeb/src"
    click WeChatUI "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/Wechat.WebApi"
    click MalusWebApi "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/MalusAdmin.WebApi"
    click WechatWebApi "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/Wechat.WebApi"
    click BackStageManager "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Servers/BackStageManger"
    click BusinessManager "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Servers/BusinessManger"
    click Common "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/MalusAdmin.Common"
    click Repository "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/MalusAdmin.Repository"
    click SignalRHub "https://github.com/pridejoy/malusadmin/blob/master/MalusApi/MalusAdmin.Servers/BackStageManger/Hub/OnlineUserHub.cs"
    click QuartzJobs "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.BackUpServices/QuartzJob"
    click ConsoleApp1 "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/ConsoleApp1"
    click JWTAuth "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Common/Components/Authorization/Jwt"
    click SwaggerDocs "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Common/Components/Swagger"
    click RabbitMqIntegration "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Common/Components/RabbitMq"
    click SqlSugarComponents "https://github.com/pridejoy/malusadmin/tree/master/MalusApi/MalusAdmin.Common/Components/Sqlsugar"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef service fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef db fill:#A52A2A,stroke:#333,stroke-width:1px;
```
