# itwanger/paicoding architecture

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

- Interactive diagram: https://gitdiagram.com/itwanger/paicoding
- Repository: https://github.com/itwanger/paicoding

## Overview

##### Major System Components
- Frontend: Represented by the “paicoding-ui” module. This includes static assets (HTML, CSS, JavaScript, Thymeleaf templates, and front‐end frameworks) and handles the presentation layer.
- HTTP/Web Layer: The “paicoding-web” module serves as the entry point for HTTP requests. It contains controllers (both for the main site and the admin area), authentication, security configurations, exception handling, and the overall application startup.
- Business Logic & Data Access: Split between “paicoding-service” (business rules, service implementations, transactional logic, DAO and repository layers) and “paicoding-core” (common tools, utility components, caching, messaging, async, common configuration, and technology-specific support such as for ElasticSearch, Redis, RabbitMQ, etc.).
- Common Interfaces & Data Models: The “paicoding-api” module defines shared domain models, DTOs/VOs, enumerations, commonly used exception classes, and contracts across the layers.

- A layered architecture where the “paicoding-web” layer (HTTP and presentation) sits at the top and calls the “paicoding-service” layer.
- The “paicoding-service” leverages “paicoding-core” for utilities and infrastructure services (e.g., async execution, cache management, permission controls) and uses components defined in “paicoding-api” for consistent data contracts.
- “paicoding-ui” should be depicted as the source of UI templates/assets and static resources that the web layer renders.

##### External and Infrastructure Dependencies
- Full-Text Search: Represent ElasticSearch, which is used for fast text-based queries.
- Messaging: Include RabbitMQ as the asynchronous messaging queue; indicate that parts of the service (e.g., notifications, asynchronous event processing) interact with it.
- WebSocket and Real-Time Components: If applicable, include the WebSocket component (sourced from Spring’s websocket support) for real-time notifications or chat, as suggested by “ws” packages in the core module.
- Containerization & Deployment: Optionally, add Docker as an infrastructure layer used to containerize and deploy the application.

##### Architectural Patterns and Principles
- Layered Architecture / MVC: Emphasize the separation between presentation (paicoding-ui, paicoding-web), business logic (paicoding-service), and infrastructural support (paicoding-core, paicoding-api).
- Modularity & Separation of Concerns: Each module is purpose-built (e.g., shared API definitions, utility functions, business logic, and UI assets); this modularization should be clear.
- Environment Configuration: Since configuration files are organized with profile-specific folders (dev, test, pre, prod under resources-env), mention that these configurations determine runtime parameters for connecting to external systems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Modules and Client
    Client["Client (Web Browser)"]:::internal
    UI["paicoding-ui"]:::internal
    Web["paicoding-web"]:::internal
    Service["paicoding-service"]:::internal
    Core["paicoding-core"]:::internal
    API["paicoding-api"]:::internal

    %% External Dependencies
    MySQL["MySQL"]:::database
    MongoDB["MongoDB"]:::database
    Redis["Redis"]:::external
    Elastic["ElasticSearch"]:::external
    RabbitMQ["RabbitMQ"]:::external
    OSS["Ali-OSS"]:::external
    WS["WebSocket"]:::external
    Docker["Docker"]:::cloud

    %% Flow: Clients and UI to Web Layer
    Client -->|"HTTP_Request"| Web
    UI -->|"Provides_UI-assets"| Web

    %% Flow: Web Layer to Business Logic and Data Access
    Web -->|"Controller_call"| Service

    %% Flow: Service Layer using Core and API modules
    Service -->|"Utility_calls"| Core
    Service -->|"Data_contracts"| API

    %% External systems connections from Service and Core
    Service -->|"DB_access"| MySQL
    Service -->|"DB_access"| MongoDB
    Core -->|"Caching"| Redis
    Core -->|"Search"| Elastic
    Core -->|"Messaging"| RabbitMQ
    Core -->|"File_Storage"| OSS
    Core -->|"RealTime"| WS
    Core -->|"Deployment"| Docker

    %% Click events for internal modules
    click UI "https://github.com/itwanger/paicoding/tree/main/paicoding-ui/"
    click Web "https://github.com/itwanger/paicoding/tree/main/paicoding-web/"
    click Service "https://github.com/itwanger/paicoding/tree/main/paicoding-service/"
    click Core "https://github.com/itwanger/paicoding/tree/main/paicoding-core/"
    click API "https://github.com/itwanger/paicoding/tree/main/paicoding-api/"

    %% Class styles
    classDef internal fill:#C1FFC1,stroke:#006400,stroke-width:2px;
    classDef external fill:#FFE5E5,stroke:#B22222,stroke-width:2px;
    classDef database fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef cloud fill:#E0FFFF,stroke:#008B8B,stroke-width:2px;
```
