# wnhyang/coolguard architecture

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

- Interactive diagram: https://gitdiagram.com/wnhyang/coolguard
- Repository: https://github.com/wnhyang/coolguard

## Overview

##### Project type and purpose
- This is a modular, multi-module backend platform implementing a rules-based risk-control decision engine.
- Core modules:
- coolguard-system – user/auth management and API endpoints
- coolguard-admin – administrative console service for configuring rules/strategies
- coolguard-decision – the rule-engine microservice handling sync/async decisions
- coolguard-monitor – metrics/log collection service
- coolguard-common – shared library of utilities, contexts, error handling, MyBatis/Redis/Kafka configs
- It uses Spring Boot 3, MyBatis-Plus, Redis, Kafka, Elasticsearch, MySQL, LiteFlow, SaToken, MapStruct.

##### File structure
- Top-level pom.xml orchestrates submodules via Maven.
- “coolguard-dependencies” defines dependency management (BOM).
- Each submodule is a Spring Boot application with its own Dockerfile (admin) or SpringBootApplication entrypoint.
- “shell/docker” and “sql” contain deployment scripts and initial DB schemas.
- Patterns: layered MVC in each service (controller → service → mapper → entity), async tasks (LiteFlow), Kafka consumer/producer, common configs.

##### README for insights
- Describes rule-engine features (metrics, rules, strategies, versioning, event center, exemptions, integrations, monitoring).
- Lists tech stack and middleware: MySQL, Redis, Kafka, Elasticsearch.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        direction TB
        AdminUI["Admin Web UI"]:::client
        ExtAPI["External API Clients"]:::client
    end

    %% Services Layer
    subgraph "Microservices"
        direction TB
        System["System Service\n(coolguard-system)"]:::service
        Admin["Admin Service\n(coolguard-admin)"]:::service
        Decision["Decision Engine\n(coolguard-decision)"]:::service
        Monitor["Monitor Service\n(coolguard-monitor)"]:::service
        Common["Shared Library\n(coolguard-common)"]:::common
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        MySQL["MySQL"]:::db
        Redis["Redis"]:::db
        Kafka["Kafka"]:::mq
        ES["Elasticsearch"]:::db
    end

    %% Artifacts
    subgraph "Deployment & Scripts"
        direction TB
        BOM["coolguard-dependencies\n(pom.xml)"]:::artifact
        Docker["Docker Compose\n(shell/docker)"]:::infra
        SQL1["SQL: coolguard-init.sql"]:::artifact
        SQL2["SQL: coolguard-system.sql"]:::artifact
        SQL3["SQL: coolguard.sql"]:::artifact
    end

    %% Client to Services
    AdminUI -->|"REST"| Admin
    ExtAPI -->|"REST"| System

    %% Services to DB & Messaging
    System -->|"JDBC"| MySQL
    Admin -->|"JDBC"| MySQL
    System -->|"publish configs"| Kafka
    Decision -->|"subscribe"| Kafka
    Decision -->|"JDBC"| MySQL
    Decision -->|"cache"| Redis
    Decision -->|"async results"| Kafka
    Decision -->|"report"| ES

    %% Monitoring flows
    System -->|"metrics/logs"| Monitor
    Admin -->|"metrics/logs"| Monitor
    Decision -->|"metrics/logs"| Monitor
    Monitor -->|"store"| ES
    Monitor -->|"cache"| Redis

    %% Shared library usage
    Common -.-> System
    Common -.-> Admin
    Common -.-> Decision
    Common -.-> Monitor

    %% Artifacts relations
    BOM --> System
    BOM --> Admin
    BOM --> Decision
    BOM --> Monitor
    Docker --> System
    Docker --> Admin
    Docker --> Decision
    Docker --> Monitor
    SQL1 --> MySQL
    SQL2 --> MySQL
    SQL3 --> MySQL

    %% Click Events
    click System "https://github.com/wnhyang/coolguard/tree/main/coolguard-system/src/main/java/cn/wnhyang/coolguard/system"
    click Admin "https://github.com/wnhyang/coolguard/tree/main/coolguard-admin/src/main/java/cn/wnhyang/coolguard"
    click Decision "https://github.com/wnhyang/coolguard/tree/main/coolguard-decision/src/main/java/cn/wnhyang/coolguard/decision"
    click Monitor "https://github.com/wnhyang/coolguard/tree/main/coolguard-monitor/src/main/java/cn/wnhyang/coolguard"
    click Common "https://github.com/wnhyang/coolguard/tree/main/coolguard-common/src/main/java/cn/wnhyang/coolguard/common"
    click BOM "https://github.com/wnhyang/coolguard/blob/main/coolguard-dependencies/pom.xml"
    click Docker "https://github.com/wnhyang/coolguard/blob/main/shell/docker/docker-compose.yml"
    click SQL1 "https://github.com/wnhyang/coolguard/blob/main/sql/coolguard-init.sql"
    click SQL2 "https://github.com/wnhyang/coolguard/blob/main/sql/coolguard-system.sql"
    click SQL3 "https://github.com/wnhyang/coolguard/blob/main/sql/coolguard.sql"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef service fill:#CCE5FF,stroke:#004085,color:#004085;
    classDef db fill:#D4EDDA,stroke:#155724,color:#155724;
    classDef mq fill:#FFF3CD,stroke:#856404,color:#856404;
    classDef common fill:#F8F9FA,stroke:#6C757D,color:#6C757D,stroke-dasharray: 5 5;
    classDef infra fill:#E2E3E5,stroke:#6C757D,color:#6C757D;
    classDef artifact fill:#FFF5BA,stroke:#D39E00,color:#856404;
```
