# lmmax0/hongdou architecture

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

- Interactive diagram: https://gitdiagram.com/lmmax0/hongdou
- Repository: https://github.com/lmmax0/hongdou

## Overview

##### Project Type and Purpose
- The project is a full-stack application focused on providing video playback along with the ability for remote friends to synchronously watch videos (“红豆” – HongDou).
- The README confirms its purpose as a platform that involves video playback and synchronized viewing, while the file tree supports both a front-end (built with Vue.js and managed with webpack and Node tools) and a Java-based back-end (using Spring Boot, Spring Security, and more).

##### Analyzing the File Structure
- Frontend (myweb Folder):
- Contains configuration files such as babel.config.json, package.json, webpack.config.js.
- The “src” directory includes Vue components (e.g., App.vue) and JavaScript libraries (flv.js, hls.js) for media handling.
- index.html and server.js indicate that this layer might serve static assets or run a lightweight Node-based server.
- Backend (src/main Directory):
- Organized as a standard Maven/Spring Boot project with pom.xml at the root of the backend.
- Java packages include controllers, services, security, ffmpeg operations, exception handling, data access objects (mappers), and configurations.
- Key components include HongDouApplication (the Spring Boot main class), various WebSocket, Spring Security, and JWT-related classes, plus custom components for media handling (FFmpegUtils, TranscodeConfig).
- Resources contain configurations in application.yml, log4j2.xml, and MyBatis mapper XML files.

##### Key Architectural Components
a. Frontend Component:
- A Vue.js single-page application (SPA) that likely handles routing, UI, and direct video playback using libraries like flv.js and hls.js.
- Communicates with the backend via APIs and possibly WebSocket connections for synchronized viewing.
b. Backend Component:
- A Spring Boot application acting as the core REST API server.
- Several modules in the backend:
- Controllers: Expose REST endpoints for user management, video processing, and real-time synchronization (e.g., HelloController, UserController, UploadController).
- Security Module: Managed via SpringSecurityConfig, custom authentication providers, JWT filters, LDAP authenticators, and login filters to control access and authentication.
- Database Access: Uses MyBatis (evident from UserMapper.xml, RoleMapper.xml and DAO packages) for persistent storage of user data, roles, etc.
- WebSocket Services: Classes like WebSocketConfig and WebSocketService to support real-time communication for synchronized video sessions.
- FFmpeg Module: Provides video transcoding and media processing functionalities (FFmpegUtils, TranscodeConfig, MediaInfo).
- Exception Handling & Logging: GlobalExceptionHandler, WebLogAspect for managing errors and logging behaviors.
c. Integration & External Components:
- Potential integration with external services for LDAP authentication (shown by the LDAP-related providers) and possibly cloud storage for uploads.
- The use of JWT and WebSocket hint at real-time and secure communications across the system.

##### Architectural Patterns and Technologies
- MVC Pattern: The separation within the Spring Boot application (Controllers, Services, DAOs) and the Vue frontend follows an MVC approach.
- Security and Real-time Communication: Emphasize the integration of Spring Security, JWT, and WebSocket configurations.
- Media Processing: Highlight the use of FFmpeg-based utilities for video transcoding.
- Technologies & Frameworks:
- Frontend: Vue.js, Webpack, Babel, and associated media libraries.
- Backend: Spring Boot, Spring Security, MyBatis, JWT, WebSocket, and FFmpeg integrations.
- Build and Packaging: Maven (pom.xml) and Node Package Manager (package.json).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["Vue.js Frontend (myweb)"]:::frontend
        F2["App.vue"]:::frontend
        F3["flv.js"]:::frontend
        F4["hls.js"]:::frontend
    end
    F1 --> F2
    F1 --> F3
    F1 --> F4

    %% Backend Layer
    subgraph "Backend Layer"
        B1["Spring Boot Main Application"]:::backend
        B2["REST API Controllers"]:::backend
        subgraph "Security Module"
            B3a["SpringSecurityConfig"]:::security
            B3b["Security Components"]:::security
        end
        subgraph "WebSocket Module"
            B4a["WebSocketConfig"]:::websocket
            B4b["WebSocketService"]:::websocket
        end
        B5["FFmpeg/Media Processing"]:::media
        subgraph "Data Access Layer"
            B6a["DAO Interfaces"]:::data
            B6b["MyBatis Mappers"]:::data
        end
        subgraph "Exception Handling & Logging"
            B7a["GlobalExceptionHandler"]:::exception
            B7b["WebLogAspect"]:::exception
        end
    end

    %% External Systems
    D["Database"]:::external
    L["LDAP Server"]:::external

    %% Connections between Frontend and Backend
    F1 -->|"API_call"| B2
    F1 -->|"WS_connect"| B4a

    %% Internal Backend Flows
    B2 -->|"processes"| B1
    B2 -->|"auth_check"| B3a
    B2 -->|"video_processing"| B5
    B2 -->|"data_access"| B6a
    B2 -->|"error_handling"| B7a
    B4a -->|"real_time_sync"| B1
    B6a -->|"queries"| D
    B3b -->|"LDAP_auth"| L

    %% Click Events
    click F1 "https://github.com/lmmax0/hongdou/tree/master/myweb"
    click F2 "https://github.com/lmmax0/hongdou/blob/master/myweb/src/App.vue"
    click F3 "https://github.com/lmmax0/hongdou/blob/master/myweb/src/js/flv.js"
    click F4 "https://github.com/lmmax0/hongdou/blob/master/myweb/src/js/hls.js"
    click B1 "https://github.com/lmmax0/hongdou/blob/master/src/main/java/com/lmdd/HongDouApplication.java"
    click B2 "https://github.com/lmmax0/hongdou/tree/master/src/main/java/com/lmdd/controller"
    click B3a "https://github.com/lmmax0/hongdou/blob/master/src/main/java/com/lmdd/config/SpringSecurityConfig.java"
    click B3b "https://github.com/lmmax0/hongdou/tree/master/src/main/java/com/lmdd/security"
    click B4a "https://github.com/lmmax0/hongdou/blob/master/src/main/java/com/lmdd/config/WebSocketConfig.java"
    click B4b "https://github.com/lmmax0/hongdou/blob/master/src/main/java/com/lmdd/service/WebSocketService.java"
    click B5 "https://github.com/lmmax0/hongdou/tree/master/src/main/java/com/lmdd/ffmpeg"
    click B6a "https://github.com/lmmax0/hongdou/tree/master/src/main/java/com/lmdd/dao"
    click B6b "https://github.com/lmmax0/hongdou/tree/master/src/main/resources/mappers"
    click B7a "https://github.com/lmmax0/hongdou/tree/master/src/main/java/com/lmdd/exception"
    click B7b "https://github.com/lmmax0/hongdou/blob/master/src/main/java/com/lmdd/filter/WebLogAspect.java"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef security fill:#fc9,stroke:#333,stroke-width:2px;
    classDef websocket fill:#cfc,stroke:#333,stroke-width:2px;
    classDef media fill:#fcc,stroke:#333,stroke-width:2px;
    classDef data fill:#cff,stroke:#333,stroke-width:2px;
    classDef exception fill:#ddd,stroke:#333,stroke-width:2px;
    classDef external fill:#eee,stroke:#333,stroke-width:2px;
```
