# spring-cloud-DDD-structure **Repository Path**: Little-Orange-O/spring-cloud-ddd-structure ## Basic Information - **Project Name**: spring-cloud-DDD-structure - **Description**: DDD微服务落地示例项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-03 - **Last Updated**: 2026-04-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DDD设计微服务框架 ## 一、项目背景 本系统采用 **领域驱动设计(DDD)** 的思想进行模块化开发,旨在实现业务逻辑与基础设施解耦、提升可维护性与扩展性。通过清晰的层级划分和组件隔离,支持未来多服务协同、异步消息处理等复杂场景。 ## 二、总体架构图 ``` mermaid flowchart TB %% Common 模块(最左侧) COM["公共组件 Common

• 通用工具类
• 共享常量
• 异常定义
• 公共组件
common
"] %% 启动层 subgraph BL["
启动层

"] BS["启动模块 Bootstrap

• 应用配置加载
• 依赖注入配置
• 服务生命周期
• 启动引导程序
boot-starter
"] end %% 应用层 subgraph AL["
应用层

"] direction LR APP["应用服务 Application

• 业务流程编排
• 事务管理
• 权限控制
• 业务规则协调
application
"] SCH["调度服务 Scheduler

• 定时任务
• 作业调度
• 批处理任务
• 定时数据同步
scheduler
"] INB["入站适配器 Inbound

• 请求处理
• 参数校验
• 协议适配
• 接口实现
infrastructure/inbound
"] EL["事件监听器 Event Listener

• 消息订阅
• 事件处理
• 消息路由
• 异步处理
infrastructure/messaging/event-listener
"] subgraph IC["接口契约"] API["服务API Service API

• 接口定义
• DTO对象
• 接口文档
• 版本控制
service-api
"] ID["接口规范 Interface Definition

• 接口规范
• 参数约束
• 错误码定义
• 接口协议
interface-definition
"] end end %% 领域层 subgraph DL["
领域层

"] DOM["领域模型 Domain Model

• 聚合根定义
• 实体对象
• 值对象
• 领域服务
• 领域事件
domain
"] end %% 基础设施层 subgraph IL["
基础设施层

"] direction LR REPO["数据仓储 Repository

• 数据持久化
• 缓存管理
• 数据查询
• ORM映射
infrastructure/repo
"] EP["事件发布器 Event Publisher

• 事件发布
• 消息分发
• 异步通知
• 消息持久化
infrastructure/messaging/event-publisher
"] OUT["出站适配器 Outbound

• 外部服务调用
• 协议转换
• 熔断降级
• 负载均衡
infrastructure/outbound
"] end %% 模块内部关系 APP --- SCH --- INB --- EL REPO --- EP --- OUT %% 层次依赖关系 BL ===> AL AL ===> DL DL ===> IL %% Common的依赖 AL & DL & IL -.-> COM %% 接口契约依赖 API --> ID INB --> ID %% 样式定义 classDef common fill:#FFFFFF,stroke:#78909C,stroke-width:2px,color:#37474F classDef starter fill:#FFFFFF,stroke:#1E88E5,stroke-width:2px,color:#1565C0 classDef application fill:#FFFFFF,stroke:#3949AB,stroke-width:2px,color:#283593 classDef domain fill:#FFFFFF,stroke:#2E7D32,stroke-width:4px,color:#1B5E20,font-weight:bold classDef infra fill:#FFFFFF,stroke:#757575,stroke-width:2px,color:#424242 classDef contract fill:#FFFFFF,stroke:#7B1FA2,stroke-width:2px,color:#4A148C %% 层容器样式 - 移除背景,调整标题样式 classDef layer fill:none,stroke:#90A4AE,stroke-width:3px,color:#FFFFFF,font-weight:bold %% 应用样式 class COM common class BS starter class APP,SCH,INB,EL application class DOM domain class REPO,EP,OUT infra class API,ID contract class BL,AL,DL,IL layer %% 连接线样式 linkStyle default stroke:#B0BEC5,stroke-width:1px linkStyle 2,3,4,5 stroke:#546E7A,stroke-width:3px linkStyle 6,7 stroke:#90A4AE,stroke-dasharray: 5 5 ``` ## 三、模块划分与职责说明 ### 1. 启动层(Bootstrap Layer) #### 模块名称: boot-starter #### 核心职责 1. 应用初始化配置(如 Spring Boot 配置加载) 2. 依赖注入容器配置 3. 服务生命周期管理(启动/关闭钩子) 4. 由于domain不依赖容器,此处需要配置domain服务bean到容器中 #### 对外暴露 无接口,仅用于启动项目 ### 2. 应用层(Application Layer) #### Application模块 ##### 1. 模块名称 application ##### 2. 核心职责 1. 接收页面请求:接收用户页面请求 2. 编排业务流程:组织协调领域服务和实体操作,完成特定业务场景。 3. 管理事务边界:确保一系列操作要么全部成功,要么全部回滚,维护数据的一致性和完整性。 4. 调用领域模型完成规则协调