# dromara/lamp-cloud architecture

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

- Interactive diagram: https://gitdiagram.com/dromara/lamp-cloud
- Repository: https://github.com/dromara/lamp-cloud

## Overview

##### Project type and purpose
- This is a full‐stack, multi‐module Java17/SpringCloudAlibaba rapid development platform (“lamp-cloud”), organized as a monorepo. It combines microservices (API gateway, OAuth, system, base, generator, support services) with shared libraries (lamp-public, lamp-base, lamp-support) and a separate front-end ecosystem (Vue3).
- Purpose: Provide a SaaS-capable, RBAC-enabled, multi-tenant back-end scaffolding with code generation, file storage, messaging, distributed transactions, resilience, and monitoring built in.

##### Top-level structure and architectural patterns
- Libraries:
- lamp-public: common utilities, annotation/aspect, cache, data-scope SDK, file/message SDK, Sa-token extensions
- lamp-base: core multi-tenant/user/role/file/message services and server application
- lamp-support: supporting services (boot server template, job executor, monitor server)
- Microservices:
- lamp-gateway: API gateway (routing, filters, auth via Sa-token), Dockerized
- lamp-oauth: OAuth2 authorization server
- lamp-system: system management (tenant, dict, parameter, login logs, server info)
- lamp-generator: code generation service (metadata DB, Freemarker templates)
- lamp-base-server: combined “base” back-end application if running monolith
- Patterns:
- Layered MVC (entity → mapper → manager/biz → service → controller)
- Facade modules (lamp-*-facade) for inter-service API with Feign + fallbacks
- Strategy pattern (file storage, message sending)
- Microservices with service registry/discovery (Nacos), config center (Nacos), circuit breaker (Sentinel), distributed transaction (Seata), messaging (RabbitMQ).

##### External systems and middleware
- Service registry & config: Nacos
- Databases: MySQL (multi-tenant isolation), optional Dameng/Oracle/SQLServer
- Cache: Redis
- Message broker: RabbitMQ
- File storage: FastDFS, MinIO, Aliyun, Huawei, Qiniu, or local
- Monitoring/tracing: SkyWalking, Prometheus/Grafana (via lamp-monitor)
- CI/CD: Jenkinsfiles, Dockerfiles, shell scripts

##### Main components and interactions
a. API Gateway (lamp-gateway)
- Exposes single entry point for clients
- Performs authentication/authorization via Sa-token
- Routes requests to microservices over HTTP/REST/Feign
b. OAuth Service (lamp-oauth)
- Manages tokens, user authentication, event listeners for login/logout
c. Core Services
- Base Service (lamp-base-server): user/org/role management, file upload/download, internal messaging
- System Service (lamp-system-server): tenant application management, dict/param, area, client, login log, server info
- Generator Service (lamp-generator-server): persists table metadata, generates code templates via Freemarker
d. Support Services
- Monitor Service (lamp-support/lamp-monitor): dashboards, security config
- Job Executor (lamp-support/lamp-job-executor): runs distributed scheduled tasks via XXL-Job
- Boot Server template (lamp-support/lamp-boot-server): sample monolithic server with pre-wired configs
e. Shared Libraries (lamp-public, lamp-base, lamp-support libs)
- Packaged and published as Maven artifacts or loaded via classpath
f. Infrastructure
- Nacos cluster (service registry + config)
- MySQL cluster (one DB per tenant or shared with tenant_id filter)
- Redis cluster (caching, token store)
- RabbitMQ (event bus for messaging, glue events, notifications)
- File storage backends (via strategy implementations)
- SkyWalking & Prometheus/Grafana for tracing & metrics

##### Architectural patterns & design principles
- High cohesion, low coupling: monorepo of self-contained modules
- Microservices: each server runs independently, registers in Nacos
- Layered design and separation of concerns in each module
- Facade and API modules to decouple business implementations from API contracts
- Strategy pattern for pluggable file storage and messaging
- Spring Cloud features: discovery, config, circuit breaker, load-balancing, distributed transactions

##### Essential elements
- Arrowheads to show request/response or publish/subscribe direction
- Brief callouts for design patterns (‍“Strategy” on file storage, “Facade” on inter-service APIs)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web Clients
    subgraph "Web Clients"
        direction TB
        WebClients["Vue3 / Vben-Admin"]:::client
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Nacos["Nacos (Registry / Config)"]:::infra
        MySQL["MySQL Cluster"]:::infra
        Redis["Redis Cluster"]:::infra
        RabbitMQ["RabbitMQ"]:::infra
        FileStorage["File Storage Backends"]:::infra
        Monitoring["SkyWalking / Prometheus / Grafana"]:::infra
    end

    %% API Gateway
    subgraph "API Gateway"
        direction TB
        Gateway["lamp-gateway-server"]:::gateway
    end

    %% Core Microservices
    subgraph "Core Services"
        direction TB
        OAuth["lamp-oauth-server"]:::core
        BaseService["lamp-base-server"]:::core
        System["lamp-system-server"]:::core
        Generator["lamp-generator-server"]:::core
    end

    %% Support Services
    subgraph "Support Services"
        direction TB
        Monitor["Monitor Service"]:::support
        JobExec["Job Executor"]:::support
        BootServer["Boot Server Template"]:::support
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        direction TB
        LibPublic["lamp-public"]:::lib
        LibBaseBiz["lamp-base-biz"]:::lib
        LibBaseController["lamp-base-controller"]:::lib
        LibBaseEntity["lamp-base-entity"]:::lib
        LibBaseFacade["lamp-base-facade"]:::lib
        LibSupportBoot["lamp-boot-server"]:::lib
        LibSupportJob["lamp-job-executor"]:::lib
        LibSupportMonitor["lamp-monitor"]:::lib
    end

    %% Connections
    WebClients -->|"HTTP/REST"| Gateway
    Gateway -->|"HTTP/Feign"| OAuth
    Gateway -->|"HTTP/Feign"| BaseService
    Gateway -->|"HTTP/Feign"| System
    Gateway -->|"HTTP/Feign"| Generator

    OAuth -->|"JDBC / MyBatis"| MySQL
    BaseService -->|"JDBC / MyBatis"| MySQL
    System -->|"JDBC / MyBatis"| MySQL
    Generator -->|"JDBC / MyBatis"| MySQL

    OAuth -->|"Cache (Spring Cache)"| Redis
    BaseService -->|"Cache (Spring Cache)"| Redis
    System -->|"Cache (Spring Cache)"| Redis
    Generator -->|"Cache (Spring Cache)"| Redis

    OAuth -->|"Publish/Subscribe"| RabbitMQ
    BaseService -->|"Publish/Subscribe"| RabbitMQ
    System -->|"Publish/Subscribe"| RabbitMQ
    Generator -->|"Publish/Subscribe"| RabbitMQ

    BaseService -->|"FileStrategy API"| FileStorage
    System -->|"FileStrategy API"| FileStorage
    Generator -->|"FileStrategy API"| FileStorage

    OAuth -->|"service registration / config fetch"| Nacos
    BaseService -->|"service registration / config fetch"| Nacos
    System -->|"service registration / config fetch"| Nacos
    Generator -->|"service registration / config fetch"| Nacos
    Gateway -->|"service registration / config fetch"| Nacos
    Monitor -->|"service registration / config fetch"| Nacos
    JobExec -->|"service registration / config fetch"| Nacos
    BootServer -->|"service registration / config fetch"| Nacos

    Monitor -->|"JDBC / MyBatis"| MySQL
    JobExec -->|"JDBC / MyBatis"| MySQL
    BootServer -->|"JDBC / MyBatis"| MySQL

    %% Shared libraries usage
    OAuth -->|uses| LibPublic
    BaseService -->|uses| LibPublic
    System -->|uses| LibPublic
    Generator -->|uses| LibPublic

    BaseService -->|uses| LibBaseBiz
    BaseService -->|uses| LibBaseController
    BaseService -->|uses| LibBaseEntity
    BaseService -->|uses| LibBaseFacade

    Monitor -->|uses| LibSupportMonitor
    JobExec -->|uses| LibSupportJob
    BootServer -->|uses| LibSupportBoot

    %% Click Events
    click LibPublic "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-public/"
    click LibBaseBiz "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-base/lamp-base-biz"
    click LibBaseController "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-base/lamp-base-controller"
    click LibBaseEntity "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-base/lamp-base-entity"
    click LibBaseFacade "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-base/lamp-base-facade"
    click LibSupportBoot "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-boot-server"
    click LibSupportJob "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-job-executor"
    click LibSupportMonitor "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-monitor"
    click Gateway "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-gateway/lamp-gateway-server"
    click OAuth "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-oauth/lamp-oauth-server"
    click System "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-system/lamp-system-server"
    click Generator "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-generator/lamp-generator-server"
    click BaseService "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-base/lamp-base-server"
    click JobExec "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-job-executor/src"
    click Monitor "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-monitor/src"
    click BootServer "https://github.com/dromara/lamp-cloud/tree/java17/5.x/lamp-support/lamp-boot-server/src"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#0366d6,color:#0366d6;
    classDef gateway fill:#1E3A8A,stroke:#1E40AF,color:#FFFFFF;
    classDef core fill:#065f46,stroke:#10B981,color:#FFFFFF;
    classDef support fill:#D97706,stroke:#F59E0B,color:#FFFFFF;
    classDef infra fill:#6B7280,stroke:#4B5563,color:#FFFFFF,stroke-dasharray: 3 3;
    classDef lib fill:#F59E0B,stroke:#D97706,color:#000000,stroke-dasharray: 2 2;
```
