# dafengzhen/youdeyiwu architecture

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

- Interactive diagram: https://gitdiagram.com/dafengzhen/youdeyiwu
- Repository: https://github.com/dafengzhen/youdeyiwu

## Overview

##### Project type and purpose
- Youdeyiwu is a full-stack, multi-platform open-source lightweight forum.
- It consists of a Java Spring Boot backend (REST API), multiple clients (Flutter mobile/desktop, Angular/Electron desktop, Next.js web), a documentation site, and hosting/deployment scripts.

##### Key directories and architectural patterns
- /src (Java Spring Boot) follows a layered architecture:
· Controllers (REST endpoints)
· Services (business logic)
· Repositories (data access, JPA/Flyway migrations)
· Entities/DTOs/VOs (domain model)
· Aspects (AOP for logging, security, points, events)
· Event/listener modules (application events, notifications)
· Security (JWT filters, AccessDecisionManager)
- /app (Flutter): cross-platform mobile & desktop app using Provider for state, API client utilities, generated JSON serialization.
- /desktop (Angular + Electron): desktop app using NgRx (actions, reducers, effects), Angular modules & components, Electron preload/main.
- /web (Next.js): React/TypeScript web app using Next.js App Router, React Query-style data fetching (“actions”), contexts, interfaces.
- /hosting: Docker Compose for reverse proxy / static hosting.
- /docs: VitePress documentation site.

##### Main components
- Clients Layer (left):
- Mobile/Desktop App (Flutter)
- Angular/Electron Desktop App
- Next.js Web Application
- API Layer (center):
- Java Spring Boot REST API
– Controllers & AOP aspects
– Service Layer
– Repository Layer (JPA + Flyway migrations)
– Security Module (JWT authentication/authorization)
– Event Bus (Spring ApplicationEvents, listeners)
- Persistence Layer (right):
- Relational Database (e.g., PostgreSQL/MySQL)
- File Storage Service (local FS or S3/OSS, configurable)
- Supporting Infrastructure (bottom/right):
- Cache Layer (Redis or in-memory, via CacheConfig)
- Message Broker (if external events or notifications needed)
- CDN / Static Hosting (for web assets, via hosting folder)
- DevOps / Deployment (bottom):
- Docker / docker-compose
- CI/CD workflows (GitHub Actions)
- Vercel / Netlify (for Next.js)
- Electron build scripts

##### Relationships and interactions
- API Layer reads/writes to the Database and File Storage.
- API Layer publishes internal events consumed by NotificationEventIntegrator and Listeners.
- Cache sits between API and Database for read-through/write-back.
- Deployment pipelines push Docker images for API and host static frontends on CDN or Electron installers.

##### Architectural patterns & design principles
- Backend: layered architecture, separation of concerns, AOP for cross-cutting.
- Persistence: repository pattern, data migrations (Flyway).
- Security: JWT-based stateless auth, custom filters, access decision manager.
- Frontends:
- Flutter uses Provider for DI/state, code generation for JSON models
- Angular/Electron uses NgRx (Redux pattern): actions, reducers, effects
- Next.js uses React Server Components/App Router, encapsulated “actions” for data fetching, React Context

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients" 
        direction TB
        Flutter["Flutter Mobile/Desktop App"]:::clients
        AngularDesktop["Angular/Electron Desktop App"]:::clients
        NextWeb["Next.js Web Application"]:::clients
    end

    subgraph "API Layer"
        direction TB
        SpringBoot["YoudeyiwuApplication (Entry Point)"]:::api
        Controllers["Controllers"]:::api
        Services["Service Layer"]:::api
        Repositories["JPA Repositories"]:::api
        Flyway["Flyway Migrations"]:::api
        Domain["Domain Model"]:::api
        Entities["Entities"]:::api
        DTOs["DTOs"]:::api
        VOs["VOs"]:::api
        Aspects["AOP Aspects"]:::api
        EventBus["Event Bus & Listeners"]:::api
        EventClasses["Event Classes & Integrator"]:::api
        Listeners["Application Listeners"]:::api
        Security["Security Module (JWT)"]:::api
        FileSvc["FileService"]:::api
        FileSvcImpl["FileServiceImpl"]:::api
    end

    subgraph "Persistence Layer"
        direction TB
        Database["Relational Database"]:::db
        FileStorage["File Storage Service"]:::db
    end

    subgraph "Infrastructure"
        direction TB
        CacheLayer["Cache Layer (Redis/in-memory)"]:::infra
        MsgBroker["Message Broker"]:::infra
        CDN["CDN / Static Hosting"]:::infra
    end

    subgraph "DevOps / Deployment"
        direction TB
        DockerAPI["Dockerfile & docker-compose"]:::devops
        HostingCompose["Hosting docker-compose"]:::devops
        CI["CI/CD Workflows"]:::devops
        Docs["Documentation Site"]:::devops
        Scripts["Scripts & Utilities"]:::devops
    end

    %% Client to API
    Flutter -->|HTTPS| Controllers
    AngularDesktop -->|HTTPS| Controllers
    NextWeb -->|HTTPS| Controllers

    %% API internal flow
    Controllers -->|invokes| Services
    Controllers -->|auth via JWT| Security
    Services -->|calls| Repositories
    Repositories -->|reads/writes via JDBC| Database
    Services -->|uses| FileStorage
    Services -->|publishes| EventBus
    EventBus -->|triggers| Listeners
    Services -->|cross-cutting| Aspects

    %% Cache between API and DB
    Services -->|read/write| CacheLayer
    CacheLayer -.->|fallback| Database

    %% Messaging
    MsgBroker -->|events| EventBus

    %% CDN for frontends
    Controllers -->|serves static| CDN
    CDN -->|delivers assets| NextWeb

    %% DevOps flows
    CI --> DockerAPI
    CI --> HostingCompose
    DockerAPI --> Controllers
    HostingCompose --> CDN
    CI --> Docs
    CI --> Scripts

    %% Click Events
    click Flutter "https://github.com/dafengzhen/youdeyiwu/tree/main/app/"
    click AngularDesktop "https://github.com/dafengzhen/youdeyiwu/tree/main/desktop/"
    click NextWeb "https://github.com/dafengzhen/youdeyiwu/tree/main/web/"
    click SpringBoot "https://github.com/dafengzhen/youdeyiwu/blob/main/src/main/java/com/youdeyiwu/YoudeyiwuApplication.java"
    click Controllers "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/controller/"
    click Services "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/service/"
    click Repositories "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/repository/"
    click Flyway "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/resources/db/migration/"
    click Entities "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/model/entity/"
    click DTOs "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/model/dto/"
    click VOs "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/model/vo/"
    click Aspects "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/aspect/"
    click EventClasses "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/event/"
    click Listeners "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/listener/"
    click Security "https://github.com/dafengzhen/youdeyiwu/tree/main/src/main/java/com/youdeyiwu/security/"
    click FileSvc "https://github.com/dafengzhen/youdeyiwu/blob/main/src/main/java/com/youdeyiwu/service/file/FileService.java"
    click FileSvcImpl "https://github.com/dafengzhen/youdeyiwu/blob/main/src/main/java/com/youdeyiwu/service/file/FileServiceImpl.java"
    click CacheLayer "https://github.com/dafengzhen/youdeyiwu/blob/main/src/main/java/com/youdeyiwu/config/CacheConfig.java"
    click DockerAPI "https://github.com/dafengzhen/youdeyiwu/blob/main/docker-compose.yml"
    click HostingCompose "https://github.com/dafengzhen/youdeyiwu/blob/main/hosting/docker-compose.yml"
    click CI "https://github.com/dafengzhen/youdeyiwu/tree/main/.github/workflows/"
    click Docs "https://github.com/dafengzhen/youdeyiwu/tree/main/docs/"
    click Scripts "https://github.com/dafengzhen/youdeyiwu/tree/main/scripts/"

    %% Styles
    classDef clients fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef api fill:#DFF2BF,stroke:#4F8A10,color:#4F8A10
    classDef db fill:#FFD2D2,stroke:#D8000C,color:#D8000C
    classDef infra fill:#E0E0E0,stroke:#888888,color:#555555
    classDef devops fill:#F5F5F5,stroke:#AAAAAA,color:#333333
```
