Explorar o código

feat(agent-skills): 新增ddd4j-project-builder技能

- 在README.md中更新技能总数从24个增加到25个
- 添加ddd4j-project-builder技能的详细介绍文档
- 实现DDD项目初始化和目录规范检查功能
- 支持单体单模块、单体多模块、单体微服务三种项目类型
- 集成DDD经典分层架构、六边形架构、整洁架构、COLA V5标准
- 提供新项目初始化和旧项目规范检查两种工作模式
- 自动生成符合DDD规范的完整项目结构和目录
- 添加详细的架构文档和使用示例说明
wandl-6A72h hai 8 meses
pai
achega
3281784dcd

+ 64 - 1
README.md

@@ -106,7 +106,7 @@ python convert_all.py ../skills ../adapters-output
 
 ## 可用插件和技能
 
-本仓库的技能按功能分为 7 个插件类别,共包含 24 个技能:
+本仓库的技能按功能分为 7 个插件类别,共包含 25 个技能:
 
 ### 1. teaching-skills(教学技能集合)
 
@@ -304,6 +304,68 @@ Markdown 相关技能集合,包括 Mermaid 图表绘制等。
 - 全生命周期覆盖,从产品调研到项目运维
 - 易于定制,使用占位符便于替换
 
+#### ddd4j-project-builder(DDD 项目构建器)
+
+DDD(领域驱动设计)项目初始化和目录规范检查技能。支持三种项目类型:单体单模块、单体多模块、单体微服务。可以识别项目结构类型并验证目录规范是否符合 DDD、六边形架构、整洁架构和 COLA V5 标准。
+
+**使用示例:**
+- "使用 ddd4j-project-builder 初始化一个单体单模块的 DDD 项目"
+- "创建一个单体多模块项目,包含 api、order、payment 三个业务模块"
+- "初始化一个微服务架构项目,包含 user-service、order-service、product-service"
+- "检查现有项目的 DDD 结构是否符合规范"
+- "验证这个项目的目录结构是否符合 COLA V5 架构"
+- "识别这个项目是单体单模块还是单体多模块结构"
+
+**支持的项目类型:**
+
+1. **单体单模块(Single-Module Monolith)**
+   - 适用场景:中小型应用,单个业务领域,团队规模 5-15 人
+   - 特点:单一 Maven 模块,所有层在同一模块内
+   - 示例:`"初始化一个单体单模块项目,groupId=io.ddd4j.base, artifactId=ddd4j-order"`
+
+2. **单体多模块(Multi-Module Monolith)**
+   - 适用场景:中大型应用,多个业务域,团队规模 15-50 人
+   - 特点:多个 Maven 模块,按业务域划分,共享 common 模块
+   - 示例:`"创建一个单体多模块项目,包含 api、order、payment 模块"`
+
+3. **单体微服务(Microservices)**
+   - 适用场景:大型电商平台,多个业务域,团队规模 50+ 人
+   - 特点:每个服务独立部署,服务间通过 RPC 和消息队列通信
+   - 示例:`"初始化微服务项目,包含 user-service、order-service、product-service"`
+
+**支持的架构模式:**
+
+1. **DDD 经典分层架构** - interfaces → application → domain ← infrastructure
+2. **六边形架构(Hexagonal)** - 端口和适配器模式
+3. **整洁架构(Clean Architecture)** - 实体、用例、接口适配器
+4. **COLA V5** - Adapter → App → Domain ← Infrastructure
+
+**功能特性:**
+
+- **新项目初始化**:
+  - 自动生成完整的 Maven 项目结构
+  - 创建所有必需的目录和文件(pom.xml、package-info.java、.gitignore、LICENSE 等)
+  - 支持自定义 groupId、artifactId、version、packageBase
+  - 自动生成符合 DDD 规范的包结构
+
+- **旧项目规范检查**:
+  - 自动识别项目类型(单体单模块/单体多模块/微服务)
+  - 识别架构模式(DDD Classic/Hexagonal/Clean/COLA V5)
+  - 验证目录结构合规性
+  - 检查包命名规范
+  - 验证层依赖关系
+  - 生成详细的验证报告
+
+**输出位置:**
+- 所有生成的项目文件保存在 `./ddd4j-project/` 目录下
+
+**参考文档:**
+- 技能内置了完整的架构文档(docs/ 目录):
+  - DDD 经典分层架构目录结构
+  - 六边形架构详细目录结构参考
+  - 整洁架构详细目录结构参考
+  - COLA V5 架构详细目录结构参考
+
 #### mcp-builder(MCP 构建器)
 
 帮助创建和配置 Model Context Protocol (MCP) 服务器。
@@ -439,6 +501,7 @@ Markdown 相关技能集合,包括 Mermaid 图表绘制等。
 │   │   ├── test-writer/
 │   │   ├── documentation-builder/
 │   │   ├── zh-product-doc-generator/
+│   │   ├── ddd4j-project-builder/
 │   │   ├── mcp-builder/
 │   │   ├── webapp-testing/
 │   │   ├── frontend-design/

BIN=BIN
media/rm_marketplace.png


+ 21 - 0
skills/ddd4j-project-builder/LICENSE.txt

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 226 - 0
skills/ddd4j-project-builder/SKILL.md

@@ -0,0 +1,226 @@
+---
+name: ddd4j-project-builder
+description: A comprehensive skill for initializing new DDD (Domain-Driven Design) projects and checking existing project structure compliance. Supports three project types: single-module monolith, multi-module monolith, and microservices. Can identify project structure type and validate directory conventions against DDD, Hexagonal Architecture, Clean Architecture, and COLA V5 standards. Use this skill when creating new DDD projects, checking project structure compliance, or migrating existing projects to DDD architecture.
+license: Complete terms in LICENSE.txt
+---
+
+# DDD Project Initialization and Structure Validation
+
+## When to use this skill
+
+Use this skill whenever you need to:
+
+- **Initialize a new DDD project** with proper directory structure
+- **Check existing project structure** compliance with DDD standards
+- **Identify project architecture type** (single-module, multi-module, microservices)
+- **Validate directory conventions** against DDD patterns
+- **Migrate existing projects** to DDD architecture
+- **Generate project scaffolding** based on DDD principles
+
+## Project Types Supported
+
+### 1. Single-Module Monolith (单体单模块)
+**适用场景**: 中小型应用,单个业务领域,团队规模 5-15 人
+
+**特点**:
+- 单一 Maven 模块
+- 所有层(interfaces, application, domain, infrastructure)在同一模块内
+- 适合快速开发和部署
+
+### 2. Multi-Module Monolith (单体多模块)
+**适用场景**: 中大型应用,多个业务域,团队规模 15-50 人
+
+**特点**:
+- 多个 Maven 模块,按业务域划分
+- 每个业务域包含完整的 DDD 四层架构
+- 共享 common 模块
+- 统一 BOM 和依赖管理
+
+### 3. Microservices (单体微服务)
+**适用场景**: 大型电商平台,多个业务域,团队规模 50+ 人
+
+**特点**:
+- 每个服务独立部署
+- 服务间通过 RPC 和消息队列通信
+- 每个服务内部按 DDD 四层架构组织
+- 独立的数据库和配置
+
+## How to use this skill
+
+### For New Project Initialization
+
+1. **Identify the project type** from user requirements:
+   - Single-module monolith → `single-module`
+   - Multi-module monolith → `multi-module`
+   - Microservices → `microservices`
+
+2. **Load the appropriate example** from the `examples/` directory:
+   - `examples/single-module.md` - Single-module monolith structure
+   - `examples/multi-module.md` - Multi-module monolith structure
+   - `examples/microservices.md` - Microservices structure
+   - `examples/architecture-patterns.md` - DDD, Hexagonal, Clean, COLA V5 patterns
+
+3. **Collect project information**:
+   - `groupId`: Maven group ID (e.g., `io.ddd4j.base`)
+   - `artifactId`: Maven artifact ID (e.g., `ddd4j-douyin`)
+   - `version`: Project version (e.g., `1.0.0-SNAPSHOT`)
+   - `parentVersion`: Parent POM version (e.g., `2023.0.x.20251205-SNAPSHOT`)
+   - `packageBase`: Base package name (e.g., `io.ddd4j.douyin`)
+   - `modules`: List of business modules (for multi-module/microservices)
+   - `architecture`: Architecture pattern (DDD Classic, Hexagonal, Clean, COLA V5)
+
+4. **Generate project structure**:
+   - Create directory structure based on selected type
+   - Generate `pom.xml` files (parent and modules)
+   - Create `package-info.java` files for each module
+   - Generate `.gitignore`, `LICENSE`, `mvnw`, `mvnw.cmd`
+   - Create basic directory structure with `src/main/java` and `src/test/java`
+
+5. **Save to project directory**:
+   - **Default location**: Save to `./ddd4j-project/` directory in the command execution directory
+   - **Directory creation**: Automatically create the directory if it doesn't exist
+   - **File naming**: Use descriptive names based on project type and module names
+
+### For Existing Project Validation
+
+1. **Analyze project structure**:
+   - Scan project directory for Maven modules
+   - Identify layer structure (interfaces, application, domain, infrastructure)
+   - Check package naming conventions
+   - Verify directory organization
+
+2. **Identify project type**:
+   - **Single-module**: Single `pom.xml` at root, all layers in one module
+   - **Multi-module**: Parent `pom.xml` with multiple modules, each module has complete layers
+   - **Microservices**: Multiple services, each with independent structure
+
+3. **Validate against standards**:
+   - Check DDD layer compliance
+   - Verify dependency direction (interfaces → application → domain ← infrastructure)
+   - Validate package naming (`{basePackage}.{module}.{layer}`)
+   - Check for required directories (`src/main/java`, `src/test/java`)
+   - Verify `package-info.java` files exist
+
+4. **Generate validation report**:
+   - List identified issues
+   - Provide recommendations
+   - Suggest fixes for non-compliant structures
+
+## Output Format and File Saving
+
+When generating a project structure, follow this response structure:
+
+1. **Save the files first**: Create the project structure in `./ddd4j-project/` directory
+   - Create the `./ddd4j-project/` directory if it doesn't exist
+   - Generate all required files and directories
+
+2. **Inform the user**: Tell them where the files were saved
+
+3. **Display the structure**: Show the generated directory structure in a code block
+
+**Example Response Structure**:
+- First line: "I've created the DDD project structure and saved it to `./ddd4j-project/{project-name}/`."
+- Then show the structure wrapped in a code block:
+  - Start with: three backticks + `text` + newline
+  - Then the directory structure
+  - End with: three backticks + newline
+
+**Critical Requirements**:
+- Always save project files to `./ddd4j-project/` directory in the command execution directory
+- Create the directory automatically if it doesn't exist
+- Generate complete project structure with all required files
+- Follow Maven and DDD conventions strictly
+
+## Project Structure Standards
+
+### Package Naming Convention
+
+For multi-module projects:
+```
+{basePackage}.{moduleName}.{layerName}
+```
+
+Examples:
+- `io.ddd4j.douyin.api.domain` - API module, domain layer
+- `io.ddd4j.douyin.api.application` - API module, application layer
+- `io.ddd4j.douyin.api.interfaces` - API module, interfaces layer
+- `io.ddd4j.douyin.api.infrastructure` - API module, infrastructure layer
+
+### Required Files
+
+Every module must have:
+- `pom.xml` - Maven configuration
+- `src/main/java/{package}/package-info.java` - Package documentation
+- `src/test/java/` - Test directory structure
+- `.gitignore` - Git ignore rules (at root)
+- `LICENSE` - License file (at root)
+- `mvnw`, `mvnw.cmd` - Maven wrapper (at root)
+
+### Layer Dependencies
+
+**Correct dependency direction**:
+```
+interfaces → application → domain ← infrastructure
+```
+
+**Rules**:
+- Domain layer must not depend on any other layer
+- Infrastructure layer implements domain layer interfaces
+- Application layer depends on domain layer
+- Interfaces layer depends on application layer
+
+## Architecture Patterns
+
+The skill supports four architecture patterns:
+
+1. **DDD Classic Layered Architecture** (DDD 经典分层架构)
+   - Layers: interfaces, application, domain, infrastructure
+   - Reference: `docs/1、DDD 经典分层架构目录结构.md` and `examples/architecture-patterns.md#ddd-classic`
+
+2. **Hexagonal Architecture** (六边形架构)
+   - Ports and Adapters pattern
+   - Reference: `docs/2、六边形架构详细目录结构参考.md` and `examples/architecture-patterns.md#hexagonal`
+
+3. **Clean Architecture** (整洁架构)
+   - Entities, Use Cases, Interface Adapters
+   - Reference: `docs/3、整洁架构详细目录结构参考.md` and `examples/architecture-patterns.md#clean`
+
+4. **COLA V5** (菱形架构)
+   - Adapter → App → Domain ← Infrastructure
+   - Reference: `docs/4、COLA V5 架构详细目录结构参考.md` and `examples/architecture-patterns.md#cola-v5`
+
+## Validation Rules
+
+When checking existing projects, validate:
+
+1. **Structure Compliance**:
+   - ✓ Correct layer organization
+   - ✓ Proper module separation
+   - ✓ Package naming conventions
+
+2. **Dependency Rules**:
+   - ✓ Domain layer has no external dependencies
+   - ✓ Infrastructure implements domain interfaces
+   - ✓ Correct dependency direction
+
+3. **File Organization**:
+   - ✓ Required directories exist
+   - ✓ `package-info.java` files present
+   - ✓ Maven configuration correct
+
+4. **Naming Conventions**:
+   - ✓ Package names follow convention
+   - ✓ Module names are descriptive
+   - ✓ Layer names are standard
+
+## Examples
+
+See the `examples/` directory for:
+- `single-module.md` - Complete single-module monolith example
+- `multi-module.md` - Complete multi-module monolith example (based on ddd4j-douyin structure)
+- `microservices.md` - Complete microservices example
+- `architecture-patterns.md` - All four architecture patterns with detailed structures
+
+## Keywords
+
+ddd, domain-driven design, ddd project, project initialization, project structure, architecture validation, single-module, multi-module, microservices, hexagonal architecture, clean architecture, cola v5, maven project, java project, 领域驱动设计, DDD项目, 项目初始化, 项目结构, 架构验证, 单体单模块, 单体多模块, 微服务, 六边形架构, 整洁架构, COLA架构

+ 1391 - 0
skills/ddd4j-project-builder/docs/1、DDD 经典分层架构目录结构.md

@@ -0,0 +1,1391 @@
+# DDD 经典分层架构目录结构参考
+
+## 目录
+
+- [1. 单体工程目录结构](#1-单体工程目录结构)
+- [2. 大型微服务工程目录结构](#2-大型微服务工程目录结构)
+- [3. DDD 经典分层架构原则与依赖关系](#3-ddd-经典分层架构原则与依赖关系)
+- [4. DDD 核心概念](#4-ddd-核心概念)
+
+---
+
+## 1. 单体工程目录结构
+
+**适用场景**:中小型应用,单个业务领域,团队规模 5-15 人
+
+以一个订单管理系统为例:
+
+```
+order-management-system/
+├── pom.xml
+├── README.md
+│
+├── src/main/java/
+│   └── com/example/order/
+│       │
+│       ├── OrderApplication.java             # 应用启动类
+│       │
+│       ├── interfaces/                       # 接口层(用户界面层)
+│       │   ├── web/                          # Web接口
+│       │   │   ├── controller/
+│       │   │   │   ├── OrderController.java
+│       │   │   │   │   ├── @RestController
+│       │   │   │   │   ├── @RequestMapping("/api/orders")
+│       │   │   │   │   ├── placeOrder(@RequestBody)
+│       │   │   │   │   ├── getOrder(@PathVariable)
+│       │   │   │   │   └── cancelOrder(@PathVariable)
+│       │   │   │   │
+│       │   │   │   ├── CustomerController.java
+│       │   │   │   └── ProductController.java
+│       │   │   │
+│       │   │   ├── dto/
+│       │   │   │   ├── request/
+│       │   │   │   │   ├── PlaceOrderRequest.java
+│       │   │   │   │   ├── PayOrderRequest.java
+│       │   │   │   │   └── RegisterCustomerRequest.java
+│       │   │   │   │
+│       │   │   │   ├── response/
+│       │   │   │   │   ├── OrderResponse.java
+│       │   │   │   │   ├── CustomerResponse.java
+│       │   │   │   │   └── ApiResponse.java
+│       │   │   │   │
+│       │   │   │   └── assembler/
+│       │   │   │       ├── OrderAssembler.java
+│       │   │   │       └── CustomerAssembler.java
+│       │   │   │
+│       │   │   ├── filter/
+│       │   │   │   ├── AuthenticationFilter.java
+│       │   │   │   └── LoggingFilter.java
+│       │   │   │
+│       │   │   └── advice/
+│       │   │       └── GlobalExceptionHandler.java
+│       │   │
+│       │   └── rpc/                          # RPC接口(可选)
+│       │       ├── OrderRpcProvider.java
+│       │       └── PaymentRpcConsumer.java
+│       │
+│       ├── application/                      # 应用层(用例编排)
+│       │   ├── service/
+│       │   │   ├── OrderApplicationService.java
+│       │   │   │   ├── placeOrder(PlaceOrderCommand): OrderId
+│       │   │   │   ├── payOrder(PayOrderCommand): void
+│       │   │   │   └── cancelOrder(CancelOrderCommand): void
+│       │   │   │
+│       │   │   ├── CustomerApplicationService.java
+│       │   │   └── ProductApplicationService.java
+│       │   │
+│       │   ├── command/                      # 命令对象(CQRS)
+│       │   │   ├── PlaceOrderCommand.java
+│       │   │   ├── PayOrderCommand.java
+│       │   │   └── CancelOrderCommand.java
+│       │   │
+│       │   ├── query/                        # 查询对象(CQRS)
+│       │   │   ├── GetOrderQuery.java
+│       │   │   ├── OrderListQuery.java
+│       │   │   └── CustomerQuery.java
+│       │   │
+│       │   ├── handler/                      # 命令/查询处理器
+│       │   │   ├── commandhandler/
+│       │   │   │   ├── PlaceOrderCommandHandler.java
+│       │   │   │   ├── PayOrderCommandHandler.java
+│       │   │   │   └── CancelOrderCommandHandler.java
+│       │   │   │
+│       │   │   └── queryhandler/
+│       │   │       ├── GetOrderQueryHandler.java
+│       │   │       └── OrderListQueryHandler.java
+│       │   │
+│       │   ├── dto/                          # 应用层DTO
+│       │   │   ├── OrderDTO.java
+│       │   │   ├── CustomerDTO.java
+│       │   │   └── ProductDTO.java
+│       │   │
+│       │   └── eventhandler/                 # 应用事件处理器
+│       │       ├── OrderPlacedEventHandler.java
+│       │       ├── OrderPaidEventHandler.java
+│       │       └── CustomerRegisteredEventHandler.java
+│       │
+│       ├── domain/                           # 领域层(核心业务逻辑)
+│       │   ├── model/                        # 领域模型
+│       │   │   ├── aggregate/                # 聚合
+│       │   │   │   ├── order/
+│       │   │   │   │   ├── Order.java        # 聚合根
+│       │   │   │   │   │   ├── OrderId
+│       │   │   │   │   │   ├── CustomerId
+│       │   │   │   │   │   ├── OrderItems
+│       │   │   │   │   │   ├── OrderStatus
+│       │   │   │   │   │   ├── place()
+│       │   │   │   │   │   ├── pay()
+│       │   │   │   │   │   ├── cancel()
+│       │   │   │   │   │   └── calculateTotal()
+│       │   │   │   │   │
+│       │   │   │   │   └── OrderItem.java    # 实体
+│       │   │   │   │
+│       │   │   │   ├── customer/
+│       │   │   │   │   ├── Customer.java    # 聚合根
+│       │   │   │   │   └── CustomerId.java
+│       │   │   │   │
+│       │   │   │   └── product/
+│       │   │   │       └── Product.java     # 聚合根
+│       │   │   │
+│       │   │   ├── valueobject/              # 值对象
+│       │   │   │   ├── Money.java
+│       │   │   │   ├── Email.java
+│       │   │   │   ├── Address.java
+│       │   │   │   ├── PhoneNumber.java
+│       │   │   │   └── Quantity.java
+│       │   │   │
+│       │   │   └── event/                    # 领域事件
+│       │   │       ├── DomainEvent.java
+│       │   │       ├── OrderPlacedEvent.java
+│       │   │       ├── OrderPaidEvent.java
+│       │   │       └── CustomerRegisteredEvent.java
+│       │   │
+│       │   ├── service/                      # 领域服务
+│       │   │   ├── OrderDomainService.java
+│       │   │   ├── PricingDomainService.java
+│       │   │   └── InventoryDomainService.java
+│       │   │
+│       │   ├── repository/                   # 仓储接口
+│       │   │   ├── OrderRepository.java
+│       │   │   ├── CustomerRepository.java
+│       │   │   └── ProductRepository.java
+│       │   │
+│       │   ├── specification/                # 规约模式
+│       │   │   ├── Specification.java
+│       │   │   ├── CustomerSpecification.java
+│       │   │   └── OrderSpecification.java
+│       │   │
+│       │   └── factory/                      # 工厂模式
+│       │       ├── OrderFactory.java
+│       │       └── CustomerFactory.java
+│       │
+│       ├── infrastructure/                   # 基础设施层(技术实现)
+│       │   ├── persistence/                  # 持久化
+│       │   │   ├── repository/
+│       │   │   │   ├── JpaOrderRepository.java
+│       │   │   │   ├── JpaCustomerRepository.java
+│       │   │   │   └── MyBatisProductRepository.java
+│       │   │   │
+│       │   │   ├── entity/                   # 持久化实体
+│       │   │   │   ├── OrderEntity.java
+│       │   │   │   ├── CustomerEntity.java
+│       │   │   │   └── ProductEntity.java
+│       │   │   │
+│       │   │   ├── mapper/
+│       │   │   │   ├── OrderMapper.java
+│       │   │   │   └── CustomerMapper.java
+│       │   │   │
+│       │   │   └── dao/
+│       │   │       ├── OrderDao.java
+│       │   │       └── CustomerDao.java
+│       │   │
+│       │   ├── messaging/                    # 消息传递
+│       │   │   ├── eventpublisher/
+│       │   │   │   ├── KafkaEventPublisher.java
+│       │   │   │   └── DomainEventPublisherImpl.java
+│       │   │   │
+│       │   │   └── eventconsumer/
+│       │   │       └── OrderEventConsumer.java
+│       │   │
+│       │   ├── external/                     # 外部服务集成
+│       │   │   ├── payment/
+│       │   │   │   ├── PaymentService.java
+│       │   │   │   ├── AlipayPaymentService.java
+│       │   │   │   └── WechatPaymentService.java
+│       │   │   │
+│       │   │   └── notification/
+│       │   │       ├── EmailService.java
+│       │   │       └── SMSService.java
+│       │   │
+│       │   ├── cache/                        # 缓存
+│       │   │   ├── RedisCache.java
+│       │   │   └── CacheProvider.java
+│       │   │
+│       │   ├── config/
+│       │   │   ├── PersistenceConfig.java
+│       │   │   ├── MessagingConfig.java
+│       │   │   └── CacheConfig.java
+│       │   │
+│       │   └── security/
+│       │       ├── JwtTokenProvider.java
+│       │       └── PasswordEncoder.java
+│       │
+│       └── shared/                           # 共享组件
+│           ├── kernel/
+│           │   ├── AggregateRoot.java
+│           │   ├── ValueObject.java
+│           │   └── Entity.java
+│           │
+│           ├── util/
+│           │   ├── Assert.java
+│           │   └── ValidationUtils.java
+│           │
+│           └── constant/
+│               └── AppConstants.java
+│
+├── src/test/java/
+│   ├── unit/
+│   │   ├── domain/
+│   │   │   ├── OrderTest.java
+│   │   │   └── CustomerTest.java
+│   │   ├── application/
+│   │   │   └── OrderApplicationServiceTest.java
+│   │   └── interfaces/
+│   │       └── OrderControllerTest.java
+│   │
+│   └── integration/
+│       ├── OrderIntegrationTest.java
+│       └── PaymentIntegrationTest.java
+│
+├── src/main/resources/
+│   ├── application.yml
+│   ├── application-dev.yml
+│   ├── application-prod.yml
+│   ├── db/migration/
+│   │   ├── V1__init_schema.sql
+│   │   └── V2__create_tables.sql
+│   └── mapper/
+│       ├── OrderMapper.xml
+│       └── CustomerMapper.xml
+│
+├── docker/
+│   ├── Dockerfile
+│   └── docker-compose.yml
+│
+├── docs/
+│   ├── architecture/
+│   │   └── ddd-architecture.md
+│   └── api/
+│       └── openapi.yaml
+│
+└── .gitignore
+```
+
+**单体工程 Maven 模块依赖关系**:
+
+```
+src/main/java/
+    └── com/example/order/
+        interfaces(接口层)
+            ↓ 依赖
+        application(应用层)
+            ↓ 依赖
+        domain(领域层)
+            ↑ 依赖(通过接口)
+        infrastructure(基础设施层)
+            ↓ 依赖
+        shared(共享组件)
+```
+
+---
+
+## 2. 大型微服务工程目录结构
+
+**适用场景**:大型电商平台,多个业务域,团队规模 50+ 人
+
+```
+ecommerce-platform/                      # 电商平台根目录
+├── pom.xml                              # 父 POM
+├── README.md
+├── .gitignore
+├── docker-compose.yml
+│
+├── platform-common/                     # 平台通用模块
+│   ├── pom.xml
+│   └── src/main/java/com/ecommerce/common/
+│       ├── kernel/
+│       │   ├── AggregateRoot.java
+│       │   ├── ValueObject.java
+│       │   └── Entity.java
+│       ├── util/
+│       │   ├── Assert.java
+│       │   └── ValidationUtils.java
+│       ├── constant/
+│       │   └── AppConstants.java
+│       └── exception/
+│           └── SystemException.java
+│
+├── services/                            # 微服务目录
+│   │
+│   ├── user-service/                    # 用户服务
+│   │   ├── user-service-api/            # 服务 API 模块
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/api/
+│   │   │           ├── UserService.java
+│   │   │           ├── dto/
+│   │   │           │   ├── UserDTO.java
+│   │   │           │   └── RegisterUserRequest.java
+│   │   │           └── facade/
+│   │   │               └── UserFacade.java
+│   │   │
+│   │   ├── user-service-domain/         # 领域模块
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   └── User.java
+│   │   │           │   ├── valueobject/
+│   │   │           │   │   ├── UserId.java
+│   │   │           │   │   ├── Email.java
+│   │   │           │   │   └── PhoneNumber.java
+│   │   │           │   └── event/
+│   │   │           │       └── UserRegisteredEvent.java
+│   │   │           │
+│   │   │           ├── service/
+│   │   │           │   ├── UserDomainService.java
+│   │   │           │   └── AuthenticationDomainService.java
+│   │   │           │
+│   │   │           ├── repository/
+│   │   │           │   └── UserRepository.java
+│   │   │           │
+│   │   │           └── specification/
+│   │   │               └── UserSpecification.java
+│   │   │
+│   │   ├── user-service-application/    # 应用模块
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/application/
+│   │   │           ├── service/
+│   │   │           │   └── UserApplicationService.java
+│   │   │           │
+│   │   │           ├── command/
+│   │   │           │   ├── RegisterUserCommand.java
+│   │   │           │   └── LoginCommand.java
+│   │   │           │
+│   │   │           ├── query/
+│   │   │           │   └── GetUserQuery.java
+│   │   │           │
+│   │   │           ├── handler/
+│   │   │           │   ├── commandhandler/
+│   │   │           │   │   ├── RegisterUserCommandHandler.java
+│   │   │           │   │   └── LoginCommandHandler.java
+│   │   │           │   │
+│   │   │           │   └── queryhandler/
+│   │   │           │       └── GetUserQueryHandler.java
+│   │   │           │
+│   │   │           └── eventhandler/
+│   │   │               └── UserRegisteredEventHandler.java
+│   │   │
+│   │   ├── user-service-infrastructure/ # 基础设施模块
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/infrastructure/
+│   │   │           ├── persistence/
+│   │   │           │   ├── repository/
+│   │   │           │   │   └── JpaUserRepository.java
+│   │   │           │   ├── entity/
+│   │   │           │   │   └── UserEntity.java
+│   │   │           │   └── mapper/
+│   │   │           │       └── UserMapper.java
+│   │   │           │
+│   │   │           ├── messaging/
+│   │   │           │   ├── eventpublisher/
+│   │   │           │   │   └── KafkaUserEventPublisher.java
+│   │   │           │   │
+│   │   │           │   └── eventconsumer/
+│   │   │           │       └── UserEventConsumer.java
+│   │   │           │
+│   │   │           ├── external/
+│   │   │           │   ├── notification/
+│   │   │           │   │   ├── EmailService.java
+│   │   │           │   │   └── SMSService.java
+│   │   │           │   │
+│   │   │           │   └── verification/
+│   │   │           │       └── SmsVerificationService.java
+│   │   │           │
+│   │   │           ├── cache/
+│   │   │           │   └── RedisUserCache.java
+│   │   │           │
+│   │   │           └── config/
+│   │   │               ├── PersistenceConfig.java
+│   │   │               └── MessagingConfig.java
+│   │   │
+│   │   ├── user-service-interfaces/     # 接口模块
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/interfaces/
+│   │   │           ├── web/
+│   │   │           │   ├── controller/
+│   │   │           │   │   ├── UserController.java
+│   │   │           │   │   └── AuthController.java
+│   │   │           │   │
+│   │   │           │   ├── dto/
+│   │   │           │   │   ├── request/
+│   │   │           │   │   │   ├── RegisterUserRequest.java
+│   │   │           │   │   │   └── LoginRequest.java
+│   │   │           │   │   │
+│   │   │           │   │   └── response/
+│   │   │           │   │       ├── UserResponse.java
+│   │   │           │   │       └── TokenResponse.java
+│   │   │           │   │
+│   │   │           │   └── assembler/
+│   │   │           │       └── UserAssembler.java
+│   │   │           │
+│   │   │           └── rpc/
+│   │   │               ├── UserRpcProvider.java
+│   │   │               └── OrderRpcConsumer.java
+│   │   │
+│   │   └── user-service-start/           # 启动模块
+│   │       └── src/main/java/
+│   │           └── com/ecommerce/user/
+│   │               └── UserApplication.java
+│   │
+│   │   └── pom.xml
+│   │
+│   ├── order-service/                   # 订单服务
+│   │   ├── order-service-api/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/api/
+│   │   │           ├── OrderService.java
+│   │   │           └── dto/
+│   │   │               ├── OrderDTO.java
+│   │   │               └── PlaceOrderRequest.java
+│   │   │
+│   │   ├── order-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   ├── Order.java       # 聚合根
+│   │   │           │   │   ├── OrderItem.java   # 实体
+│   │   │           │   │   └── Cart.java        # 聚合根
+│   │   │           │   │
+│   │   │           │   ├── valueobject/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   ├── Address.java
+│   │   │           │   │   └── OrderStatus.java
+│   │   │           │   │
+│   │   │           │   └── event/
+│   │   │           │       ├── OrderPlacedEvent.java
+│   │   │           │       ├── OrderPaidEvent.java
+│   │   │           │       └── OrderCancelledEvent.java
+│   │   │           │
+│   │   │           ├── service/
+│   │   │           │   ├── OrderDomainService.java
+│   │   │           │   ├── PricingDomainService.java
+│   │   │           │   └── PaymentDomainService.java
+│   │   │           │
+│   │   │           ├── repository/
+│   │   │           │   ├── OrderRepository.java
+│   │   │           │   └── CartRepository.java
+│   │   │           │
+│   │   │           └── specification/
+│   │   │               └── OrderSpecification.java
+│   │   │
+│   │   ├── order-service-application/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/application/
+│   │   │           ├── service/
+│   │   │           │   ├── OrderApplicationService.java
+│   │   │           │   └── CartApplicationService.java
+│   │   │           │
+│   │   │           ├── command/
+│   │   │           │   ├── PlaceOrderCommand.java
+│   │   │           │   ├── PayOrderCommand.java
+│   │   │           │   └── CancelOrderCommand.java
+│   │   │           │
+│   │   │           ├── query/
+│   │   │           │   ├── GetOrderQuery.java
+│   │   │           │   └── OrderListQuery.java
+│   │   │           │
+│   │   │           ├── handler/
+│   │   │           │   ├── commandhandler/
+│   │   │           │   │   ├── PlaceOrderCommandHandler.java
+│   │   │           │   │   ├── PayOrderCommandHandler.java
+│   │   │           │   │   └── CancelOrderCommandHandler.java
+│   │   │           │   │
+│   │   │           │   └── queryhandler/
+│   │   │           │       ├── GetOrderQueryHandler.java
+│   │   │           │       └── OrderListQueryHandler.java
+│   │   │           │
+│   │   │           ├── coordinator/
+│   │   │           │   └── OrderProcessingCoordinator.java
+│   │   │           │
+│   │   │           └── eventhandler/
+│   │   │               ├── OrderPlacedEventHandler.java
+│   │   │               └── OrderPaidEventHandler.java
+│   │   │
+│   │   ├── order-service-infrastructure/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/infrastructure/
+│   │   │           ├── persistence/
+│   │   │           │   ├── repository/
+│   │   │           │   │   ├── JpaOrderRepository.java
+│   │   │           │   │   └── JpaCartRepository.java
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── OrderEntity.java
+│   │   │           │   │   └── CartEntity.java
+│   │   │           │   └── mapper/
+│   │   │           │       ├── OrderMapper.java
+│   │   │           │       └── CartMapper.java
+│   │   │           │
+│   │   │           ├── messaging/
+│   │   │           │   ├── eventpublisher/
+│   │   │           │   │   └── KafkaOrderEventPublisher.java
+│   │   │           │   │
+│   │   │           │   └── eventconsumer/
+│   │   │           │       ├── PaymentEventConsumer.java
+│   │   │           │       └── UserEventConsumer.java
+│   │   │           │
+│   │   │           ├── external/
+│   │   │           │   ├── payment/
+│   │   │           │   │   ├── PaymentGatewayClient.java
+│   │   │           │   │   └── AlipayClient.java
+│   │   │           │   │
+│   │   │           │   ├── inventory/
+│   │   │           │   │   └── InventoryServiceClient.java
+│   │   │           │   │
+│   │   │           │   └── notification/
+│   │   │           │       └── NotificationServiceClient.java
+│   │   │           │
+│   │   │           ├── cache/
+│   │   │           │   └── RedisOrderCache.java
+│   │   │           │
+│   │   │           └── config/
+│   │   │               ├── PersistenceConfig.java
+│   │   │               ├── MessagingConfig.java
+│   │   │               └── ExternalServiceConfig.java
+│   │   │
+│   │   ├── order-service-interfaces/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/interfaces/
+│   │   │           ├── web/
+│   │   │           │   ├── controller/
+│   │   │           │   │   ├── OrderController.java
+│   │   │           │   │   └── CartController.java
+│   │   │           │   │
+│   │   │           │   ├── dto/
+│   │   │           │   │   ├── request/
+│   │   │           │   │   │   ├── PlaceOrderRequest.java
+│   │   │           │   │   │   └── PayOrderRequest.java
+│   │   │           │   │   │
+│   │   │           │   │   ├── response/
+│   │   │           │   │   │   ├── OrderResponse.java
+│   │   │           │   │   │   └── CartResponse.java
+│   │   │           │   │   │
+│   │   │           │   │   └── assembler/
+│   │   │           │   │       └── OrderAssembler.java
+│   │   │           │   │
+│   │   │           │   └── advice/
+│   │   │           │       └── GlobalExceptionHandler.java
+│   │   │           │
+│   │   │           └── rpc/
+│   │   │               ├── OrderRpcProvider.java
+│   │   │               └── ProductRpcConsumer.java
+│   │   │
+│   │   └── order-service-start/
+│   │       └── src/main/java/
+│   │           └── com/ecommerce/order/
+│   │               └── OrderApplication.java
+│   │
+│   │   └── pom.xml
+│   │
+│   ├── product-service/                 # 商品服务
+│   │   ├── product-service-api/
+│   │   ├── product-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/product/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   ├── Product.java
+│   │   │           │   │   └── Category.java
+│   │   │           │   │
+│   │   │           │   ├── valueobject/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   └── Quantity.java
+│   │   │           │   │
+│   │   │           │   └── event/
+│   │   │           │       └── ProductCreatedEvent.java
+│   │   │           │
+│   │   │           ├── service/
+│   │   │           │   ├── ProductDomainService.java
+│   │   │           │   └── InventoryDomainService.java
+│   │   │           │
+│   │   │           └── repository/
+│   │   │               └── ProductRepository.java
+│   │   │
+│   │   ├── product-service-application/
+│   │   ├── product-service-infrastructure/
+│   │   ├── product-service-interfaces/
+│   │   └── product-service-start/
+│   │
+│   ├── payment-service/                 # 支付服务
+│   │   ├── payment-service-api/
+│   │   ├── payment-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/payment/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   └── Payment.java
+│   │   │           │   │
+│   │   │           │   ├── valueobject/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   └── PaymentStatus.java
+│   │   │           │   │
+│   │   │           │   └── event/
+│   │   │           │       └── PaymentCompletedEvent.java
+│   │   │           │
+│   │   │           ├── service/
+│   │   │           │   └── PaymentDomainService.java
+│   │   │           │
+│   │   │           └── repository/
+│   │   │               └── PaymentRepository.java
+│   │   │
+│   │   ├── payment-service-application/
+│   │   ├── payment-service-infrastructure/
+│   │   ├── payment-service-interfaces/
+│   │   └── payment-service-start/
+│   │
+│   ├── inventory-service/               # 库存服务
+│   │   ├── inventory-service-api/
+│   │   ├── inventory-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/inventory/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   └── Inventory.java
+│   │   │           │   │
+│   │   │           │   └── event/
+│   │   │           │       └── InventoryDeductedEvent.java
+│   │   │           │
+│   │   │           ├── service/
+│   │   │           │   └── InventoryDomainService.java
+│   │   │           │
+│   │   │           └── repository/
+│   │   │               └── InventoryRepository.java
+│   │   │
+│   │   ├── inventory-service-application/
+│   │   ├── inventory-service-infrastructure/
+│   │   ├── inventory-service-interfaces/
+│   │   └── inventory-service-start/
+│   │
+│   └── notification-service/            # 通知服务
+│       ├── notification-service-api/
+│       ├── notification-service-domain/
+│       ├── notification-service-application/
+│       ├── notification-service-infrastructure/
+│       ├── notification-service-interfaces/
+│       └── notification-service-start/
+│
+│
+├── gateway/                             # 网关服务
+│   ├── gateway-start/
+│   │   └── src/main/java/
+│   │       └── com/ecommerce/gateway/
+│   │           └── GatewayApplication.java
+│   ├── gateway-interfaces/
+│   │   └── src/main/java/
+│   │       └── com/ecommerce/gateway/interfaces/
+│   │           ├── web/
+│   │           │   ├── controller/
+│   │           │   │   └── GatewayController.java
+│   │           │   └── filter/
+│   │           │       ├── AuthFilter.java
+│   │           │       ├── RateLimitFilter.java
+│   │           │       └── RoutingFilter.java
+│   │           └── rpc/
+│   └── pom.xml
+│
+│
+├── shared/                              # 共享服务
+│   │
+│   ├── auth-service/                    # 认证授权服务
+│   │   ├── auth-service-api/
+│   │   ├── auth-service-domain/
+│   │   ├── auth-service-application/
+│   │   ├── auth-service-infrastructure/
+│   │   ├── auth-service-interfaces/
+│   │   └── auth-service-start/
+│   │
+│   └── config-service/                  # 配置中心(可选)
+│       └── config-service-start/
+│
+│
+├── docs/                                # 文档
+│   ├── architecture/
+│   │   ├── ddd-architecture.md
+│   │   ├── bounded-contexts.md
+│   │   └── microservices.md
+│   ├── api/
+│   │   ├── user-service.yaml
+│   │   ├── order-service.yaml
+│   │   └── payment-service.yaml
+│   └── deployment/
+│       └── kubernetes/
+│
+├── scripts/                             # 脚本
+│   ├── deploy/
+│   │   ├── deploy-dev.sh
+│   │   └── deploy-prod.sh
+│   └── db/
+│       ├── init-user.sql
+│       ├── init-order.sql
+│       └── init-payment.sql
+│
+└── docker/                              # Docker 配置
+    ├── docker-compose.yml
+    └── kubernetes/
+        ├── user-service-deployment.yaml
+        ├── order-service-deployment.yaml
+        └── ingress.yaml
+```
+
+**微服务架构特点**:
+
+1. **服务独立部署**:每个服务有独立的启动模块和数据库
+2. **服务间通信**:通过 RPC(Dubbo/gRPC)和消息队列(Kafka/RocketMQ)
+3. **共享组件**:`platform-common` 提供通用能力
+4. **网关统一入口**:`gateway` 服务处理路由、认证、限流
+5. **独立数据库**:每个服务拥有自己的数据库 schema
+6. **模块化设计**:每个服务内部按 DDD 四层架构组织
+
+**微服务依赖关系**(跨服务):
+
+```
+┌─────────────┐      ┌─────────────┐
+│  Frontend   │─────▶│   Gateway   │
+└─────────────┘      └─────────────┘
+                            │
+            ┌───────────────┼───────────────┐
+            ▼               ▼               ▼
+    ┌───────────┐   ┌───────────┐   ┌───────────┐
+    │    User   │   │   Order   │   │  Product  │
+    │  Service  │◀──▶│  Service  │◀──▶│  Service  │
+    └───────────┘   └─────┬─────┘   └───────────┘
+                          │
+                ┌─────────┼─────────┐
+                ▼         ▼         ▼
+          ┌─────────┐ ┌───────┐ ┌─────────┐
+          │ Payment │ │Inventory│ │Notification│
+          │ Service │ │ Service│ │  Service │
+          └─────────┘ └───────┘ └─────────┘
+```
+
+---
+
+## 3. DDD 经典分层架构原则与依赖关系
+
+### 3.1 经典四层架构
+
+DDD 经典分层架构由 Eric Evans 在《领域驱动设计》一书中提出:
+
+```
+┌─────────────────────────────────────────────────────────┐
+│                    接口层 (Interfaces)                    │
+│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐   │
+│  │   Web   │  │   RPC   │  │   CLI   │  │ GraphQL │   │
+│  │Controller│  │Provider │  │   API   │  │Resolver │   │
+│  └─────────┘  └─────────┘  └─────────┘  └─────────┘   │
+└────────────────────────┬────────────────────────────────┘
+                         │
+                         ↓ 依赖
+┌─────────────────────────────────────────────────────────┐
+│                   应用层 (Application)                    │
+│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌─────────┐ │
+│  │Application│  │ Command  │  │  Query   │  │Event    │ │
+│  │ Service   │  │ Handler  │  │ Handler  │  │Handler  │ │
+│  └──────────┘  └──────────┘  └──────────┘  └─────────┘ │
+└────────────────────────┬────────────────────────────────┘
+                         │
+                         ↓ 依赖
+┌─────────────────────────────────────────────────────────┐
+│                    领域层 (Domain)                       │
+│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌─────────┐ │
+│  │ Aggregate│  │  Entity  │  │Value Obj.│  │Domain   │ │
+│  │   Root   │  │          │  │          │  │Service  │ │
+│  └──────────┘  └──────────┘  └──────────┘  └─────────┘ │
+│  ┌──────────┐  ┌──────────┐  ┌──────────┐               │
+│  │ Repository│  │ Specifi. │  │ Factory  │               │
+│  │(Interface)│  │   cation │  │          │               │
+│  └──────────┘  └──────────┘  └──────────┘               │
+└────────────────────────┬────────────────────────────────┘
+                         ↑
+                         │ 实现接口
+┌────────────────────────┴────────────────────────────────┐
+│                 基础设施层 (Infrastructure)                │
+│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌─────────┐ │
+│  │Repository│  │ Messaging│  │  Cache   │  │External │ │
+│  │ Impl.    │  │ Publisher │  │ Provider │  │Service  │ │
+│  └──────────┘  └──────────┘  └──────────┘  └─────────┘ │
+└─────────────────────────────────────────────────────────┘
+```
+
+### 3.2 依赖规则
+
+**核心规则**:依赖只能由外向内,领域层不依赖任何外层
+
+```java
+// ✓ 正确:接口层 依赖 应用层
+@RestController
+public class OrderController {
+    @Autowired
+    private OrderApplicationService orderApplicationService;  // 应用层
+}
+
+// ✓ 正确:应用层 依赖 领域层
+@Service
+public class OrderApplicationService {
+    @Autowired
+    private OrderRepository orderRepository;  // 领域层接口
+}
+
+// ✓ 正确:基础设施层 实现 领域层接口
+@Repository
+public class JpaOrderRepository implements OrderRepository {  // 领域层接口
+    // 基础设施层实现
+}
+
+// ✗ 错误:领域层不能依赖应用层
+@Entity
+public class Order {
+    @Autowired
+    private OrderApplicationService appService;  // 错误!
+}
+
+// ✗ 错误:领域层不能依赖基础设施层
+@Entity
+public class Order {
+    @Autowired
+    private OrderMapper orderMapper;  // 错误!
+}
+```
+
+### 3.3 各层职责
+
+| 层级 | 职责 | 典型组件 | 依赖方向 |
+|------|------|----------|----------|
+| **Interfaces** | 外部交互、数据转换 | Controller、DTO、Filter、Advice | → Application |
+| **Application** | 用例编排、流程协调 | ApplicationService、Command/Query Handler | → Domain |
+| **Domain** | 核心业务逻辑 | Aggregate、Entity、ValueObject、DomainService | → (只定义接口) |
+| **Infrastructure** | 技术实现、外部集成 | Repository Impl、Event Publisher、External Client | ← Domain(实现接口) |
+
+### 3.4 CQRS 模式实现
+
+DDD 架构通常结合 CQRS(Command Query Responsibility Segregation)模式:
+
+```java
+// 命令(Command)- 修改状态
+public class PlaceOrderCommand {
+    private String customerId;
+    private List<OrderItemDTO> items;
+    private Address shippingAddress;
+}
+
+@Component
+public class PlaceOrderCommandHandler {
+
+    @Autowired
+    private OrderRepository orderRepository;
+
+    @Autowired
+    private ProductRepository productRepository;
+
+    public OrderId handle(PlaceOrderCommand command) {
+        // 1. 创建领域对象
+        Customer customer = customerRepository.findById(new CustomerId(command.getCustomerId()));
+        Order order = Order.place(customer, command.getItems());
+
+        // 2. 调用领域服务
+        order.validate();
+
+        // 3. 持久化
+        orderRepository.save(order);
+
+        return order.getId();
+    }
+}
+
+// 查询(Query)- 读取状态
+public class GetOrderQuery {
+    private String orderId;
+}
+
+@Component
+public class GetOrderQueryHandler {
+
+    @Autowired
+    private OrderQueryRepository orderQueryRepository;  // 独立的查询仓储
+
+    public OrderDTO handle(GetOrderQuery query) {
+        // 直接查询,可以跳过领域模型
+        return orderQueryRepository.findById(query.getOrderId());
+    }
+}
+```
+
+---
+
+## 4. DDD 核心概念
+
+### 4.1 聚合(Aggregate)和聚合根(Aggregate Root)
+
+**目的**:定义一致性边界和数据修改边界
+
+```java
+// 聚合根:Order
+@Entity
+public class Order extends AggregateRoot {
+
+    private OrderId orderId;
+    private CustomerId customerId;
+    private Money totalAmount;
+    private OrderStatus status;
+    private List<OrderItem> items;  // 包含的实体
+
+    // 修改状态的入口点,保证不变式
+    public void addItem(Product product, int quantity) {
+        // 业务规则检查
+        if (this.status != OrderStatus.PENDING) {
+            throw new OrderException("只有待处理状态的订单可以添加商品");
+        }
+
+        // 添加明细
+        OrderItem item = new OrderItem(product, quantity);
+        this.items.add(item);
+
+        // 更新总金额(保证不变式)
+        recalculateTotal();
+    }
+
+    public void place() {
+        // 业务规则验证
+        if (items.isEmpty()) {
+            throw new OrderException("订单不能为空");
+        }
+
+        // 状态变更
+        this.status = OrderStatus.PLACED;
+
+        // 发布领域事件
+        registerEvent(new OrderPlacedEvent(this.orderId));
+    }
+
+    private void recalculateTotal() {
+        this.totalAmount = this.items.stream()
+            .map(OrderItem::getSubTotal)
+            .reduce(Money.ZERO, Money::add);
+    }
+}
+
+// 聚合内的实体:OrderItem
+@Entity
+public class OrderItem {
+
+    private OrderItemId itemId;
+    private ProductId productId;
+    private Money unitPrice;
+    private int quantity;
+    private Money subTotal;
+
+    // 只能通过聚合根操作
+    protected OrderItem(Product product, int quantity) {
+        this.productId = product.getId();
+        this.unitPrice = product.getPrice();
+        this.quantity = quantity;
+        this.subTotal = unitPrice.multiply(quantity);
+    }
+
+    public void increaseQuantity(int delta) {
+        this.quantity += delta;
+        this.subTotal = this.unitPrice.multiply(this.quantity);
+    }
+}
+```
+
+### 4.2 实体(Entity)和值对象(Value Object)
+
+```java
+// 实体:有唯一标识,可变
+@Entity
+public class Customer {
+
+    private CustomerId id;  // 唯一标识
+
+    private String name;
+    private Email email;
+    private PhoneNumber phone;
+
+    // 可变性:状态可以改变
+    public void changeName(String newName) {
+        if (newName == null || newName.isEmpty()) {
+            throw new IllegalArgumentException("姓名不能为空");
+        }
+        this.name = newName;
+    }
+
+    // 相等性:通过 ID 判断
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
+        Customer customer = (Customer) obj;
+        return id.equals(customer.id);
+    }
+}
+
+// 值对象:无唯一标识,不可变
+@ValueObject
+public class Email {
+
+    private final String value;  // final,不可变
+
+    public Email(String value) {
+        if (!isValid(value)) {
+            throw new IllegalArgumentException("无效的邮箱地址");
+        }
+        this.value = value;
+    }
+
+    private boolean isValid(String value) {
+        return value != null && value.matches("^[A-Za-z0-9+_.-]+@(.+)$");
+    }
+
+    // 相等性:通过所有属性判断
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
+        Email email = (Email) obj;
+        return value.equals(email.value);
+    }
+
+    @Override
+    public int hashCode() {
+        return value.hashCode();
+    }
+}
+
+// 另一个值对象示例:Money
+@ValueObject
+public class Money {
+
+    private final BigDecimal amount;
+    private final String currency;
+
+    public Money(BigDecimal amount, String currency) {
+        this.amount = amount;
+        this.currency = currency;
+    }
+
+    public Money add(Money other) {
+        if (!this.currency.equals(other.currency)) {
+            throw new IllegalArgumentException("货币类型不同");
+        }
+        return new Money(this.amount.add(other.amount), this.currency);
+    }
+
+    public Money multiply(double multiplier) {
+        return new Money(
+            this.amount.multiply(BigDecimal.valueOf(multiplier)),
+            this.currency
+        );
+    }
+
+    public static Money ZERO = new Money(BigDecimal.ZERO, "CNY");
+}
+```
+
+### 4.3 仓储(Repository)模式
+
+```java
+// 1. 定义仓储接口(位于领域层)
+public interface OrderRepository {
+
+    /**
+     * 保存订单
+     */
+    void save(Order order);
+
+    /**
+     * 根据 ID 查找订单
+     */
+    Optional<Order> findById(OrderId orderId);
+
+    /**
+     * 查找客户的订单列表
+     */
+    List<Order> findByCustomerId(CustomerId customerId);
+
+    /**
+     * 删除订单
+     */
+    void delete(OrderId orderId);
+}
+
+// 2. 实现仓储(位于基础设施层)
+@Repository
+public class JpaOrderRepository implements OrderRepository {
+
+    @Autowired
+    private OrderJpaRepository jpaRepository;
+
+    @Autowired
+    private OrderMapper mapper;
+
+    @Override
+    public void save(Order order) {
+        OrderEntity entity = mapper.toEntity(order);
+        jpaRepository.save(entity);
+
+        // 发布领域事件
+        for (DomainEvent event : order.getDomainEvents()) {
+            eventPublisher.publish(event);
+        }
+        order.clearDomainEvents();
+    }
+
+    @Override
+    public Optional<Order> findById(OrderId orderId) {
+        OrderEntity entity = jpaRepository.findById(orderId.getValue());
+        return entity != null
+            ? Optional.of(mapper.toDomain(entity))
+            : Optional.empty();
+    }
+
+    @Override
+    public List<Order> findByCustomerId(CustomerId customerId) {
+        List<OrderEntity> entities = jpaRepository.findByCustomerId(customerId.getValue());
+        return entities.stream()
+            .map(mapper::toDomain)
+            .collect(Collectors.toList());
+    }
+
+    @Override
+    public void delete(OrderId orderId) {
+        jpaRepository.deleteById(orderId.getValue());
+    }
+}
+```
+
+### 4.4 领域事件(Domain Event)
+
+```java
+// 1. 定义领域事件
+@Data
+public class OrderPlacedEvent implements DomainEvent {
+
+    private final OrderId orderId;
+    private final CustomerId customerId;
+    private final Money totalAmount;
+    private final LocalDateTime occurredOn;
+
+    public OrderPlacedEvent(OrderId orderId, CustomerId customerId, Money totalAmount) {
+        this.orderId = orderId;
+        this.customerId = customerId;
+        this.totalAmount = totalAmount;
+        this.occurredOn = LocalDateTime.now();
+    }
+}
+
+// 2. 在聚合根中发布事件
+@Entity
+public class Order extends AggregateRoot {
+
+    private List<DomainEvent> domainEvents = new ArrayList<>();
+
+    public void place() {
+        // 业务逻辑
+        this.status = OrderStatus.PLACED;
+
+        // 发布领域事件
+        registerEvent(new OrderPlacedEvent(
+            this.orderId,
+            this.customerId,
+            this.totalAmount
+        ));
+    }
+
+    public List<DomainEvent> getDomainEvents() {
+        return Collections.unmodifiableList(domainEvents);
+    }
+
+    public void clearDomainEvents() {
+        this.domainEvents.clear();
+    }
+}
+
+// 3. 事件处理器(位于应用层)
+@Component
+public class OrderPlacedEventHandler {
+
+    @Autowired
+    private NotificationService notificationService;
+
+    @Autowired
+    private CustomerServiceClient customerServiceClient;
+
+    @EventListener
+    public void handle(OrderPlacedEvent event) {
+        // 发送订单确认邮件
+        notificationService.sendOrderConfirmation(
+            event.getCustomerId(),
+            event.getOrderId()
+        );
+
+        // 更新客户统计信息
+        customerServiceClient.incrementOrderCount(event.getCustomerId());
+    }
+}
+```
+
+### 4.5 领域服务(Domain Service)
+
+```java
+// 当业务逻辑不适合放在实体或值对象中时,使用领域服务
+@DomainService
+public class PricingDomainService {
+
+    @Autowired
+    private ProductRepository productRepository;
+
+    @Autowired
+    private DiscountPolicy discountPolicy;
+
+    /**
+     * 计算订单价格(涉及多个实体,不适合放在 Order 中)
+     */
+    public Money calculateOrderPrice(Order order, Customer customer) {
+        // 基础价格
+        Money basePrice = order.getBasePrice();
+
+        // 应用客户折扣
+        Money discount = discountPolicy.calculateDiscount(customer, basePrice);
+
+        // 返回最终价格
+        return basePrice.subtract(discount);
+    }
+}
+```
+
+### 4.6 规约(Specification)模式
+
+```java
+// 1. 定义规约接口
+public interface Specification<T> {
+
+    boolean isSatisfiedBy(T candidate);
+
+    and Specification<T> and(Specification<T> other);
+    or Specification<T> or(Specification<T> other);
+    not Specification<T> not();
+}
+
+// 2. 抽象基类
+public abstract class AbstractSpecification<T> implements Specification<T> {
+
+    @Override
+    public and Specification<T> and(Specification<T> other) {
+        return new AndSpecification<>(this, other);
+    }
+
+    @Override
+    public or Specification<T> or(Specification<T> other) {
+        return new OrSpecification<>(this, other);
+    }
+
+    @Override
+    public not Specification<T> not() {
+        return new NotSpecification<>(this);
+    }
+}
+
+// 3. 具体规约
+public class CustomerCanPlaceOrderSpecification extends AbstractSpecification<Customer> {
+
+    private final OrderRepository orderRepository;
+
+    @Override
+    public boolean isSatisfiedBy(Customer customer) {
+        // 检查用户是否激活
+        if (!customer.isActive()) {
+            return false;
+        }
+
+        // 检查用户是否有过多未支付订单
+        List<Order> unpaidOrders = orderRepository.findUnpaidByCustomer(customer.getId());
+        if (unpaidOrders.size() >= 3) {
+            return false;
+        }
+
+        return true;
+    }
+}
+
+// 4. 使用规约
+@Service
+public class OrderApplicationService {
+
+    @Autowired
+    private CustomerCanPlaceOrderSpecification canPlaceOrderSpec;
+
+    public void placeOrder(PlaceOrderCommand command) {
+        Customer customer = customerRepository.findById(command.getCustomerId());
+
+        // 使用规约进行业务规则验证
+        if (!canPlaceOrderSpec.isSatisfiedBy(customer)) {
+            throw new OrderException("当前用户不能下单");
+        }
+
+        // 继续下单流程
+    }
+}
+```
+
+### 4.7 工厂(Factory)模式
+
+```java
+// 当创建复杂对象或聚合时,使用工厂
+@Factory
+public class OrderFactory {
+
+    private final ProductRepository productRepository;
+
+    /**
+     * 创建订单(涉及复杂的创建逻辑)
+     */
+    public Order createOrder(Customer customer, List<CreateOrderItemRequest> items) {
+        // 验证
+        if (items == null || items.isEmpty()) {
+            throw new IllegalArgumentException("订单明细不能为空");
+        }
+
+        // 创建订单
+        Order order = new Order(
+            OrderId.generate(),
+            customer.getId(),
+            OrderStatus.PENDING
+        );
+
+        // 添加明细
+        for (CreateOrderItemRequest item : items) {
+            Product product = productRepository.findById(item.getProductId());
+
+            // 验证库存
+            if (!product.hasStock(item.getQuantity())) {
+                throw new InsufficientStockException(product.getId());
+            }
+
+            order.addItem(product, item.getQuantity());
+        }
+
+        return order;
+    }
+}
+```
+
+---
+
+## 总结
+
+DDD 经典分层架构的核心价值:
+
+1. **关注点分离**:四层架构各司其职,降低耦合
+2. **领域为核心**:领域层独立,不依赖任何外部技术
+3. **依赖倒置**:通过接口隔离领域层和基础设施层
+4. **业务语言统一**:代码结构直接反映业务概念
+5. **可测试性**:各层可独立测试,领域层完全可单元测试
+6. **可扩展性**:无论是单体应用还是微服务,架构模式一致
+
+DDD 战略模式(限界上下文、上下文映射)与战术模式(聚合、实体、值对象、仓储)的结合,帮助团队构建易于理解、易于维护、易于演化的企业级应用。
+
+**权威参考**:
+- 《领域驱动设计》- Eric Evans
+- 《实现领域驱动设计》- Vaughn Vernon
+- 《领域驱动设计精粹》- Vaughn Vernon

+ 823 - 0
skills/ddd4j-project-builder/docs/2、六边形架构详细目录结构参考.md

@@ -0,0 +1,823 @@
+# 六边形架构(端口和适配器)目录结构
+
+## 📋 目录
+
+1. [单体工程目录结构](#单体工程目录结构)
+2. [大型微服务工程目录结构](#大型微服务工程目录结构)
+3. [架构原则与依赖关系](#架构原则与依赖关系)
+4. [六边形架构核心概念](#六边形架构核心概念)
+
+---
+
+## 🏢 单体工程目录结构
+
+**适用场景**: 中小型项目,单一限界上下文,需要清晰的技术隔离
+
+```
+order-service/                                    # 订单服务(单体应用)
+├── 📁 src/
+│   ├── 📁 main/
+│   │   ├── 📁 java/io/ddd4j/order/
+│   │   │   │
+│   │   │   ├── 📁 application/                  # 应用层(用例层)
+│   │   │   │   ├── 📁 ports/                    # 端口定义(接口)
+│   │   │   │   │   ├── 📁 inbound/             # 入站端口(驱动端)
+│   │   │   │   │   │   ├── IOrderService.java          # 订单服务端口
+│   │   │   │   │   │   │   ├── createOrder(CreateOrderCmd): OrderId
+│   │   │   │   │   │   │   ├── getOrder(OrderId): Order
+│   │   │   │   │   │   │   └── cancelOrder(OrderId): void
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── ICustomerService.java       # 客户服务端口
+│   │   │   │   │   │   └── IPaymentService.java        # 支付服务端口
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 outbound/            # 出站端口(被驱动端)
+│   │   │   │   │       ├── IOrderRepository.java       # 订单仓储端口
+│   │   │   │   │       │   ├── save(Order): void
+│   │   │   │   │       │   ├── findById(OrderId): Order
+│   │   │   │   │       │   └── findByCustomer(CustomerId): List<Order>
+│   │   │   │   │       │
+│   │   │   │   │       ├── ICustomerRepository.java    # 客户仓储端口
+│   │   │   │   │       ├── IProductRepository.java     # 产品仓储端口
+│   │   │   │   │       │
+│   │   │   │   │       ├── IPaymentProvider.java       # 支付提供商端口
+│   │   │   │   │       │   └── processPayment(PaymentInfo): PaymentResult
+│   │   │   │   │       │
+│   │   │   │   │       ├── INotificationService.java   # 通知服务端口
+│   │   │   │   │       └── IEventPublisher.java        # 事件发布端口
+│   │   │   │   │
+│   │   │   │   ├── 📁 services/                 # 应用服务实现
+│   │   │   │   │   ├── OrderServiceImpl.java          # 实现IOrderService
+│   │   │   │   │   │   ├── @Service
+│   │   │   │   │   │   └── implements IOrderService
+│   │   │   │   │   │
+│   │   │   │   │   ├── CustomerServiceImpl.java        # 实现ICustomerService
+│   │   │   │   │   └── PaymentServiceImpl.java         # 实现IPaymentService
+│   │   │   │   │
+│   │   │   │   ├── 📁 usecases/                 # 具体用例
+│   │   │   │   │   ├── 📁 order/                    # 订单用例
+│   │   │   │   │   │   ├── CreateOrderUseCase.java
+│   │   │   │   │   │   │   ├── execute(CreateOrderCmd): OrderId
+│   │   │   │   │   │   │   └── validate(CreateOrderCmd): void
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── ProcessOrderUseCase.java
+│   │   │   │   │   │   └── CancelOrderUseCase.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 customer/                # 客户用例
+│   │   │   │   │   │   ├── RegisterCustomerUseCase.java
+│   │   │   │   │   │   └── ValidateCustomerUseCase.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 dto/                      # 用例DTO
+│   │   │   │   │       ├── CreateOrderCmd.java
+│   │   │   │   │       ├── OrderDTO.java
+│   │   │   │   │       └── PaymentDTO.java
+│   │   │   │   │
+│   │   │   │   └── 📁 exception/                # 应用层异常
+│   │   │   │       ├── ApplicationException.java
+│   │   │   │       ├── ValidationException.java
+│   │   │   │       └── BusinessRuleException.java
+│   │   │   │
+│   │   │   ├── 📁 domain/                       # 领域层(核心业务逻辑)
+│   │   │   │   ├── 📁 model/                    # 领域模型/实体
+│   │   │   │   │   ├── Order.java                # 订单聚合根
+│   │   │   │   │   │   ├── OrderId
+│   │   │   │   │   │   ├── CustomerId
+│   │   │   │   │   │   ├── List<OrderItem>
+│   │   │   │   │   │   ├── OrderStatus
+│   │   │   │   │   │   ├── Money
+│   │   │   │   │   │   ├── place()
+│   │   │   │   │   │   ├── pay()
+│   │   │   │   │   │   └── cancel()
+│   │   │   │   │   │
+│   │   │   │   │   ├── OrderItem.java            # 订单项
+│   │   │   │   │   ├── Customer.java             # 客户实体
+│   │   │   │   │   └── Product.java              # 产品实体
+│   │   │   │   │
+│   │   │   │   ├── 📁 valueobject/              # 值对象
+│   │   │   │   │   ├── OrderId.java
+│   │   │   │   │   ├── CustomerId.java
+│   │   │   │   │   ├── Money.java
+│   │   │   │   │   │   ├── amount: BigDecimal
+│   │   │   │   │   │   ├── currency: Currency
+│   │   │   │   │   │   ├── add(Money): Money
+│   │   │   │   │   │   └── equals(): boolean
+│   │   │   │   │   │
+│   │   │   │   │   ├── Email.java
+│   │   │   │   │   ├── PhoneNumber.java
+│   │   │   │   │   ├── Address.java
+│   │   │   │   │   └── Quantity.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 event/                    # 领域事件
+│   │   │   │   │   ├── DomainEvent.java         # 基础事件接口
+│   │   │   │   │   │   ├── occurredOn(): Instant
+│   │   │   │   │   │   └── getAggregateId(): String
+│   │   │   │   │   │
+│   │   │   │   │   ├── OrderCreatedEvent.java
+│   │   │   │   │   ├── OrderPaidEvent.java
+│   │   │   │   │   ├── OrderCancelledEvent.java
+│   │   │   │   │   └── CustomerRegisteredEvent.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 service/                  # 领域服务
+│   │   │   │   │   ├── OrderValidationService.java
+│   │   │   │   │   ├── PricingService.java
+│   │   │   │   │   └── InventoryService.java
+│   │   │   │   │
+│   │   │   │   └── 📁 exception/                # 领域异常
+│   │   │   │       ├── DomainException.java
+│   │   │   │       └── InvalidStateException.java
+│   │   │   │
+│   │   │   ├── 📁 infrastructure/               # 基础设施层(适配器实现)
+│   │   │   │   ├── 📁 adapter/                  # 适配器实现
+│   │   │   │   │   ├── 📁 inbound/             # 入站适配器(驱动适配器)
+│   │   │   │   │   │   ├── 📁 web/             # Web适配器
+│   │   │   │   │   │   │   ├── 📁 controller/
+│   │   │   │   │   │   │   │   ├── OrderController.java           # REST控制器
+│   │   │   │   │   │   │   │   │   ├── @RestController
+│   │   │   │   │   │   │   │   │   ├── @RequestMapping("/api/orders")
+│   │   │   │   │   │   │   │   │   └── implements IOrderService
+│   │   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   │   ├── CustomerController.java
+│   │   │   │   │   │   │   │   └── PaymentController.java
+│   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   ├── 📁 dto/         # 请求/响应DTO
+│   │   │   │   │   │   │   │   ├── 📁 request/
+│   │   │   │   │   │   │   │   │   ├── CreateOrderRequest.java
+│   │   │   │   │   │   │   │   │   └── UpdateOrderRequest.java
+│   │   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   │   └── 📁 response/
+│   │   │   │   │   │   │   │       ├── OrderResponse.java
+│   │   │   │   │   │   │   │       └── ApiResponse.java
+│   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   ├── 📁 filter/      # Web过滤器
+│   │   │   │   │   │   │   │   ├── AuthenticationFilter.java
+│   │   │   │   │   │   │   │   ├── LoggingFilter.java
+│   │   │   │   │   │   │   │   └── CorsFilter.java
+│   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   ├── 📁 interceptor/ # 拦截器
+│   │   │   │   │   │   │   │   └── PerformanceInterceptor.java
+│   │   │   │   │   │   │   │
+│   │   │   │   │   │   │   └── 📁 exception/   # 异常处理
+│   │   │   │   │   │   │       ├── GlobalExceptionHandler.java
+│   │   │   │   │   │   │       └── ErrorResponse.java
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── 📁 cli/         # 命令行适配器
+│   │   │   │   │   │   │   └── CommandLineInterface.java
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── 📁 messaging/   # 消息适配器
+│   │   │   │   │   │   │   ├── OrderMessageConsumer.java
+│   │   │   │   │   │   │   └── EventSubscriber.java
+│   │   │   │   │   │   │
+│   │   │   │   │   │   └── 📁 scheduled/   # 定时任务适配器
+│   │   │   │   │   │       └── OrderCleanupScheduler.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 outbound/        # 出站适配器(被驱动适配器)
+│   │   │   │   │       ├── 📁 persistence/  # 持久化适配器
+│   │   │   │   │       │   ├── 📁 repositoryimpl/
+│   │   │   │   │       │   │   ├── OrderRepositoryImpl.java    # 实现IOrderRepository
+│   │   │   │   │       │   │   ├── CustomerRepositoryImpl.java
+│   │   │   │   │       │   │   └── ProductRepositoryImpl.java
+│   │   │   │   │       │   │
+│   │   │   │   │       │   ├── 📁 mapper/
+│   │   │   │   │       │   │   ├── OrderMapper.java           # MyBatis Mapper
+│   │   │   │   │       │   │   └── OrderDataMapper.java      # DO<->Entity转换
+│   │   │   │   │       │   │
+│   │   │   │   │       │   └── 📁 entity/
+│   │   │   │   │       │       ├── OrderEntity.java           # JPA/MyBatis实体
+│   │   │   │   │       │       ├── CustomerEntity.java
+│   │   │   │   │       │       └── ProductEntity.java
+│   │   │   │   │       │
+│   │   │   │   │       ├── 📁 external/     # 外部服务适配器
+│   │   │   │   │       │   ├── PaymentProviderAdapter.java   # 实现IPaymentProvider
+│   │   │   │   │       │   │   ├── @Service
+│   │   │   │   │       │   │   └── implements IPaymentProvider
+│   │   │   │   │       │   │
+│   │   │   │   │       │   ├── EmailServiceAdapter.java     # 实现INotificationService
+│   │   │   │   │       │   │   ├── SMSServiceAdapter.java
+│   │   │   │   │       │   │   └── ThirdPartyApiClient.java
+│   │   │   │   │       │
+│   │   │   │   │       ├── 📁 messaging/   # 消息适配器
+│   │   │   │   │       │   ├── EventPublisherAdapter.java   # 实现IEventPublisher
+│   │   │   │   │       │   ├── MessageProducer.java
+│   │   │   │   │       │   └── QueueSender.java
+│   │   │   │   │       │
+│   │   │   │   │       └── 📁 cache/       # 缓存适配器
+│   │   │   │   │           ├── RedisCacheAdapter.java
+│   │   │   │   │           └── LocalCacheAdapter.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 config/                   # 配置类
+│   │   │   │   │   ├── DatabaseConfig.java
+│   │   │   │   │   ├── WebConfig.java
+│   │   │   │   │   ├── SecurityConfig.java
+│   │   │   │   │   ├── CacheConfig.java
+│   │   │   │   │   └── BeanConfig.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 database/                 # 数据库相关
+│   │   │   │   │   ├── 📁 migration/
+│   │   │   │   │   │   ├── V1__init.sql
+│   │   │   │   │   │   └── V2__add_orders.sql
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 enums/
+│   │   │   │   │       ├── OrderStatus.java
+│   │   │   │   │       └── UserRole.java
+│   │   │   │   │
+│   │   │   │   └── 📁 security/                 # 安全相关
+│   │   │   │       ├── JwtTokenProvider.java
+│   │   │   │       ├── PasswordEncoder.java
+│   │   │   │       └── SecurityUtils.java
+│   │   │   │
+│   │   │   ├── 📁 shared/                       # 共享组件
+│   │   │   │   ├── 📁 kernel/                   # 核心共享
+│   │   │   │   │   ├── BaseEntity.java
+│   │   │   │   │   ├── AggregateRoot.java
+│   │   │   │   │   ├── ValueObject.java
+│   │   │   │   │   └── Identifier.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 util/                     # 工具类
+│   │   │   │   │   ├── DateUtils.java
+│   │   │   │   │   ├── StringUtils.java
+│   │   │   │   │   ├── Validator.java
+│   │   │   │   │   └── ObjectMapperUtils.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 constants/                # 常量定义
+│   │   │   │   │   ├── AppConstants.java
+│   │   │   │   │   ├── ErrorCodes.java
+│   │   │   │   │   └── ValidationMessages.java
+│   │   │   │   │
+│   │   │   │   └── 📁 exception/                # 全局异常
+│   │   │   │       ├── GlobalException.java
+│   │   │   │       ├── ErrorResponse.java
+│   │   │   │       └── ExceptionHandler.java
+│   │   │   │
+│   │   │   └── OrderApplication.java           # 应用启动类
+│   │   │       ├── @SpringBootApplication
+│   │   │       └── main(String[] args)
+│   │   │
+│   │   └── 📁 resources/
+│   │       ├── application.yml
+│   │       ├── application-dev.yml
+│   │       ├── application-prod.yml
+│   │       ├── 📁 db/
+│   │       │   ├── migration/
+│   │       │   └── seed/
+│   │       ├── 📁 i18n/
+│   │       │   ├── messages.properties
+│   │       │   └── messages_zh.properties
+│   │       ├── 📁 templates/
+│   │       │   └── email/
+│   │       ├── logback-spring.xml
+│   │       └── banner.txt
+│   │
+│   └── 📁 test/
+│       ├── 📁 unit/
+│       │   ├── 📁 domain/
+│       │   │   ├── OrderTest.java
+│       │   │   └── MoneyTest.java
+│       │   ├── 📁 application/
+│       │   │   └── CreateOrderUseCaseTest.java
+│       │   └── 📁 infrastructure/
+│       │       └── OrderRepositoryImplTest.java
+│       │
+│       ├── 📁 integration/
+│       │   └── OrderIntegrationTest.java
+│       │
+│       └── 📁 e2e/
+│           └── ApiE2ETest.java
+│
+├── 📁 docker/
+│   ├── Dockerfile
+│   └── docker-compose.yml
+│
+├── pom.xml
+├── README.md
+└── .gitignore
+```
+
+---
+
+## 🏢 大型微服务工程目录结构
+
+**适用场景**: 大型企业项目,多限界上下文,需要独立部署和技术隔离
+
+```
+ecommerce-platform/                                  # 电商平台(微服务父工程)
+│
+├── 📁 order-service/                              # 订单服务(独立微服务)
+│   ├── 📁 order-api/                              # API模块(端口定义)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/api/
+│   │   │   ├── 📁 ports/                          # 端口接口
+│   │   │   │   ├── 📁 inbound/
+│   │   │   │   │   ├── IOrderService.java         # 订单服务端口
+│   │   │   │   │   ├── ICustomerService.java
+│   │   │   │   │   └── IPaymentService.java
+│   │   │   │   │
+│   │   │   │   └── 📁 outbound/
+│   │   │   │       ├── IOrderRepository.java      # 仓储端口
+│   │   │   │       ├── ICustomerRepository.java
+│   │   │   │       ├── IPaymentProvider.java      # 支付端口
+│   │   │   │       └── IEventPublisher.java       # 事件发布端口
+│   │   │   │
+│   │   │   └── 📁 dto/                            # API DTO
+│   │   │       ├── CreateOrderCmd.java
+│   │   │       ├── OrderDTO.java
+│   │   │       └── OrderItemDTO.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-domain/                           # 领域模块(核心业务)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/domain/
+│   │   │   ├── 📁 model/
+│   │   │   │   ├── Order.java                     # 聚合根
+│   │   │   │   ├── OrderItem.java
+│   │   │   │   ├── Customer.java
+│   │   │   │   └── Product.java
+│   │   │   │
+│   │   │   ├── 📁 valueobject/
+│   │   │   │   ├── OrderId.java
+│   │   │   │   ├── Money.java
+│   │   │   │   └── Email.java
+│   │   │   │
+│   │   │   ├── 📁 event/
+│   │   │   │   ├── OrderCreatedEvent.java
+│   │   │   │   └── OrderPaidEvent.java
+│   │   │   │
+│   │   │   ├── 📁 service/
+│   │   │   │   └── OrderValidationService.java
+│   │   │   │
+│   │   │   └── 📁 exception/
+│   │   │       └── DomainException.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-application/                      # 应用模块(用例实现)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/application/
+│   │   │   ├── 📁 services/
+│   │   │   │   ├── OrderServiceImpl.java           # 实现IOrderService
+│   │   │   │   └── CustomerServiceImpl.java
+│   │   │   │
+│   │   │   ├── 📁 usecases/
+│   │   │   │   ├── CreateOrderUseCase.java
+│   │   │   │   ├── ProcessOrderUseCase.java
+│   │   │   │   └── CancelOrderUseCase.java
+│   │   │   │
+│   │   │   └── 📁 exception/
+│   │   │       └── ApplicationException.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-infrastructure/                   # 基础设施模块(适配器实现)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/infrastructure/
+│   │   │   ├── 📁 adapter/
+│   │   │   │   ├── 📁 inbound/
+│   │   │   │   │   ├── 📁 web/
+│   │   │   │   │   │   ├── OrderController.java   # REST适配器
+│   │   │   │   │   │   └── dto/
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 messaging/
+│   │   │   │   │   │   └── OrderEventConsumer.java  # 消息适配器
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 cli/
+│   │   │   │   │       └── CommandLineAdapter.java
+│   │   │   │   │
+│   │   │   │   └── 📁 outbound/
+│   │   │   │       ├── 📁 persistence/
+│   │   │   │       │   ├── OrderRepositoryImpl.java    # 持久化适配器
+│   │   │   │       │   ├── OrderMapper.java
+│   │   │   │       │   └── OrderEntity.java
+│   │   │   │       │
+│   │   │   │       ├── 📁 external/
+│   │   │   │       │   ├── PaymentProviderAdapter.java   # 外部服务适配器
+│   │   │   │       │   └── EmailServiceAdapter.java
+│   │   │   │       │
+│   │   │   │       └── 📁 messaging/
+│   │   │   │           └── EventPublisherAdapter.java   # 消息发布适配器
+│   │   │   │
+│   │   │   ├── 📁 config/
+│   │   │   │   ├── DatabaseConfig.java
+│   │   │   │   ├── WebConfig.java
+│   │   │   │   └── SecurityConfig.java
+│   │   │   │
+│   │   │   └── 📁 security/
+│   │   │       └── JwtTokenProvider.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-start/                             # 启动模块
+│   │   ├── 📁 src/main/java/io/ddd4j/order/
+│   │   │   └── OrderApplication.java
+│   │   │
+│   │   ├── 📁 src/main/resources/
+│   │   │   ├── application.yml
+│   │   │   └── 📁 mapper/
+│   │   │
+│   │   └── pom.xml
+│   │
+│   └── pom.xml                                     # 订单服务父POM
+│
+├── 📁 customer-service/                           # 客户服务(独立微服务)
+│   ├── 📁 customer-api/                           # 客户API模块
+│   │   └── 📁 src/main/java/io/ddd4j/customer/api/
+│   │       ├── 📁 ports/
+│   │       │   ├── ICustomerService.java
+│   │       │   └── ICustomerRepository.java
+│   │       └── 📁 dto/
+│   │
+│   ├── 📁 customer-domain/                        # 客户领域模块
+│   │   └── 📁 src/main/java/io/ddd4j/customer/domain/
+│   │       ├── 📁 model/
+│   │       │   └── Customer.java
+│   │       └── 📁 valueobject/
+│   │           └── Email.java
+│   │
+│   ├── 📁 customer-application/                   # 客户应用模块
+│   │   └── 📁 src/main/java/io/ddd4j/customer/application/
+│   │       └── 📁 services/
+│   │           └── CustomerServiceImpl.java
+│   │
+│   ├── 📁 customer-infrastructure/               # 客户基础设施模块
+│   │   └── 📁 src/main/java/io/ddd4j/customer/infrastructure/
+│   │       └── 📁 adapter/
+│   │           ├── 📁 inbound/
+│   │           │   └── 📁 web/
+│   │           │       └── CustomerController.java
+│   │           └── 📁 outbound/
+│   │               └── 📁 persistence/
+│   │                   └── CustomerRepositoryImpl.java
+│   │
+│   ├── 📁 customer-start/                         # 客户启动模块
+│   │   └── 📁 src/main/java/io/ddd4j/customer/
+│   │       └── CustomerApplication.java
+│   │
+│   └── pom.xml
+│
+├── 📁 payment-service/                            # 支付服务(独立微服务)
+│   ├── 📁 payment-api/
+│   ├── 📁 payment-domain/
+│   ├── 📁 payment-application/
+│   ├── 📁 payment-infrastructure/
+│   └── 📁 payment-start/
+│
+├── 📁 product-service/                            # 产品服务(独立微服务)
+│   ├── 📁 product-api/
+│   ├── 📁 product-domain/
+│   ├── 📁 product-application/
+│   ├── 📁 product-infrastructure/
+│   └── 📁 product-start/
+│
+├── 📁 shared-kernel/                              # 共享内核
+│   ├── 📁 shared-domain/                          # 共享领域模块
+│   │   └── 📁 src/main/java/io/ddd4j/shared/domain/
+│   │       ├── 📁 model/
+│   │       │   ├── Money.java
+│   │       │   └── Email.java
+│   │       └── 📁 event/
+│   │           └── DomainEvent.java
+│   │
+│   ├── 📁 shared-infrastructure/                  # 共享基础设施
+│   │   └── 📁 src/main/java/io/ddd4j/shared/infrastructure/
+│   │       ├── 📁 config/
+│   │       │   └── CommonConfig.java
+│   │       └── 📁 util/
+│   │           └── JsonUtils.java
+│   │
+│   └── pom.xml
+│
+├── 📁 gateway/                                    # API网关
+│   └── 📁 src/main/java/io/ddd4j/gateway/
+│       ├── GatewayApplication.java
+│       └── 📁 filter/
+│           ├── AuthFilter.java
+│           └── RateLimitFilter.java
+│
+├── 📁 docker/                                     # Docker编排
+│   ├── docker-compose.yml
+│   └── 📁 docker/
+│       ├── order-service/
+│       ├── customer-service/
+│       └── gateway/
+│
+├── 📁 k8s/                                        # Kubernetes配置
+│   ├── 📁 order-service/
+│   │   ├── deployment.yaml
+│   │   └── service.yaml
+│   │
+│   ├── 📁 customer-service/
+│   └── 📁 gateway/
+│
+├── pom.xml                                        # 父POM
+├── README.md
+└── .gitignore
+```
+
+---
+
+## 🏗 架构原则与依赖关系
+
+### 六边形架构核心原则
+
+```
+         ┌─────────────────────────────────────┐
+         │         应用层(Application)          │
+         │  - 用例(Use Cases)                 │
+         │  - 应用服务(Application Services)   │
+         └─────────────────────────────────────┘
+                      ↑           ↓
+    ┌─────────────────┴─────────────┴─────────────────┐
+    │                    端口(Ports)                    │
+    │         - 入站端口(Inbound/Driving)              │
+    │         - 出站端口(Outbound/Driven)              │
+    └─────────────────────────────────────────────────┘
+                      ↑           ↓
+    ┌─────────────────┴─────────────┴─────────────────┐
+    │                适配器(Adapters)                  │
+    │  - 入站适配器:Web、CLI、Messaging               │
+    │  - 出站适配器:Database、External API、Cache     │
+    └─────────────────────────────────────────────────┘
+```
+
+### 依赖规则
+
+```
+适配器(Adapters) → 端口(Ports) ← 应用层(Application) ← 领域层(Domain)
+```
+
+- **领域层**:完全独立,无任何外部依赖
+- **应用层**:依赖领域层,定义端口接口
+- **基础设施层**:实现应用层定义的端口
+- **适配器**:通过端口与应用层交互
+
+---
+
+## 🎯 六边形架构核心概念
+
+### 1. 端口(Ports)
+
+端口是应用与外部世界交互的接口,分为两类:
+
+#### 入站端口(Inbound/Driving Ports)
+定义应用对外提供的服务能力:
+
+```java
+// application/ports/inbound/IOrderService.java
+public interface IOrderService {
+    OrderId createOrder(CreateOrderCmd cmd);
+    Order getOrder(OrderId id);
+    void cancelOrder(OrderId id);
+    List<Order> getCustomerOrders(CustomerId customerId);
+}
+```
+
+#### 出站端口(Outbound/Driven Ports)
+定义应用依赖的外部服务:
+
+```java
+// application/ports/outbound/IOrderRepository.java
+public interface IOrderRepository {
+    void save(Order order);
+    Optional<Order> findById(OrderId id);
+    List<Order> findByCustomer(CustomerId customerId);
+}
+
+// application/ports/outbound/IPaymentProvider.java
+public interface IPaymentProvider {
+    PaymentResult processPayment(PaymentInfo paymentInfo);
+}
+
+// application/ports/outbound/IEventPublisher.java
+public interface IEventPublisher {
+    void publish(DomainEvent event);
+}
+```
+
+### 2. 适配器(Adapters)
+
+适配器是端口的具体实现,分为两类:
+
+#### 入站适配器(Inbound/Driving Adapters)
+驱动应用执行的适配器:
+
+```java
+// infrastructure/adapter/inbound/web/OrderController.java
+@RestController
+@RequestMapping("/api/orders")
+public class OrderController implements IOrderService {
+
+    private final IOrderService orderService; // 注入端口
+
+    @PostMapping
+    public ResponseEntity<OrderResponse> createOrder(@RequestBody CreateOrderRequest request) {
+        CreateOrderCmd cmd = toCommand(request);
+        OrderId orderId = orderService.createOrder(cmd);
+        return ResponseEntity.ok(new OrderResponse(orderId));
+    }
+
+    @GetMapping("/{id}")
+    public ResponseEntity<OrderResponse> getOrder(@PathVariable String id) {
+        Order order = orderService.getOrder(new OrderId(id));
+        return ResponseEntity.ok(toResponse(order));
+    }
+}
+```
+
+#### 出站适配器(Outbound/Driven Adapters)
+被应用调用的适配器:
+
+```java
+// infrastructure/adapter/outbound/persistence/OrderRepositoryImpl.java
+@Repository
+public class OrderRepositoryImpl implements IOrderRepository {
+
+    private final OrderMapper orderMapper;
+
+    @Override
+    public void save(Order order) {
+        OrderEntity entity = toEntity(order);
+        orderMapper.insert(entity);
+    }
+
+    @Override
+    public Optional<Order> findById(OrderId id) {
+        OrderEntity entity = orderMapper.selectById(id.getValue());
+        return Optional.ofNullable(toDomain(entity));
+    }
+}
+
+// infrastructure/adapter/outbound/external/PaymentProviderAdapter.java
+@Service
+public class PaymentProviderAdapter implements IPaymentProvider {
+
+    private final AlipayClient alipayClient;
+
+    @Override
+    public PaymentResult processPayment(PaymentInfo paymentInfo) {
+        // 调用支付宝API
+        return alipayClient.pay(paymentInfo);
+    }
+}
+```
+
+### 3. 用例(Use Cases)
+
+用例封装特定的业务流程:
+
+```java
+// application/usecases/order/CreateOrderUseCase.java
+@Component
+public class CreateOrderUseCase {
+
+    private final IOrderRepository orderRepository;
+    private final ICustomerRepository customerRepository;
+    private final IProductRepository productRepository;
+    private final IEventPublisher eventPublisher;
+
+    public OrderId execute(CreateOrderCmd cmd) {
+        // 1. 验证客户
+        Customer customer = customerRepository.findById(cmd.getCustomerId())
+            .orElseThrow(() -> new CustomerNotFoundException(cmd.getCustomerId()));
+
+        // 2. 创建订单
+        Order order = Order.create(
+            customer.getId(),
+            cmd.getItems(),
+            cmd.getShippingAddress()
+        );
+
+        // 3. 保存订单
+        orderRepository.save(order);
+
+        // 4. 发布事件
+        eventPublisher.publish(new OrderCreatedEvent(
+            order.getId(),
+            customer.getId(),
+            order.getTotalAmount()
+        ));
+
+        return order.getId();
+    }
+}
+```
+
+### 4. 依赖注入配置
+
+```java
+// infrastructure/config/BeanConfig.java
+@Configuration
+public class BeanConfig {
+
+    // 出站适配器Bean
+    @Bean
+    public IOrderRepository orderRepository(OrderMapper orderMapper) {
+        return new OrderRepositoryImpl(orderMapper);
+    }
+
+    @Bean
+    public IPaymentProvider paymentProvider(AlipayClient alipayClient) {
+        return new PaymentProviderAdapter(alipayClient);
+    }
+
+    @Bean
+    public IEventPublisher eventPublisher(KafkaTemplate<String, String> kafkaTemplate) {
+        return new KafkaEventPublisherAdapter(kafkaTemplate);
+    }
+
+    // 应用服务Bean
+    @Bean
+    public IOrderService orderService(
+        IOrderRepository orderRepository,
+        IPaymentProvider paymentProvider,
+        IEventPublisher eventPublisher
+    ) {
+        return new OrderServiceImpl(
+            orderRepository,
+            paymentProvider,
+            eventPublisher
+        );
+    }
+}
+```
+
+---
+
+## 📚 权威参考
+
+### 六边形架构创始人
+- **Alistair Cockburn** - 六边形架构(端口和适配器)创始人
+
+### 核心理念
+1. **隔离领域逻辑**:领域层完全独立,不依赖任何技术实现
+2. **端口隔离**:通过端口接口解耦应用与外部世界
+3. **适配器可替换**:适配器可以轻松替换而不影响应用核心
+4. **测试友好**:可以轻松mock端口进行测试
+
+### 最佳实践
+
+```java
+// 测试示例:使用Mock端口
+class CreateOrderUseCaseTest {
+
+    @Test
+    void should_create_order_successfully() {
+        // Given: Mock出站端口
+        IOrderRepository mockRepo = mock(IOrderRepository.class);
+        ICustomerRepository mockCustomerRepo = mock(ICustomerRepository.class);
+        IEventPublisher mockPublisher = mock(IEventPublisher.class);
+
+        // Setup mock behavior
+        when(mockCustomerRepo.findById(any())).thenReturn(Optional.of(customer));
+
+        // When: 执行用例
+        CreateOrderUseCase useCase = new CreateOrderUseCase(
+            mockRepo, mockCustomerRepo, mockPublisher
+        );
+        OrderId orderId = useCase.execute(cmd);
+
+        // Then: 验证交互
+        verify(mockRepo).save(any(Order.class));
+        verify(mockPublisher).publish(any(OrderCreatedEvent.class));
+    }
+}
+```
+
+---
+
+## 🔄 与其他架构的关系
+
+### 六边形架构 vs DDD 分层架构
+
+| 方面 | 六边形架构 | DDD 分层架构 |
+|------|-----------|-------------|
+| 核心理念 | 端口和适配器 | 领域驱动设计 |
+| 依赖方向 | 适配器 → 端口 ← 应用 | 接口 → 应用 → 领域 ← 基础设施 |
+| 关注点 | 技术隔离 | 业务领域建模 |
+| 适用场景 | 需要技术替换的场景 | 复杂业务领域 |
+
+### 六边形架构 vs 整洁架构
+
+- 六边形架构是整洁架构的前身
+- 整洁架构更强调同心圆层次结构
+- 两者都遵循依赖倒置原则
+
+---
+
+## 💡 选择建议
+
+### 选择六边形架构的场景:
+1. 需要频繁更换技术实现(如数据库、消息队列)
+2. 多种驱动方式(Web、CLI、消息)
+3. 高度可测试性要求
+4. 清晰的技术边界需求
+
+### 不选择六边形架构的场景:
+1. 简单CRUD应用
+2. 固定技术栈,不需要替换
+3. 小型团队,快速迭代
+
+---
+
+## 🚀 快速开始
+
+```bash
+# 创建六边形架构项目
+mvn archetype:generate \
+  -DarchetypeGroupId=io.ddd4j.boot \
+  -DarchetypeArtifactId=hexagonal-archetype \
+  -DarchetypeVersion=3.3.x
+```

+ 913 - 0
skills/ddd4j-project-builder/docs/3、整洁架构详细目录结构参考.md

@@ -0,0 +1,913 @@
+# 整洁架构(Clean Architecture)目录结构
+
+## 📋 目录
+
+1. [单体工程目录结构](#单体工程目录结构)
+2. [大型微服务工程目录结构](#大型微服务工程目录结构)
+3. [架构原则与依赖关系](#架构原则与依赖关系)
+4. [整洁架构核心概念](#整洁架构核心概念)
+
+---
+
+## 🏢 单体工程目录结构
+
+**适用场景**: 中小型项目,需要高度解耦和可测试性
+
+```
+order-service/                                    # 订单服务(单体应用)
+├── 📁 src/
+│   ├── 📁 main/
+│   │   ├── 📁 java/io/ddd4j/order/
+│   │   │   │
+│   │   │   ├── 📁 domain/                       # 领域层(最内层)
+│   │   │   │   ├── 📁 entity/                   # 业务实体
+│   │   │   │   │   ├── Order.java               # 订单实体
+│   │   │   │   │   │   ├── id: EntityId
+│   │   │   │   │   │   ├── customer: Customer
+│   │   │   │   │   │   ├── items: List<OrderItem>
+│   │   │   │   │   │   ├── status: OrderStatus
+│   │   │   │   │   │   ├── total: Money
+│   │   │   │   │   │   ├── place()
+│   │   │   │   │   │   ├── pay(Money)
+│   │   │   │   │   │   ├── cancel()
+│   │   │   │   │   │   └── validateBusinessRules()
+│   │   │   │   │   │
+│   │   │   │   │   ├── OrderItem.java           # 订单项实体
+│   │   │   │   │   │   ├── product: Product
+│   │   │   │   │   │   ├── quantity: Quantity
+│   │   │   │   │   │   ├── price: Money
+│   │   │   │   │   │   └── updateQuantity(Quantity)
+│   │   │   │   │   │
+│   │   │   │   │   ├── Customer.java            # 客户实体
+│   │   │   │   │   │   ├── id: CustomerId
+│   │   │   │   │   │   ├── name: CustomerName
+│   │   │   │   │   │   ├── email: Email
+│   │   │   │   │   │   └── register()
+│   │   │   │   │   │
+│   │   │   │   │   └── Payment.java             # 支付实体
+│   │   │   │   │       ├── id: PaymentId
+│   │   │   │   │       ├── amount: Money
+│   │   │   │   │       └── status: PaymentStatus
+│   │   │   │   │
+│   │   │   │   ├── 📁 valueobject/              # 值对象
+│   │   │   │   │   ├── Money.java
+│   │   │   │   │   │   ├── amount: BigDecimal
+│   │   │   │   │   │   ├── currency: Currency
+│   │   │   │   │   │   ├── add(Money): Money
+│   │   │   │   │   │   ├── subtract(Money): Money
+│   │   │   │   │   │   └── equals(): boolean
+│   │   │   │   │   │
+│   │   │   │   │   ├── Email.java
+│   │   │   │   │   │   ├── address: String
+│   │   │   │   │   │   └── validate(): void
+│   │   │   │   │   │
+│   │   │   │   │   ├── Quantity.java
+│   │   │   │   │   │   ├── value: int
+│   │   │   │   │   │   └── add(Quantity): Quantity
+│   │   │   │   │   │
+│   │   │   │   │   ├── OrderId.java
+│   │   │   │   │   ├── CustomerId.java
+│   │   │   │   │   ├── ProductId.java
+│   │   │   │   │   └── OrderStatus.java
+│   │   │   │   │       ├── PENDING, CONFIRMED, PAID, SHIPPED, CANCELLED
+│   │   │   │   │       └── canTransitionTo(OrderStatus)
+│   │   │   │   │
+│   │   │   │   ├── 📁 service/                  # 领域服务
+│   │   │   │   │   ├── OrderDomainService.java
+│   │   │   │   │   │   ├── calculateDiscount(Order): Money
+│   │   │   │   │   │   └── validateOrder(Order): boolean
+│   │   │   │   │   │
+│   │   │   │   │   ├── PricingService.java
+│   │   │   │   │   └── InventoryService.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 repository/               # 仓储接口(领域层定义)
+│   │   │   │   │   ├── OrderRepository.java
+│   │   │   │   │   │   ├── save(Order): Order
+│   │   │   │   │   │   ├── findById(OrderId): Order
+│   │   │   │   │   │   └── findAll(): List<Order>
+│   │   │   │   │   │
+│   │   │   │   │   ├── CustomerRepository.java
+│   │   │   │   │   └── ProductRepository.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 event/                    # 领域事件
+│   │   │   │   │   ├── DomainEvent.java         # 基础事件
+│   │   │   │   │   │   ├── occurredOn: Instant
+│   │   │   │   │   │   └── version: Long
+│   │   │   │   │   │
+│   │   │   │   │   ├── OrderEvents.java
+│   │   │   │   │   │   ├── OrderCreatedEvent.java
+│   │   │   │   │   │   ├── OrderPaidEvent.java
+│   │   │   │   │   │   └── OrderCancelledEvent.java
+│   │   │   │   │   │
+│   │   │   │   │   └── CustomerEvents.java
+│   │   │   │   │       └── CustomerRegisteredEvent.java
+│   │   │   │   │
+│   │   │   │   └── 📁 exception/                # 领域异常
+│   │   │   │       ├── DomainException.java
+│   │   │   │       ├── BusinessRuleException.java
+│   │   │   │       └── ValidationException.java
+│   │   │   │
+│   │   │   ├── 📁 application/                  # 应用层(用例层)
+│   │   │   │   ├── 📁 usecase/                  # 用例/交互器
+│   │   │   │   │   ├── 📁 order/                  # 订单用例
+│   │   │   │   │   │   ├── CreateOrderUseCase.java
+│   │   │   │   │   │   │   ├── @Component
+│   │   │   │   │   │   │   ├── execute(CreateOrderRequest): CreateOrderResponse
+│   │   │   │   │   │   │   └── validate(CreateOrderRequest): void
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── GetOrderUseCase.java
+│   │   │   │   │   │   │   ├── execute(GetOrderRequest): OrderResponse
+│   │   │   │   │   │   │   └── execute(OrderId): Order
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── PayOrderUseCase.java
+│   │   │   │   │   │   └── CancelOrderUseCase.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 customer/               # 客户用例
+│   │   │   │   │   │   ├── RegisterCustomerUseCase.java
+│   │   │   │   │   │   ├── GetCustomerUseCase.java
+│   │   │   │   │   │   └── UpdateCustomerUseCase.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 payment/                # 支付用例
+│   │   │   │   │       └── ProcessPaymentUseCase.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 ports/                    # 端口(接口)
+│   │   │   │   │   ├── 📁 input/                  # 输入端口
+│   │   │   │   │   │   ├── InputPort.java         # 标记接口
+│   │   │   │   │   │   │   └── execute(): Response
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── OrderInputPort.java
+│   │   │   │   │   │   ├── CustomerInputPort.java
+│   │   │   │   │   │   └── PaymentInputPort.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 output/                 # 输出端口
+│   │   │   │   │   │   ├── OutputPort.java        # 标记接口
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── OrderOutputPort.java
+│   │   │   │   │   │   ├── CustomerOutputPort.java
+│   │   │   │   │   │   ├── ProductOutputPort.java
+│   │   │   │   │   │   ├── PaymentOutputPort.java
+│   │   │   │   │   │   └── NotificationOutputPort.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 gateways/                # 网关接口
+│   │   │   │   │       ├── IdGenerator.java
+│   │   │   │   │       ├── DateTimeGateway.java
+│   │   │   │   │       └── CryptoGateway.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 dto/                      # 数据传输对象
+│   │   │   │   │   ├── 📁 request/              # 请求DTO
+│   │   │   │   │   │   ├── CreateOrderRequest.java
+│   │   │   │   │   │   │   ├── customerName: String
+│   │   │   │   │   │   │   ├── items: List<OrderItemRequest>
+│   │   │   │   │   │   │   └── shippingAddress: String
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── PayOrderRequest.java
+│   │   │   │   │   │   ├── GetOrderRequest.java
+│   │   │   │   │   │   └── RegisterCustomerRequest.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 response/             # 响应DTO
+│   │   │   │   │   │   ├── CreateOrderResponse.java
+│   │   │   │   │   │   │   ├── orderId: String
+│   │   │   │   │   │   │   └── status: String
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── OrderResponse.java
+│   │   │   │   │   │   ├── CustomerResponse.java
+│   │   │   │   │   │   └── ApiResponse.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 internal/             # 内部DTO
+│   │   │   │   │       ├── OrderDTO.java
+│   │   │   │   │       └── CustomerDTO.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 service/                  # 应用服务(协调用例)
+│   │   │   │   │   ├── OrderApplicationService.java
+│   │   │   │   │   │   └── createOrder(CreateOrderRequest): OrderDTO
+│   │   │   │   │   │
+│   │   │   │   │   └── CustomerApplicationService.java
+│   │   │   │   │
+│   │   │   │   └── 📁 exception/                # 应用层异常
+│   │   │   │       ├── ApplicationException.java
+│   │   │   │       ├── UseCaseException.java
+│   │   │   │       └── ValidationException.java
+│   │   │   │
+│   │   │   ├── 📁 infrastructure/               # 基础设施层(最外层)
+│   │   │   │   ├── 📁 persistence/              # 持久化实现
+│   │   │   │   │   ├── 📁 repository/           # 仓储实现
+│   │   │   │   │   │   ├── OrderRepositoryImpl.java
+│   │   │   │   │   │   │   ├── @Repository
+│   │   │   │   │   │   │   └── implements OrderOutputPort
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── CustomerRepositoryImpl.java
+│   │   │   │   │   │   └── ProductRepositoryImpl.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 mapper/               # 数据映射器
+│   │   │   │   │   │   ├── OrderMapper.java       # MyBatis Mapper接口
+│   │   │   │   │   │   ├── OrderDataMapper.java  # DO<->Entity转换
+│   │   │   │   │   │   └── CustomerMapper.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 entity/               # 持久化实体
+│   │   │   │   │       ├── OrderEntity.java
+│   │   │   │   │       │   ├── @Entity
+│   │   │   │   │       │   ├── @Table("orders")
+│   │   │   │   │       │   ├── toDomain(): Order
+│   │   │   │   │       │   └── toEntity(Order): OrderEntity
+│   │   │   │   │       │
+│   │   │   │   │       ├── CustomerEntity.java
+│   │   │   │   │       └── ProductEntity.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 web/                      # Web层实现
+│   │   │   │   │   ├── 📁 controller/           # 控制器
+│   │   │   │   │   │   ├── OrderController.java
+│   │   │   │   │   │   │   ├── @RestController
+│   │   │   │   │   │   │   ├── @RequestMapping("/api/orders")
+│   │   │   │   │   │   │   └── createOrder(@RequestBody): ResponseEntity
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── CustomerController.java
+│   │   │   │   │   │   └── PaymentController.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 dto/                  # Web DTO
+│   │   │   │   │   │   ├── 📁 request/
+│   │   │   │   │   │   │   ├── CreateOrderWebRequest.java
+│   │   │   │   │   │   │   └── PayOrderWebRequest.java
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── 📁 response/
+│   │   │   │   │   │   │   └── OrderWebResponse.java
+│   │   │   │   │   │   │
+│   │   │   │   │   │   └── 📁 assembler/            # DTO装配器
+│   │   │   │   │   │       ├── OrderWebAssembler.java
+│   │   │   │   │   │       └── CustomerWebAssembler.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 filter/               # 过滤器
+│   │   │   │   │   │   ├── AuthenticationFilter.java
+│   │   │   │   │   │   ├── LoggingFilter.java
+│   │   │   │   │   │   └── CorsFilter.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 interceptor/          # 拦截器
+│   │   │   │   │   │   └── PerformanceInterceptor.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 advice/               # 异常处理
+│   │   │   │   │       ├── GlobalExceptionHandler.java
+│   │   │   │   │       └── ErrorResponse.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 external/                 # 外部服务适配器
+│   │   │   │   │   ├── 📁 payment/              # 支付服务
+│   │   │   │   │   │   ├── StripePaymentAdapter.java
+│   │   │   │   │   │   │   ├── @Service
+│   │   │   │   │   │   │   └── implements PaymentOutputPort
+│   │   │   │   │   │   │
+│   │   │   │   │   │   ├── PayPalPaymentAdapter.java
+│   │   │   │   │   │   └── AlipayPaymentAdapter.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 notification/         # 通知服务
+│   │   │   │   │   │   ├── EmailNotificationAdapter.java
+│   │   │   │   │   │   ├── SMSNotificationAdapter.java
+│   │   │   │   │   │   └── PushNotificationAdapter.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 messaging/            # 消息队列
+│   │   │   │   │   │   ├── RabbitMQAdapter.java
+│   │   │   │   │   │   ├── KafkaAdapter.java
+│   │   │   │   │   │   └── EventPublisherAdapter.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 storage/              # 存储服务
+│   │   │   │   │       ├── S3StorageAdapter.java
+│   │   │   │   │       └── LocalStorageAdapter.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 config/                   # 配置类
+│   │   │   │   │   ├── 📁 persistence/          # 持久化配置
+│   │   │   │   │   │   ├── JpaConfig.java
+│   │   │   │   │   │   ├── DataSourceConfig.java
+│   │   │   │   │   │   └── TransactionConfig.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 web/                  # Web配置
+│   │   │   │   │   │   ├── WebConfig.java
+│   │   │   │   │   │   ├── SecurityConfig.java
+│   │   │   │   │   │   └── SwaggerConfig.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 external/             # 外部服务配置
+│   │   │   │   │   │   ├── PaymentConfig.java
+│   │   │   │   │   │   ├── NotificationConfig.java
+│   │   │   │   │   │   └── MessagingConfig.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── UseCaseConfig.java       # 用例配置
+│   │   │   │   │   ├── BeanConfig.java
+│   │   │   │   │   └── ModuleConfig.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 security/                 # 安全实现
+│   │   │   │   │   ├── JwtTokenProvider.java
+│   │   │   │   │   ├── PasswordEncoderImpl.java
+│   │   │   │   │   └── SecurityContextImpl.java
+│   │   │   │   │
+│   │   │   │   └── 📁 logging/                  # 日志实现
+│   │   │   │       ├── LoggingAdapter.java
+│   │   │   │       └── AuditLogger.java
+│   │   │   │
+│   │   │   ├── 📁 interfaces/                   # 接口适配器层(可选分离)
+│   │   │   │   ├── 📁 adapters/                 # 适配器
+│   │   │   │   │   ├── 📁 web/                  # Web适配器
+│   │   │   │   │   │   ├── OrderWebAdapter.java
+│   │   │   │   │   │   └── CustomerWebAdapter.java
+│   │   │   │   │   │
+│   │   │   │   │   ├── 📁 cli/                  # 命令行适配器
+│   │   │   │   │   │   └── CommandLineAdapter.java
+│   │   │   │   │   │
+│   │   │   │   │   └── 📁 message/              # 消息适配器
+│   │   │   │   │       ├── KafkaConsumerAdapter.java
+│   │   │   │   │       └── RabbitMQConsumerAdapter.java
+│   │   │   │   │
+│   │   │   │   └── 📁 presenters/              # 展示器
+│   │   │   │       ├── OrderPresenter.java
+│   │   │   │       └── CustomerPresenter.java
+│   │   │   │
+│   │   │   └── OrderApplication.java           # 应用启动类
+│   │   │       ├── @SpringBootApplication
+│   │   │       ├── main()
+│   │   │       └── configure()
+│   │   │
+│   │   └── 📁 resources/
+│   │       ├── application.yml
+│   │       ├── application-dev.yml
+│   │       ├── application-prod.yml
+│   │       ├── 📁 db/
+│   │       │   ├── migration/
+│   │       │   └── seed/
+│   │       ├── 📁 i18n/
+│   │       │   └── messages.properties
+│   │       ├── 📁 templates/
+│   │       │   └── email/
+│   │       ├── logback-spring.xml
+│   │       └── banner.txt
+│   │
+│   └── 📁 test/
+│       ├── 📁 unit/
+│       │   ├── 📁 domain/
+│       │   │   ├── OrderTest.java
+│       │   │   └── MoneyTest.java
+│       │   ├── 📁 application/
+│       │   │   └── CreateOrderUseCaseTest.java
+│       │   └── 📁 infrastructure/
+│       │       └── OrderRepositoryImplTest.java
+│       │
+│       ├── 📁 integration/
+│       │   └── OrderIntegrationTest.java
+│       │
+│       └── 📁 e2e/
+│           └── ApiE2ETest.java
+│
+├── 📁 docker/
+│   ├── Dockerfile
+│   └── docker-compose.yml
+│
+├── pom.xml
+├── README.md
+└── .gitignore
+```
+
+---
+
+## 🏢 大型微服务工程目录结构
+
+**适用场景**: 大型企业项目,需要高度解耦、可测试性和独立部署
+
+```
+ecommerce-platform/                                  # 电商平台(微服务父工程)
+│
+├── 📁 order-service/                              # 订单服务(独立微服务)
+│   ├── 📁 order-domain/                           # 领域模块(JAR)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/domain/
+│   │   │   ├── 📁 entity/
+│   │   │   │   ├── Order.java                     # 聚合根
+│   │   │   │   ├── OrderItem.java
+│   │   │   │   └── Payment.java
+│   │   │   │
+│   │   │   ├── 📁 valueobject/
+│   │   │   │   ├── OrderId.java
+│   │   │   │   ├── Money.java
+│   │   │   │   └── OrderStatus.java
+│   │   │   │
+│   │   │   ├── 📁 service/
+│   │   │   │   └── OrderDomainService.java
+│   │   │   │
+│   │   │   ├── 📁 repository/           # 仓储接口
+│   │   │   │   ├── OrderRepository.java
+│   │   │   │   └── CustomerRepository.java
+│   │   │   │
+│   │   │   ├── 📁 event/
+│   │   │   │   ├── OrderCreatedEvent.java
+│   │   │   │   └── OrderPaidEvent.java
+│   │   │   │
+│   │   │   └── 📁 exception/
+│   │   │       └── DomainException.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-application/                      # 应用模块(JAR)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/application/
+│   │   │   ├── 📁 usecase/
+│   │   │   │   ├── 📁 order/
+│   │   │   │   │   ├── CreateOrderUseCase.java
+│   │   │   │   │   ├── GetOrderUseCase.java
+│   │   │   │   │   ├── PayOrderUseCase.java
+│   │   │   │   │   └── CancelOrderUseCase.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 customer/
+│   │   │   │   │   └── GetCustomerUseCase.java
+│   │   │   │   │
+│   │   │   │   └── 📁 payment/
+│   │   │   │       └── ProcessPaymentUseCase.java
+│   │   │   │
+│   │   │   ├── 📁 ports/
+│   │   │   │   ├── 📁 input/
+│   │   │   │   │   ├── OrderInputPort.java
+│   │   │   │   │   └── CustomerInputPort.java
+│   │   │   │   │
+│   │   │   │   └── 📁 output/
+│   │   │   │       ├── OrderOutputPort.java
+│   │   │   │       ├── CustomerOutputPort.java
+│   │   │   │       └── PaymentOutputPort.java
+│   │   │   │       │
+│   │   │   ├── 📁 dto/
+│   │   │   │   ├── 📁 request/
+│   │   │   │   │   ├── CreateOrderRequest.java
+│   │   │   │   │   └── GetOrderRequest.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 response/
+│   │   │   │   │   ├── OrderResponse.java
+│   │   │   │   │   └── CustomerResponse.java
+│   │   │   │   │
+│   │   │   │   └── 📁 internal/
+│   │   │   │       └── OrderDTO.java
+│   │   │   │
+│   │   │   └── 📁 service/
+│   │   │       └── OrderApplicationService.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-infrastructure/                   # 基础设施模块(JAR)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/infrastructure/
+│   │   │   ├── 📁 persistence/
+│   │   │   │   ├── 📁 repository/
+│   │   │   │   │   ├── OrderRepositoryImpl.java    # 实现OrderOutputPort
+│   │   │   │   │   └── CustomerRepositoryImpl.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 mapper/
+│   │   │   │   │   ├── OrderMapper.java
+│   │   │   │   │   └── OrderDataMapper.java
+│   │   │   │   │
+│   │   │   │   └── 📁 entity/
+│   │   │   │       └── OrderEntity.java
+│   │   │   │
+│   │   │   ├── 📁 web/
+│   │   │   │   ├── 📁 controller/
+│   │   │   │   │   ├── OrderController.java
+│   │   │   │   │   └── CustomerController.java
+│   │   │   │   │
+│   │   │   │   └── 📁 dto/
+│   │   │   │       ├── CreateOrderWebRequest.java
+│   │   │   │       └── OrderWebResponse.java
+│   │   │   │
+│   │   │   ├── 📁 external/
+│   │   │   │   ├── 📁 payment/
+│   │   │   │   │   ├── StripePaymentAdapter.java  # 实现PaymentOutputPort
+│   │   │   │   │   └── PayPalPaymentAdapter.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 messaging/
+│   │   │   │   │   ├── KafkaEventPublisher.java   # 实现EventPublisherOutputPort
+│   │   │   │   │   └── RabbitMQEventConsumer.java
+│   │   │   │   │
+│   │   │   │   └── 📁 notification/
+│   │   │   │       └── EmailNotificationAdapter.java
+│   │   │   │
+│   │   │   └── 📁 config/
+│   │   │       ├── DatabaseConfig.java
+│   │   │       ├── WebConfig.java
+│   │   │       └── SecurityConfig.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-interfaces/                       # 接口适配器模块(JAR)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/interfaces/
+│   │   │   ├── 📁 adapters/
+│   │   │   │   ├── 📁 web/
+│   │   │   │   │   └── OrderWebAdapter.java
+│   │   │   │   │
+│   │   │   │   ├── 📁 cli/
+│   │   │   │   │   └── CommandLineAdapter.java
+│   │   │   │   │
+│   │   │   │   └── 📁 message/
+│   │   │   │       └── KafkaConsumerAdapter.java
+│   │   │   │
+│   │   │   └── 📁 presenters/
+│   │   │       └── OrderPresenter.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── 📁 order-start/                             # 启动模块(可执行JAR)
+│   │   ├── 📁 src/main/java/io/ddd4j/order/
+│   │   │   └── OrderApplication.java
+│   │   │
+│   │   ├── 📁 src/main/resources/
+│   │   │   ├── application.yml
+│   │   │   └── 📁 mapper/
+│   │   │
+│   │   └── pom.xml
+│   │
+│   └── pom.xml                                     # 订单服务父POM
+│
+├── 📁 customer-service/                           # 客户服务(独立微服务)
+│   ├── 📁 customer-domain/
+│   │   └── 📁 src/main/java/io/ddd4j/customer/domain/
+│   │       ├── 📁 entity/
+│   │       │   └── Customer.java
+│   │       └── 📁 valueobject/
+│   │           └── Email.java
+│   │
+│   ├── 📁 customer-application/
+│   │   └── 📁 src/main/java/io/ddd4j/customer/application/
+│   │       └── 📁 usecase/
+│   │           └── RegisterCustomerUseCase.java
+│   │
+│   ├── 📁 customer-infrastructure/
+│   │   └── 📁 src/main/java/io/ddd4j/customer/infrastructure/
+│   │       └── 📁 persistence/
+│   │           └── CustomerRepositoryImpl.java
+│   │
+│   ├── 📁 customer-interfaces/
+│   │   └── 📁 src/main/java/io/ddd4j/customer/interfaces/
+│   │       └── 📁 adapters/
+│   │           └── web/
+│   │               └── CustomerWebAdapter.java
+│   │
+│   └── 📁 customer-start/
+│       └── 📁 src/main/java/io/ddd4j/customer/
+│           └── CustomerApplication.java
+│
+├── 📁 payment-service/                            # 支付服务(独立微服务)
+│   ├── 📁 payment-domain/
+│   ├── 📁 payment-application/
+│   ├── 📁 payment-infrastructure/
+│   ├── 📁 payment-interfaces/
+│   └── 📁 payment-start/
+│
+├── 📁 product-service/                            # 产品服务(独立微服务)
+│   ├── 📁 product-domain/
+│   ├── 📁 product-application/
+│   ├── 📁 product-infrastructure/
+│   ├── 📁 product-interfaces/
+│   └── 📁 product-start/
+│
+├── 📁 shared-kernel/                              # 共享内核
+│   ├── 📁 shared-domain/                          # 共享领域模块
+│   │   └── 📁 src/main/java/io/ddd4j/shared/domain/
+│   │       ├── 📁 entity/
+│   │       │   └── BaseEntity.java
+│   │       └── 📁 valueobject/
+│   │           ├── Money.java
+│   │           └── Email.java
+│   │
+│   ├── 📁 shared-application/                    # 共享应用模块
+│   │   └── 📁 src/main/java/io/ddd4j/shared/application/
+│   │       └── dto/
+│   │           └── BaseDTO.java
+│   │
+│   └── pom.xml
+│
+├── 📁 gateway/                                    # API网关
+│   └── 📁 src/main/java/io/ddd4j/gateway/
+│       ├── GatewayApplication.java
+│       └── 📁 filter/
+│           ├── AuthFilter.java
+│           └── RateLimitFilter.java
+│
+├── 📁 docker/
+│   ├── docker-compose.yml
+│   └── 📁 docker/
+│       ├── order-service/
+│       ├── customer-service/
+│       └── gateway/
+│
+├── 📁 k8s/
+│   ├── 📁 order-service/
+│   │   ├── deployment.yaml
+│   │   └── service.yaml
+│   │
+│   ├── 📁 customer-service/
+│   └── 📁 gateway/
+│
+├── pom.xml
+├── README.md
+└── .gitignore
+```
+
+---
+
+## 🏗 架构原则与依赖关系
+
+### 整洁架构同心圆
+
+```
+        ┌─────────────────────────────────────┐
+        │       Interface Adapters            │  ← 最外层
+        │   (Controllers, Presenters,        │
+        │    Gateways, HTTP, DB, UI, etc)   │
+        └─────────────────────────────────────┘
+                        ↑
+        ┌─────────────────────────────────────┐
+        │       Use Cases / Application       │
+        │   (Business Use Cases, Application  │
+        │         Services, Input Port)       │
+        └─────────────────────────────────────┘
+                        ↑
+        ┌─────────────────────────────────────┐
+        │      Entities / Business Rules     │  ← 最内层
+        │ (Enterprise Business Rules,         │
+        │   Core Domain Models, Entities)    │
+        └─────────────────────────────────────┘
+```
+
+### 依赖规则
+
+```
+Interface Adapters → Use Cases → Entities
+```
+
+- **Entities(最内层)**:核心业务逻辑,无任何外部依赖
+- **Use Cases(应用层)**:依赖Entities,定义输出端口接口
+- **Interface Adapters(最外层)**:实现Use Cases定义的端口,处理技术细节
+
+---
+
+## 🎯 整洁架构核心概念
+
+### 1. 实体(Entities)
+
+企业级业务规则,最内层,完全独立:
+
+```java
+// domain/entity/Order.java
+public class Order {
+
+    private final OrderId id;
+    private CustomerId customerId;
+    private List<OrderItem> items;
+    private OrderStatus status;
+    private Money total;
+
+    public Order(OrderId id, CustomerId customerId, List<OrderItem> items) {
+        this.id = id;
+        this.customerId = customerId;
+        this.items = new ArrayList<>(items);
+        this.status = OrderStatus.PENDING;
+        this.total = calculateTotal();
+        validate();
+    }
+
+    public void place() {
+        if (status != OrderStatus.PENDING) {
+            throw new BusinessRuleException("Order can only be placed from pending status");
+        }
+        this.status = OrderStatus.CONFIRMED;
+    }
+
+    public void pay(Money amount) {
+        if (status != OrderStatus.CONFIRMED) {
+            throw new BusinessRuleException("Order must be confirmed before payment");
+        }
+        if (!total.equals(amount)) {
+            throw new BusinessRuleException("Payment amount does not match order total");
+        }
+        this.status = OrderStatus.PAID;
+    }
+
+    public void cancel() {
+        if (status == OrderStatus.SHIPPED || status == OrderStatus.DELIVERED) {
+            throw new BusinessRuleException("Cannot cancel shipped or delivered order");
+        }
+        this.status = OrderStatus.CANCELLED;
+    }
+
+    private Money calculateTotal() {
+        return items.stream()
+            .map(item -> item.getPrice().multiply(item.getQuantity()))
+            .reduce(Money.ZERO, Money::add);
+    }
+
+    private void validate() {
+        if (customerId == null) {
+            throw new ValidationException("Customer ID is required");
+        }
+        if (items == null || items.isEmpty()) {
+            throw new ValidationException("Order must have at least one item");
+        }
+    }
+}
+```
+
+### 2. 用例(Use Cases)
+
+应用特定业务规则,协调Entities:
+
+```java
+// application/usecase/order/CreateOrderUseCase.java
+@Component
+public class CreateOrderUseCase {
+
+    private final OrderOutputPort orderOutputPort;
+    private final CustomerOutputPort customerOutputPort;
+    private final ProductOutputPort productOutputPort;
+
+    public CreateOrderResponse execute(CreateOrderRequest request) {
+        // 1. 验证客户
+        Customer customer = customerOutputPort.findById(request.getCustomerId())
+            .orElseThrow(() -> new CustomerNotFoundException(request.getCustomerId()));
+
+        // 2. 获取产品
+        List<Product> products = productOutputPort.findByIds(request.getProductIds());
+
+        // 3. 创建订单实体
+        Order order = new Order(
+            OrderId.generate(),
+            customer.getId(),
+            createOrderItems(request.getItems())
+        );
+
+        // 4. 保存订单
+        orderOutputPort.save(order);
+
+        // 5. 返回结果
+        return new CreateOrderResponse(
+            order.getId().getValue(),
+            order.getStatus().name()
+        );
+    }
+}
+```
+
+### 3. 输出端口(Output Ports)
+
+应用层定义的接口,由外层实现:
+
+```java
+// application/ports/output/OrderOutputPort.java
+public interface OrderOutputPort {
+    Order save(Order order);
+    Optional<Order> findById(OrderId id);
+    List<Order> findByCustomer(CustomerId customerId);
+}
+
+// application/ports/output/CustomerOutputPort.java
+public interface CustomerOutputPort {
+    Optional<Customer> findById(CustomerId id);
+    boolean exists(CustomerId id);
+}
+
+// application/ports/output/PaymentOutputPort.java
+public interface PaymentOutputPort {
+    PaymentResult processPayment(PaymentInfo paymentInfo);
+}
+```
+
+### 4. 适配器实现
+
+最外层,实现端口接口:
+
+```java
+// infrastructure/persistence/OrderRepositoryImpl.java
+@Repository
+public class OrderRepositoryImpl implements OrderOutputPort {
+
+    private final OrderMapper orderMapper;
+
+    @Override
+    public Order save(Order order) {
+        OrderEntity entity = toEntity(order);
+        orderMapper.insert(entity);
+        return toDomain(entity);
+    }
+
+    @Override
+    public Optional<Order> findById(OrderId id) {
+        OrderEntity entity = orderMapper.selectById(id.getValue());
+        return Optional.ofNullable(toDomain(entity));
+    }
+}
+
+// infrastructure/external/StripePaymentAdapter.java
+@Service
+public class StripePaymentAdapter implements PaymentOutputPort {
+
+    private final StripeClient stripeClient;
+
+    @Override
+    public PaymentResult processPayment(PaymentInfo paymentInfo) {
+        PaymentIntent intent = stripeClient.createPaymentIntent(
+            paymentInfo.getAmount().getValue(),
+            paymentInfo.getCurrency()
+        );
+        return new PaymentResult(intent.getId(), intent.getStatus());
+    }
+}
+
+// infrastructure/web/OrderController.java
+@RestController
+@RequestMapping("/api/orders")
+public class OrderController {
+
+    private final CreateOrderUseCase createOrderUseCase;
+    private final GetOrderUseCase getOrderUseCase;
+
+    @PostMapping
+    public ResponseEntity<CreateOrderWebResponse> createOrder(
+        @RequestBody CreateOrderWebRequest request
+    ) {
+        CreateOrderRequest useCaseRequest = toUseCaseRequest(request);
+        CreateOrderResponse response = createOrderUseCase.execute(useCaseRequest);
+        return ResponseEntity.ok(toWebResponse(response));
+    }
+}
+```
+
+### 5. 依赖注入配置
+
+```java
+// infrastructure/config/UseCaseConfig.java
+@Configuration
+public class UseCaseConfig {
+
+    // Output Port实现
+    @Bean
+    public OrderOutputPort orderOutputPort(OrderMapper orderMapper) {
+        return new OrderRepositoryImpl(orderMapper);
+    }
+
+    @Bean
+    public CustomerOutputPort customerOutputPort(CustomerMapper customerMapper) {
+        return new CustomerRepositoryImpl(customerMapper);
+    }
+
+    @Bean
+    public PaymentOutputPort paymentOutputPort(StripeClient stripeClient) {
+        return new StripePaymentAdapter(stripeClient);
+    }
+
+    // Use Case Bean
+    @Bean
+    public CreateOrderUseCase createOrderUseCase(
+        OrderOutputPort orderOutputPort,
+        CustomerOutputPort customerOutputPort,
+        ProductOutputPort productOutputPort
+    ) {
+        return new CreateOrderUseCase(
+            orderOutputPort,
+            customerOutputPort,
+            productOutputPort
+        );
+    }
+}
+```
+
+---
+
+## 📚 权威参考
+
+### 整洁架构创始人
+- **Robert C. Martin (Uncle Bob)** - 整洁架构创始人
+
+### 核心原则
+
+1. **依赖规则**:源代码依赖关系只能指向内部,内层不知道外层的任何信息
+2. **实体独立**:最内层的实体不依赖任何框架、数据库、UI等外部技术
+3. **用例封装**:应用特定业务规则,协调实体完成业务目标
+4. **适配器隔离**:最外层负责数据转换和技术实现
+
+### 与其他架构的关系
+
+| 架构 | 核心理念 | 依赖方向 |
+|------|---------|---------|
+| 整洁架构 | 同心圆层次结构 | Adapter → Use Case → Entity |
+| 六边形架构 | 端口和适配器 | Adapter → Port ← Application |
+| DDD分层 | 领域驱动设计 | Interface → Application → Domain ← Infrastructure |
+
+---
+
+## 💡 选择建议
+
+### 选择整洁架构的场景:
+1. 需要高度的可测试性
+2. 业务逻辑复杂,需要独立演进
+3. 技术栈可能频繁更换
+4. 需要清晰的架构边界
+
+### 不选择整洁架构的场景:
+1. 简单CRUD应用
+2. 团队对架构理解不足
+3. 快速原型开发
+
+---
+
+## 🚀 快速开始
+
+```bash
+# 创建整洁架构项目
+mvn archetype:generate \
+  -DarchetypeGroupId=io.ddd4j.boot \
+  -DarchetypeArtifactId=clean-archetype \
+  -DarchetypeVersion=3.3.x
+```

+ 1336 - 0
skills/ddd4j-project-builder/docs/4、COLA V5 架构详细目录结构参考.md

@@ -0,0 +1,1336 @@
+# COLA V5 架构详细目录结构参考
+
+## 目录
+
+- [1. 单体工程目录结构](#1-单体工程目录结构)
+- [2. 大型微服务工程目录结构](#2-大型微服务工程目录结构)
+- [3. COLA V5 架构原则与依赖关系](#3-cola-v5-架构原则与依赖关系)
+- [4. COLA V5 核心概念](#4-cola-v5-核心概念)
+
+---
+
+## 1. 单体工程目录结构
+
+**适用场景**:中小型应用,单个业务领域,团队规模 5-15 人
+
+以一个订单管理系统为例:
+
+```
+order-management-system/
+├── pom.xml
+├── README.md
+│
+├── order-start/                          # 启动模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/
+│           └── OrderApplication.java     # @SpringBootApplication
+│
+├── order-adapter/                        # 适配器层模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/adapter/
+│           ├── web/                      # Web适配器
+│           │   ├── OrderController.java
+│           │   ├── CustomerController.java
+│           │   └── ProductController.java
+│           │
+│           ├── rpc/                      # RPC适配器
+│           │   ├── OrderRpcProvider.java
+│           │   └── PaymentRpcConsumer.java
+│           │
+│           ├── job/                      # 定时任务适配器
+│           │   └── OrderCleanupScheduler.java
+│           │
+│           └── message/                  # 消息适配器
+│               ├── OrderEventProducer.java
+│               └── PaymentEventConsumer.java
+│
+├── order-app/                            # 应用层模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/app/
+│           ├── executor/                 # 执行器(CQRS)
+│           │   ├── command/
+│           │   │   ├── order/
+│           │   │   │   ├── OrderCreateCmdExe.java
+│           │   │   │   ├── OrderPayCmdExe.java
+│           │   │   │   └── OrderCancelCmdExe.java
+│           │   │   └── customer/
+│           │   │       └── CustomerCreateCmdExe.java
+│           │   │
+│           │   └── query/
+│           │       ├── order/
+│           │       │   ├── OrderGetQryExe.java
+│           │       │   └── OrderListQryExe.java
+│           │       └── customer/
+│           │           └── CustomerGetQryExe.java
+│           │
+│           ├── model/                    # 应用模型
+│           │   ├── command/
+│           │   │   ├── OrderCreateCmd.java
+│           │   │   └── OrderPayCmd.java
+│           │   ├── query/
+│           │   │   ├── OrderGetQry.java
+│           │   │   └── OrderListQry.java
+│           │   └── event/
+│           │       └── OrderCreatedEvent.java
+│           │
+│           ├── service/                  # 应用服务
+│           │   └── OrderAppService.java
+│           │
+│           └── extension/                # 扩展点
+│               ├── OrderPriceCalculateExtPt.java
+│               └── impl/
+│                   ├── NormalPriceCalculateExt.java
+│                   └── VipPriceCalculateExt.java
+│
+├── order-domain/                         # 领域层模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/domain/
+│           ├── model/                    # 领域模型
+│           │   ├── entity/
+│           │   │   ├── Order.java
+│           │   │   ├── OrderItem.java
+│           │   │   └── Customer.java
+│           │   ├── vo/
+│           │   │   ├── Money.java
+│           │   │   ├── Address.java
+│           │   │   └── OrderStatus.java
+│           │   └── event/
+│           │       ├── OrderPlacedEvent.java
+│           │       └── OrderPaidEvent.java
+│           │
+│           ├── service/                  # 领域服务
+│           │   ├── OrderDomainService.java
+│           │   └── PricingDomainService.java
+│           │
+│           ├── ability/                  # 领域能力
+│           │   └── OrderAbility.java
+│           │
+│           ├── gateway/                  # 领域网关接口
+│           │   ├── OrderGateway.java
+│           │   ├── CustomerGateway.java
+│           │   ├── ProductGateway.java
+│           │   └── PaymentGateway.java
+│           │
+│           └── repository/               # 仓储接口
+│               ├── OrderRepository.java
+│               ├── CustomerRepository.java
+│               └── ProductRepository.java
+│
+├── order-infrastructure/                 # 基础设施层模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/infrastructure/
+│           ├── config/                   # 配置
+│           │   ├── DatabaseConfig.java
+│           │   ├── RedisConfig.java
+│           │   └── MQConfig.java
+│           │
+│           ├── persistence/              # 持久化实现
+│           │   ├── OrderRepositoryImpl.java
+│           │   ├── CustomerRepositoryImpl.java
+│           │   ├── mapper/
+│           │   │   ├── OrderMapper.java
+│           │   │   └── CustomerMapper.java
+│           │   └── entity/
+│           │       ├── OrderDO.java
+│           │       └── CustomerDO.java
+│           │
+│           ├── gatewayimpl/              # 网关实现
+│           │   ├── OrderGatewayImpl.java
+│           │   ├── PaymentGatewayImpl.java
+│           │   └── external/
+│           │       └── AlipayGatewayImpl.java
+│           │
+│           ├── external/                 # 外部服务客户端
+│           │   └── AlipayClient.java
+│           │
+│           └── component/                # 基础设施组件
+│               ├── lock/
+│               │   └── DistributedLock.java
+│               └── rateLimiter/
+│                   └── RateLimiter.java
+│
+├── order-common/                         # 通用模块
+│   ├── pom.xml
+│   └── src/main/java/
+│       └── com/example/order/common/
+│           ├── constant/
+│           │   └── OrderConstant.java
+│           ├── exception/
+│           │   ├── OrderException.java
+│           │   └── ErrorCode.java
+│           ├── util/
+│           │   └── BeanUtil.java
+│           └── annotation/
+│               └── ExtensionPoint.java
+│
+└── order-api/                            # API客户端模块(可选)
+    ├── pom.xml
+    └── src/main/java/
+        └── com/example/order/api/
+            ├── OrderApiClient.java
+            └── dto/
+                └── OrderDTO.java
+```
+
+**单体工程 Maven 模块依赖关系**:
+
+```
+order-start
+    ↓ depends on
+order-adapter → order-app → order-domain ← order-infrastructure
+    ↓                                                    ↓
+order-common ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ┘
+    ↓ (optional)
+order-api
+```
+
+**pom.xml 示例**(父 POM):
+
+```xml
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.example</groupId>
+    <artifactId>order-management-system</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>order-start</module>
+        <module>order-adapter</module>
+        <module>order-app</module>
+        <module>order-domain</module>
+        <module>order-infrastructure</module>
+        <module>order-common</module>
+        <module>order-api</module>
+    </modules>
+
+    <properties>
+        <cola.framework.version>5.0.0</cola.framework.version>
+        <spring.boot.version>3.3.13</spring.boot.version>
+    </properties>
+</project>
+```
+
+---
+
+## 2. 大型微服务工程目录结构
+
+**适用场景**:大型电商平台,多个业务域,团队规模 50+ 人
+
+```
+ecommerce-platform/                      # 电商平台根目录
+├── pom.xml                              # 父 POM
+├── README.md
+├── .gitignore
+├── docker-compose.yml
+│
+├── platform-common/                     # 平台通用模块
+│   ├── pom.xml
+│   └── src/main/java/com/ecommerce/common/
+│       ├── constant/
+│       ├── exception/
+│       ├── util/
+│       └── annotation/
+│
+├── platform-starter/                    # COLA 组件 Starter
+│   ├── pom.xml
+│   └── src/main/java/com/ecommerce/starter/
+│       ├── ExtensionPointAutoConfiguration.java
+│       └── AbilityAutoConfiguration.java
+│
+│
+├── services/                            # 微服务目录
+│   │
+│   ├── user-service/                    # 用户服务
+│   │   ├── user-service-start/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/
+│   │   │           └── UserApplication.java
+│   │   │
+│   │   ├── user-service-adapter/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/adapter/
+│   │   │           ├── web/
+│   │   │           │   ├── UserController.java
+│   │   │           │   └── AuthController.java
+│   │   │           ├── rpc/
+│   │   │           │   └── UserRpcProvider.java
+│   │   │           └── message/
+│   │   │               └── UserEventProducer.java
+│   │   │
+│   │   ├── user-service-app/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/app/
+│   │   │           ├── executor/
+│   │   │           │   ├── command/
+│   │   │           │   │   ├── UserRegisterCmdExe.java
+│   │   │           │   │   └── UserLoginCmdExe.java
+│   │   │           │   └── query/
+│   │   │           │       └── UserGetQryExe.java
+│   │   │           ├── model/
+│   │   │           │   ├── command/
+│   │   │           │   └── query/
+│   │   │           └── extension/
+│   │   │               └── UserValidationExtPt.java
+│   │   │
+│   │   ├── user-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── User.java
+│   │   │           │   │   └── UserProfile.java
+│   │   │           │   ├── vo/
+│   │   │           │   │   ├── UserId.java
+│   │   │           │   │   ├── Email.java
+│   │   │           │   │   └── PhoneNumber.java
+│   │   │           │   └── event/
+│   │   │           │       └── UserRegisteredEvent.java
+│   │   │           ├── service/
+│   │   │           │   └── UserDomainService.java
+│   │   │           ├── ability/
+│   │   │           │   └── UserAbility.java
+│   │   │           ├── gateway/
+│   │   │           │   ├── UserGateway.java
+│   │   │           │   └── SmsGateway.java
+│   │   │           └── repository/
+│   │   │               └── UserRepository.java
+│   │   │
+│   │   ├── user-service-infrastructure/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/infrastructure/
+│   │   │           ├── config/
+│   │   │           ├── persistence/
+│   │   │           │   ├── UserRepositoryImpl.java
+│   │   │           │   └── mapper/
+│   │   │           │       └── UserMapper.java
+│   │   │           ├── gatewayimpl/
+│   │   │           │   └── SmsGatewayImpl.java
+│   │   │           └── external/
+│   │   │               └── SmsClient.java
+│   │   │
+│   │   ├── user-service-api/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/user/api/
+│   │   │           ├── UserService.java
+│   │   │           └── dto/
+│   │   │               └── UserDTO.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── product-service/                 # 商品服务
+│   │   ├── product-service-start/
+│   │   ├── product-service-adapter/
+│   │   ├── product-service-app/
+│   │   ├── product-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/product/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── Product.java
+│   │   │           │   │   ├── Category.java
+│   │   │           │   │   └── SKU.java
+│   │   │           │   ├── vo/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   └── Quantity.java
+│   │   │           │   └── event/
+│   │   │           │       └── ProductCreatedEvent.java
+│   │   │           ├── service/
+│   │   │           │   ├── ProductDomainService.java
+│   │   │           │   └── InventoryDomainService.java
+│   │   │           ├── ability/
+│   │   │           │   └── ProductAbility.java
+│   │   │           ├── gateway/
+│   │   │           │   ├── ProductGateway.java
+│   │   │           │   └── InventoryGateway.java
+│   │   │           └── repository/
+│   │   │               └── ProductRepository.java
+│   │   ├── product-service-infrastructure/
+│   │   ├── product-service-api/
+│   │   └── pom.xml
+│   │
+│   ├── order-service/                   # 订单服务
+│   │   ├── order-service-start/
+│   │   ├── order-service-adapter/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/adapter/
+│   │   │           ├── web/
+│   │   │           │   ├── OrderController.java
+│   │   │           │   └── CartController.java
+│   │   │           ├── rpc/
+│   │   │           │   ├── OrderRpcProvider.java
+│   │   │           │   └── ProductRpcConsumer.java
+│   │   │           ├── job/
+│   │   │           │   └── OrderExpireScheduler.java
+│   │   │           └── message/
+│   │   │               ├── OrderEventProducer.java
+│   │   │               └── PaymentEventConsumer.java
+│   │   │
+│   │   ├── order-service-app/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/app/
+│   │   │           ├── executor/
+│   │   │           │   ├── command/
+│   │   │           │   │   ├── order/
+│   │   │           │   │   │   ├── OrderCreateCmdExe.java
+│   │   │           │   │   │   ├── OrderPayCmdExe.java
+│   │   │           │   │   │   └── OrderCancelCmdExe.java
+│   │   │           │   │   └── cart/
+│   │   │           │   │       └── CartAddCmdExe.java
+│   │   │           │   ├── query/
+│   │   │           │   │   ├── order/
+│   │   │           │   │   │   ├── OrderGetQryExe.java
+│   │   │           │   │   │   └── OrderListQryExe.java
+│   │   │           │   │   └── cart/
+│   │   │           │   │       └── CartGetQryExe.java
+│   │   │           │   └── event/
+│   │   │           │       └── OrderPaidEventExe.java
+│   │   │           ├── model/
+│   │   │           │   ├── command/
+│   │   │           │   ├── query/
+│   │   │           │   ├── event/
+│   │   │           │   └── dto/
+│   │   │           ├── service/
+│   │   │           │   └── OrderAppService.java
+│   │   │           └── extension/
+│   │   │               ├── OrderPriceCalculateExtPt.java
+│   │   │               └── impl/
+│   │   │                   ├── NormalPriceCalculateExt.java
+│   │   │                   ├── VipPriceCalculateExt.java
+│   │   │                   └── PromotionPriceCalculateExt.java
+│   │   │
+│   │   ├── order-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── Order.java
+│   │   │           │   │   ├── OrderItem.java
+│   │   │           │   │   ├── Cart.java
+│   │   │           │   │   └── CartItem.java
+│   │   │           │   ├── aggregate/
+│   │   │           │   │   └── OrderAggregate.java
+│   │   │           │   ├── vo/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   ├── Address.java
+│   │   │           │   │   └── OrderStatus.java
+│   │   │           │   └── event/
+│   │   │           │       ├── OrderCreatedEvent.java
+│   │   │           │       ├── OrderPaidEvent.java
+│   │   │           │       └── OrderCancelledEvent.java
+│   │   │           ├── service/
+│   │   │           │   ├── OrderDomainService.java
+│   │   │           │   └── PricingDomainService.java
+│   │   │           ├── ability/
+│   │   │           │   ├── OrderAbility.java
+│   │   │           │   └── PaymentAbility.java
+│   │   │           ├── gateway/
+│   │   │           │   ├── OrderGateway.java
+│   │   │           │   ├── ProductGateway.java
+│   │   │           │   ├── UserGateway.java
+│   │   │           │   └── PaymentGateway.java
+│   │   │           └── repository/
+│   │   │               └── OrderRepository.java
+│   │   │
+│   │   ├── order-service-infrastructure/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/infrastructure/
+│   │   │           ├── config/
+│   │   │           │   ├── DatabaseConfig.java
+│   │   │           │   ├── RedisConfig.java
+│   │   │           │   ├── KafkaConfig.java
+│   │   │           │   └── DubboConfig.java
+│   │   │           ├── persistence/
+│   │   │           │   ├── OrderRepositoryImpl.java
+│   │   │           │   ├── CartRepositoryImpl.java
+│   │   │           │   └── mapper/
+│   │   │           │       ├── OrderMapper.java
+│   │   │           │       └── CartMapper.java
+│   │   │           ├── gatewayimpl/
+│   │   │           │   ├── ProductGatewayImpl.java
+│   │   │           │   ├── UserGatewayImpl.java
+│   │   │           │   └── PaymentGatewayImpl.java
+│   │   │           └── component/
+│   │   │               ├── lock/
+│   │   │               ├── rateLimiter/
+│   │   │               └── circuitBreaker/
+│   │   │
+│   │   ├── order-service-api/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/order/api/
+│   │   │           ├── OrderService.java
+│   │   │           └── dto/
+│   │   │               └── OrderDTO.java
+│   │   │
+│   │   └── pom.xml
+│   │
+│   ├── payment-service/                 # 支付服务
+│   │   ├── payment-service-start/
+│   │   ├── payment-service-adapter/
+│   │   ├── payment-service-app/
+│   │   ├── payment-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/payment/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── Payment.java
+│   │   │           │   │   └── PaymentChannel.java
+│   │   │           │   ├── vo/
+│   │   │           │   │   ├── Money.java
+│   │   │           │   │   └── PaymentStatus.java
+│   │   │           │   └── event/
+│   │   │           │       └── PaymentCompletedEvent.java
+│   │   │           ├── service/
+│   │   │           │   └── PaymentDomainService.java
+│   │   │           ├── ability/
+│   │   │           │   └── PaymentAbility.java
+│   │   │           ├── gateway/
+│   │   │           │   ├── AlipayGateway.java
+│   │   │           │   └── WechatPayGateway.java
+│   │   │           └── repository/
+│   │   │               └── PaymentRepository.java
+│   │   ├── payment-service-infrastructure/
+│   │   ├── payment-service-api/
+│   │   └── pom.xml
+│   │
+│   ├── inventory-service/               # 库存服务
+│   │   ├── inventory-service-start/
+│   │   ├── inventory-service-adapter/
+│   │   ├── inventory-service-app/
+│   │   ├── inventory-service-domain/
+│   │   │   └── src/main/java/
+│   │   │       └── com/ecommerce/inventory/domain/
+│   │   │           ├── model/
+│   │   │           │   ├── entity/
+│   │   │           │   │   └── Inventory.java
+│   │   │           │   └── event/
+│   │   │           │       └── InventoryDeductedEvent.java
+│   │   │           ├── service/
+│   │   │           │   └── InventoryDomainService.java
+│   │   │           ├── ability/
+│   │   │           │   └── InventoryAbility.java
+│   │   │           ├── gateway/
+│   │   │           │   └── ProductGateway.java
+│   │   │           └── repository/
+│   │   │               └── InventoryRepository.java
+│   │   ├── inventory-service-infrastructure/
+│   │   ├── inventory-service-api/
+│   │   └── pom.xml
+│   │
+│   ├── notification-service/            # 通知服务
+│   │   ├── notification-service-start/
+│   │   ├── notification-service-adapter/
+│   │   ├── notification-service-app/
+│   │   ├── notification-service-domain/
+│   │   ├── notification-service-infrastructure/
+│   │   ├── notification-service-api/
+│   │   └── pom.xml
+│   │
+│   └── search-service/                  # 搜索服务
+│       ├── search-service-start/
+│       ├── search-service-adapter/
+│       ├── search-service-app/
+│       ├── search-service-domain/
+│       ├── search-service-infrastructure/
+│       ├── search-service-api/
+│       └── pom.xml
+│
+│
+├── gateway/                             # 网关服务
+│   ├── gateway-start/
+│   │   └── src/main/java/
+│   │       └── com/ecommerce/gateway/
+│   │           └── GatewayApplication.java
+│   ├── gateway-adapter/
+│   │   └── src/main/java/
+│   │       └── com/ecommerce/gateway/adapter/
+│   │           ├── web/
+│   │           │   └── GatewayController.java
+│   │           └── filter/
+│   │               ├── AuthFilter.java
+│   │               ├── RateLimitFilter.java
+│   │               └── RouteFilter.java
+│   ├── gateway-app/
+│   ├── gateway-infrastructure/
+│   └── pom.xml
+│
+│
+├── shared/                              # 共享服务
+│   │
+│   ├── auth-service/                    # 认证授权服务
+│   │   ├── auth-service-start/
+│   │   ├── auth-service-adapter/
+│   │   ├── auth-service-app/
+│   │   ├── auth-service-domain/
+│   │   ├── auth-service-infrastructure/
+│   │   └── pom.xml
+│   │
+│   └── config-service/                  # 配置中心(可选)
+│   │   ├── config-service-start/
+│   │   └── pom.xml
+│
+│
+├── docs/                                # 文档
+│   ├── architecture/
+│   │   ├── microservices.md
+│   │   └── cola-v5.md
+│   ├── api/
+│   │   ├── user-service.yaml
+│   │   ├── order-service.yaml
+│   │   └── payment-service.yaml
+│   └── deployment/
+│       └── kubernetes/
+│
+├── scripts/                             # 脚本
+│   ├── deploy/
+│   │   ├── deploy-dev.sh
+│   │   └── deploy-prod.sh
+│   └── db/
+│       ├── init-user.sql
+│       ├── init-order.sql
+│       └── init-payment.sql
+│
+└── docker/                              # Docker 配置
+    ├── docker-compose.yml
+    └── kubernetes/
+        ├── user-service-deployment.yaml
+        ├── order-service-deployment.yaml
+        └── ingress.yaml
+```
+
+**微服务架构特点**:
+
+1. **服务独立部署**:每个服务有独立的启动模块和数据库
+2. **服务间通信**:通过 RPC(Dubbo/gRPC)和消息队列(Kafka/RocketMQ)
+3. **共享组件**:`platform-common` 和 `platform-starter` 提供通用能力
+4. **网关统一入口**:`gateway` 服务处理路由、认证、限流
+5. **独立数据库**:每个服务拥有自己的数据库 schema
+
+**微服务依赖关系**(跨服务):
+
+```
+┌─────────────┐      ┌─────────────┐
+│  Frontend   │─────▶│   Gateway   │
+└─────────────┘      └─────────────┘
+                            │
+            ┌───────────────┼───────────────┐
+            ▼               ▼               ▼
+    ┌───────────┐   ┌───────────┐   ┌───────────┐
+    │    User   │   │   Order   │   │  Product  │
+    │  Service  │◀──▶│  Service  │◀──▶│  Service  │
+    └───────────┘   └─────┬─────┘   └───────────┘
+                          │
+                ┌─────────┼─────────┐
+                ▼         ▼         ▼
+          ┌─────────┐ ┌───────┐ ┌─────────┐
+          │ Payment │ │Inventory│ │Notification│
+          │ Service │ │ Service│ │  Service │
+          └─────────┘ └───────┘ └─────────┘
+```
+
+---
+
+## 3. COLA V5 架构原则与依赖关系
+
+### 3.1 CLOA(Clean Object-oriented and Layered Architecture)设计原则
+
+COLA V5 采用"菱形"架构,强调分层和依赖方向:
+
+```
+                   ┌─────────────┐
+                   │   Adapter   │  ← 适配器层(Web、RPC、Job、MQ)
+                   └──────┬──────┘
+                          │
+                   ┌──────▼──────┐
+                   │     App     │  ← 应用层(Executor、Service、Extension)
+                   └──────┬──────┘
+                          │
+        ┌─────────────────┼─────────────────┐
+        │                 │                 │
+ ┌──────▼──────┐   ┌──────▼──────┐   ┌──────▼──────┐
+ │   Domain    │   │  Domain     │   │   Domain    │  ← 领域层(核心)
+ │  (Entity)   │   │ (Ability)   │   │  (Gateway)  │
+ └──────┬──────┘   └──────┬──────┘   └──────┬──────┘
+        │                 │                 ▲
+        │                 │                 │
+        └─────────────────┼─────────────────┘
+                          │
+                   ┌──────▼──────┐
+                   │Infrastructure│ ← 基础设施层(DB、MQ、外部服务)
+                   └─────────────┘
+```
+
+### 3.2 依赖规则(Dependency Rule)
+
+**核心规则**:依赖只能由外向内,内层不依赖外层
+
+```java
+// ✓ 正确:Adapter 依赖 App
+@RestController
+public class OrderController {
+    @Autowired
+    private OrderCreateCmdExe orderCreateCmdExe;  // App层
+}
+
+// ✓ 正确:App 依赖 Domain
+@Component
+public class OrderCreateCmdExe {
+    @Autowired
+    private OrderRepository orderRepository;  // Domain层接口
+}
+
+// ✓ 正确:Infrastructure 实现 Domain 接口
+@Repository
+public class OrderRepositoryImpl implements OrderRepository {  // Domain层接口
+    // Infrastructure层实现
+}
+
+// ✗ 错误:Domain 不能依赖 App
+@Entity
+public class Order {
+    @Autowired
+    private OrderAppService appService;  // 错误!Domain层不能依赖App层
+}
+
+// ✗ 错误:Domain 不能依赖 Infrastructure
+@Entity
+public class Order {
+    @Autowired
+    private OrderMapper orderMapper;  // 错误!Domain层不能依赖Infrastructure
+}
+```
+
+### 3.3 分层职责
+
+| 层级 | 职责 | 典型组件 | 依赖方向 |
+|------|------|----------|----------|
+| **Adapter** | 外部交互适配 | Controller、RPC Provider、Scheduler、Listener | → App |
+| **App** | 用例编排、业务流程 | Executor(Command/Query)、AppService、Extension | → Domain |
+| **Domain** | 核心业务逻辑 | Entity、VO、DomainService、Ability、Gateway接口 | → (只定义接口) |
+| **Infrastructure** | 技术实现 | RepositoryImpl、GatewayImpl、ExternalClient | ← Domain(实现接口) |
+| **Common** | 通用工具 | Util、Constant、Exception、Annotation | → 被所有层依赖 |
+
+### 3.4 CQRS 模式实现
+
+COLA V5 通过 Executor 模式实现 CQRS:
+
+```java
+// 命令(Command)- 修改状态
+@Command
+public class OrderCreateCmd {
+    private String customerId;
+    private List<OrderItemDTO> items;
+    private Address address;
+}
+
+@Component
+public class OrderCreateCmdExe {
+
+    @Autowired
+    private OrderRepository orderRepository;
+
+    public void execute(OrderCreateCmd cmd) {
+        // 1. 创建领域对象
+        Order order = Order.create(cmd.getCustomerId(), cmd.getItems());
+
+        // 2. 调用领域服务
+        order.place();
+
+        // 3. 持久化
+        orderRepository.save(order);
+    }
+}
+
+// 查询(Query)- 读取状态
+@Query
+public class OrderGetQry {
+    private String orderId;
+}
+
+@Component
+public class OrderGetQryExe {
+
+    @Autowired
+    private OrderGateway orderGateway;
+
+    public OrderDTO execute(OrderGetQry qry) {
+        // 直接查询,可以跳过领域模型
+        return orderGateway.getOrderById(qry.getOrderId());
+    }
+}
+```
+
+---
+
+## 4. COLA V5 核心概念
+
+### 4.1 扩展点(Extension Point)
+
+**目的**:实现业务逻辑的可扩展性,避免大量 if-else
+
+```java
+// 1. 定义扩展点接口(位于 app/extension)
+@ExtensionPoint(bizId = "orderPriceCalculate")
+public interface OrderPriceCalculateExtPt {
+
+    /**
+     * 计算订单价格
+     * @param context 价格计算上下文
+     * @return 计算后的价格
+     */
+    Money calculatePrice(PriceCalculateContext context);
+}
+
+// 2. 定义扩展上下文
+@Data
+public class PriceCalculateContext {
+    private Order order;
+    private Customer customer;
+    private String promotionType;
+}
+
+// 3. 实现扩展点(位于 app/extension/impl)
+@Extension(bizId = "normalOrder")  // 普通订单
+public class NormalPriceCalculateExt implements OrderPriceCalculateExtPt {
+    @Override
+    public Money calculatePrice(PriceCalculateContext context) {
+        // 普通价格计算逻辑
+        return context.getOrder().getTotalAmount();
+    }
+}
+
+@Extension(bizId = "vipOrder")  // VIP 订单
+public class VipPriceCalculateExt implements OrderPriceCalculateExtPt {
+    @Override
+    public Money calculatePrice(PriceCalculateContext context) {
+        // VIP 打折逻辑
+        return context.getOrder().getTotalAmount().multiply(0.9);
+    }
+}
+
+@Extension(bizId = "promotionOrder")  // 促销订单
+public class PromotionPriceCalculateExt implements OrderPriceCalculateExtPt {
+    @Override
+    public Money calculatePrice(PriceCalculateContext context) {
+        // 促销价格计算逻辑
+        return context.getOrder().getTotalAmount().multiply(0.8);
+    }
+}
+
+// 4. 使用扩展点
+@Service
+public class OrderAppService {
+
+    @Autowired
+    private ExtensionExecutor extensionExecutor;
+
+    public Money calculatePrice(Order order, Customer customer) {
+        PriceCalculateContext context = new PriceCalculateContext(order, customer);
+
+        // 根据业务场景自动选择对应的扩展实现
+        OrderPriceCalculateExtPt extPt = extensionExecutor.execute(
+            OrderPriceCalculateExtPt.class,
+            customer.getOrderType(),  // bizId
+            context
+        );
+
+        return extPt.calculatePrice(context);
+    }
+}
+```
+
+**扩展点场景示例**:
+
+| 业务场景 | 扩展点实现 |
+|----------|-----------|
+| 不同用户类型注册验证 | UserValidationExtPt(NormalUserValidationExt、VipUserValidationExt) |
+| 不同支付渠道处理 | PaymentProcessExtPt(AlipayProcessExt、WechatPayProcessExt) |
+| 不同物流方式计费 | ShippingFeeCalculateExtPt(ExpressShippingExt、EconomyShippingExt) |
+| 不同订单类型优惠 | DiscountCalculateExtPt(NewCustomerDiscountExt、LoyalCustomerDiscountExt) |
+
+### 4.2 领域能力(Ability)
+
+**目的**:封装跨实体的业务能力
+
+```java
+// 1. 定义领域能力(位于 domain/ability)
+public interface OrderAbility {
+
+    /**
+     * 判断订单是否可以支付
+     */
+    boolean canPay(Order order);
+
+    /**
+     * 判断订单是否可以取消
+     */
+    boolean canCancel(Order order);
+
+    /**
+     * 判断用户是否可以创建订单
+     */
+    boolean canCreateOrder(Customer customer);
+}
+
+// 2. 实现领域能力
+@Component
+public class OrderAbilityImpl implements OrderAbility {
+
+    @Autowired
+    private OrderRepository orderRepository;
+
+    @Autowired
+    private CustomerRepository customerRepository;
+
+    @Override
+    public boolean canPay(Order order) {
+        // 检查订单状态
+        if (order.getStatus() != OrderStatus.PENDING_PAYMENT) {
+            return false;
+        }
+
+        // 检查订单是否过期
+        if (order.isExpired()) {
+            return false;
+        }
+
+        // 检查库存
+        if (!order.hasStock()) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean canCancel(Order order) {
+        // 只有未支付和已支付的订单可以取消
+        return order.getStatus() == OrderStatus.PENDING_PAYMENT
+            || order.getStatus() == OrderStatus.PAID;
+    }
+
+    @Override
+    public boolean canCreateOrder(Customer customer) {
+        // 检查用户状态
+        if (!customer.isActive()) {
+            return false;
+        }
+
+        // 检查用户是否有未支付订单
+        List<Order> unpaidOrders = orderRepository.findUnpaidByCustomer(customer.getId());
+        if (unpaidOrders.size() >= 3) {
+            return false;
+        }
+
+        return true;
+    }
+}
+
+// 3. 在领域服务中使用领域能力
+@Service
+public class OrderDomainService {
+
+    @Autowired
+    private OrderAbility orderAbility;
+
+    public void pay(Order order, Payment payment) {
+        // 使用能力进行业务规则验证
+        if (!orderAbility.canPay(order)) {
+            throw new OrderException("订单当前状态不允许支付");
+        }
+
+        // 执行支付逻辑
+        order.pay(payment);
+    }
+}
+```
+
+### 4.3 领域网关(Gateway)
+
+**目的**:隔离外部依赖,定义领域层需要的外部能力
+
+```java
+// 1. 定义网关接口(位于 domain/gateway)
+public interface PaymentGateway {
+
+    /**
+     * 发起支付
+     */
+    PaymentResult initiate(PaymentRequest request);
+
+    /**
+     * 查询支付状态
+     */
+    PaymentStatus queryStatus(String paymentId);
+}
+
+public interface ProductGateway {
+
+    /**
+     * 获取商品信息
+     */
+    Product getProduct(String productId);
+
+    /**
+     * 锁定库存
+     */
+    void lockInventory(String productId, int quantity);
+}
+
+public interface SmsGateway {
+
+    /**
+     * 发送短信
+     */
+    void sendSms(PhoneNumber phone, String message);
+}
+
+// 2. 在基础设施层实现网关(位于 infrastructure/gatewayimpl)
+@Repository
+public class PaymentGatewayImpl implements PaymentGateway {
+
+    @Autowired
+    private AlipayClient alipayClient;
+
+    @Autowired
+    private WechatPayClient wechatPayClient;
+
+    @Override
+    public PaymentResult initiate(PaymentRequest request) {
+        switch (request.getChannel()) {
+            case ALIPAY:
+                return alipayClient.pay(request);
+            case WECHAT:
+                return wechatPayClient.pay(request);
+            default:
+                throw new UnsupportedPaymentChannelException();
+        }
+    }
+
+    @Override
+    public PaymentStatus queryStatus(String paymentId) {
+        // 查询支付状态
+    }
+}
+
+@Component
+public class ProductGatewayImpl implements ProductGateway {
+
+    @Autowired
+    private ProductServiceClient productServiceClient;  // RPC 客户端
+
+    @Override
+    public Product getProduct(String productId) {
+        return productServiceClient.getProduct(productId);
+    }
+
+    @Override
+    public void lockInventory(String productId, int quantity) {
+        productServiceClient.lockInventory(productId, quantity);
+    }
+}
+
+// 3. 在应用层/领域层使用网关
+@Component
+public class OrderPayCmdExe {
+
+    @Autowired
+    private PaymentGateway paymentGateway;
+
+    public void execute(OrderPayCmd cmd) {
+        // 通过网关发起支付,不关心具体实现
+        PaymentResult result = paymentGateway.initiate(
+            new PaymentRequest(cmd.getOrderId(), cmd.getAmount(), cmd.getChannel())
+        );
+
+        if (result.isSuccess()) {
+            // 支付成功处理
+        }
+    }
+}
+```
+
+### 4.4 领域事件(Domain Event)
+
+**目的**:实现领域内的解耦和最终一致性
+
+```java
+// 1. 定义领域事件(位于 domain/model/event)
+@Data
+public class OrderPaidEvent implements DomainEvent {
+
+    private final String orderId;
+    private final String customerId;
+    private final Money amount;
+    private final LocalDateTime occurredOn;
+
+    public OrderPaidEvent(String orderId, String customerId, Money amount) {
+        this.orderId = orderId;
+        this.customerId = customerId;
+        this.amount = amount;
+        this.occurredOn = LocalDateTime.now();
+    }
+}
+
+// 2. 在聚合根中发布事件
+@Entity
+public class Order {
+
+    private List<DomainEvent> domainEvents = new ArrayList<>();
+
+    public void pay(Payment payment) {
+        // 业务逻辑
+        this.status = OrderStatus.PAID;
+        this.paidTime = LocalDateTime.now();
+
+        // 发布领域事件
+        this.domainEvents.add(new OrderPaidEvent(
+            this.id,
+            this.customerId,
+            this.totalAmount
+        ));
+    }
+
+    public List<DomainEvent> getDomainEvents() {
+        return Collections.unmodifiableList(domainEvents);
+    }
+
+    public void clearDomainEvents() {
+        this.domainEvents.clear();
+    }
+}
+
+// 3. 事件处理器(位于 app/eventhandler)
+@Component
+public class OrderEventHandler {
+
+    @Autowired
+    private OrderGateway orderGateway;
+
+    @Autowired
+    private NotificationGateway notificationGateway;
+
+    @Autowired
+    private CustomerGateway customerGateway;
+
+    @EventHandler
+    public void handleOrderPaidEvent(OrderPaidEvent event) {
+        // 发送支付成功通知
+        notificationGateway.sendPaymentSuccessNotification(event.getCustomerId());
+
+        // 更新用户积分
+        customerGateway.addPoints(event.getCustomerId(), event.getAmount());
+    }
+}
+
+// 4. 在仓储中保存事件
+@Repository
+public class OrderRepositoryImpl implements OrderRepository {
+
+    @Override
+    public void save(Order order) {
+        // 保存聚合
+        orderMapper.insert(order);
+
+        // 发布领域事件
+        List<DomainEvent> events = order.getDomainEvents();
+        for (DomainEvent event : events) {
+            eventPublisher.publish(event);
+        }
+
+        // 清除事件
+        order.clearDomainEvents();
+    }
+}
+```
+
+### 4.5 仓储(Repository)模式
+
+```java
+// 1. 定义仓储接口(位于 domain/repository)
+public interface OrderRepository {
+
+    /**
+     * 保存订单
+     */
+    void save(Order order);
+
+    /**
+     * 根据 ID 查找订单
+     */
+    Optional<Order> findById(String orderId);
+
+    /**
+     * 查找客户的订单列表
+     */
+    List<Order> findByCustomerId(String customerId);
+
+    /**
+     * 删除订单
+     */
+    void delete(Order order);
+}
+
+// 2. 实现仓储(位于 infrastructure/persistence)
+@Repository
+public class OrderRepositoryImpl implements OrderRepository {
+
+    @Autowired
+    private OrderMapper orderMapper;
+
+    @Autowired
+    private OrderItemMapper orderItemMapper;
+
+    @Override
+    public void save(Order order) {
+        // 保存订单主表
+        orderMapper.insert(order);
+
+        // 保存订单明细
+        for (OrderItem item : order.getItems()) {
+            orderItemMapper.insert(item);
+        }
+
+        // 发布领域事件
+        publishDomainEvents(order);
+    }
+
+    @Override
+    public Optional<Order> findById(String orderId) {
+        OrderDO orderDO = orderMapper.selectById(orderId);
+        if (orderDO == null) {
+            return Optional.empty();
+        }
+
+        List<OrderItemDO> itemDOs = orderItemMapper.selectByOrderId(orderId);
+
+        // 转换为领域对象
+        Order order = OrderConverter.toDomain(orderDO, itemDOs);
+        return Optional.of(order);
+    }
+
+    @Override
+    public List<Order> findByCustomerId(String customerId) {
+        List<OrderDO> orderDOs = orderMapper.selectByCustomerId(customerId);
+        return orderDOs.stream()
+            .map(OrderConverter::toDomain)
+            .collect(Collectors.toList());
+    }
+
+    @Override
+    public void delete(Order order) {
+        orderMapper.deleteById(order.getId());
+    }
+}
+```
+
+### 4.6 聚合(Aggregate)模式
+
+```java
+// 聚合根(Aggregate Root)
+@Entity
+public class Order {
+
+    private String orderId;
+    private String customerId;
+    private Money totalAmount;
+    private OrderStatus status;
+    private List<OrderItem> items;  // 包含的实体
+
+    // 修改状态的入口点,保证不变式
+    public void addItem(Product product, int quantity) {
+        // 业务规则检查
+        if (this.status != OrderStatus.PENDING) {
+            throw new OrderException("只有待处理状态的订单可以添加商品");
+        }
+
+        // 添加明细
+        OrderItem item = new OrderItem(product, quantity);
+        this.items.add(item);
+
+        // 更新总金额(保证不变式)
+        recalculateTotal();
+    }
+
+    public void removeItem(String itemId) {
+        // 检查状态
+        if (this.status != OrderStatus.PENDING) {
+            throw new OrderException("只有待处理状态的订单可以移除商品");
+        }
+
+        // 移除明细
+        this.items.removeIf(item -> item.getId().equals(itemId));
+
+        // 更新总金额
+        recalculateTotal();
+    }
+
+    private void recalculateTotal() {
+        this.totalAmount = this.items.stream()
+            .map(OrderItem::getSubTotal)
+            .reduce(Money.ZERO, Money::add);
+    }
+
+    public void place() {
+        // 业务规则验证
+        if (items.isEmpty()) {
+            throw new OrderException("订单不能为空");
+        }
+
+        if (totalAmount.isZero()) {
+            throw new OrderException("订单金额必须大于0");
+        }
+
+        // 状态变更
+        this.status = OrderStatus.PLACED;
+
+        // 发布领域事件
+        this.domainEvents.add(new OrderPlacedEvent(this.orderId));
+    }
+}
+
+// 聚合内的实体
+@Entity
+public class OrderItem {
+    private String itemId;
+    private String productId;
+    private String productName;
+    private Money unitPrice;
+    private int quantity;
+    private Money subTotal;
+
+    // 只能通过聚合根操作
+    protected OrderItem(Product product, int quantity) {
+        this.productId = product.getId();
+        this.productName = product.getName();
+        this.unitPrice = product.getPrice();
+        this.quantity = quantity;
+        this.subTotal = unitPrice.multiply(quantity);
+    }
+
+    public void increaseQuantity(int delta) {
+        this.quantity += delta;
+        this.subTotal = this.unitPrice.multiply(this.quantity);
+    }
+}
+```
+
+---
+
+## 总结
+
+COLA V5 架构的核心价值:
+
+1. **分层清晰**:Adapter → App → Domain ← Infrastructure,职责明确
+2. **依赖单向**:外层依赖内层,通过接口反转依赖
+3. **高度扩展**:Extension Point 机制支持业务逻辑动态扩展
+4. **能力封装**:Ability 模式封装跨实体业务规则
+5. **CQRS 分离**:命令和查询执行器分离,优化读写性能
+6. **防腐层设计**:Gateway 隔离外部依赖,保护领域模型纯净
+
+无论是单体应用还是微服务架构,COLA V5 都能提供一致的分层和代码组织方式,帮助团队构建可维护、可扩展的企业级应用。

+ 202 - 0
skills/ddd4j-project-builder/examples/architecture-patterns.md

@@ -0,0 +1,202 @@
+# Architecture Patterns Reference
+
+This document provides detailed structure examples for four DDD architecture patterns.
+
+## 1. DDD Classic Layered Architecture (DDD 经典分层架构)
+
+### Layer Structure
+
+```
+interfaces (接口层)
+    ↓ 依赖
+application (应用层)
+    ↓ 依赖
+domain (领域层)
+    ↑ 实现接口
+infrastructure (基础设施层)
+```
+
+### Package Structure
+
+```
+{basePackage}.{module}.interfaces
+{basePackage}.{module}.application
+{basePackage}.{module}.domain
+{basePackage}.{module}.infrastructure
+```
+
+### Key Components
+
+- **interfaces**: Controllers, DTOs, Filters, Exception Handlers
+- **application**: Application Services, Commands, Queries, Event Handlers
+- **domain**: Aggregates, Entities, Value Objects, Domain Services, Repository Interfaces
+- **infrastructure**: Repository Implementations, External Services, Configurations
+
+### Reference
+
+See: `docs/1、DDD 经典分层架构目录结构.md`
+
+## 2. Hexagonal Architecture (六边形架构)
+
+### Layer Structure
+
+```
+adapter (适配器层)
+    ↓ 依赖
+application (应用层)
+    ↓ 依赖
+domain (领域层)
+    ↑ 实现接口
+infrastructure (基础设施层)
+```
+
+### Package Structure
+
+```
+{basePackage}.{module}.adapter
+{basePackage}.{module}.application
+{basePackage}.{module}.domain
+{basePackage}.{module}.infrastructure
+```
+
+### Key Components
+
+- **adapter**: Web Controllers, RPC Providers, Message Consumers, Scheduled Jobs
+- **application**: Use Cases, Application Services, Ports (Inbound/Outbound)
+- **domain**: Entities, Value Objects, Domain Services, Domain Events
+- **infrastructure**: Repository Implementations, External Service Adapters, Configurations
+
+### Ports and Adapters
+
+- **Inbound Ports**: Define application services (e.g., `IOrderService`)
+- **Outbound Ports**: Define external dependencies (e.g., `IOrderRepository`, `IPaymentProvider`)
+- **Inbound Adapters**: Web Controllers, CLI, Message Consumers
+- **Outbound Adapters**: Database Repositories, External API Clients, Message Publishers
+
+### Reference
+
+See: `docs/2、六边形架构详细目录结构参考.md`
+
+## 3. Clean Architecture (整洁架构)
+
+### Layer Structure
+
+```
+interfaces (接口适配器层)
+    ↓ 依赖
+application (应用层/用例层)
+    ↓ 依赖
+domain (领域层/实体层)
+    ↑ 实现接口
+infrastructure (基础设施层)
+```
+
+### Package Structure
+
+```
+{basePackage}.{module}.interfaces
+{basePackage}.{module}.application
+{basePackage}.{module}.domain
+{basePackage}.{module}.infrastructure
+```
+
+### Key Components
+
+- **interfaces**: Controllers, Presenters, Gateways (Input/Output Ports)
+- **application**: Use Cases, Application Services, Input/Output Ports
+- **domain**: Entities, Value Objects, Domain Services, Repository Interfaces
+- **infrastructure**: Repository Implementations, External Service Adapters, Configurations
+
+### Ports
+
+- **Input Ports**: Define use case interfaces
+- **Output Ports**: Define external dependencies (Repository, External Services)
+
+### Reference
+
+See: `docs/3、整洁架构详细目录结构参考.md`
+
+## 4. COLA V5 (菱形架构)
+
+### Layer Structure
+
+```
+adapter (适配器层)
+    ↓ 依赖
+app (应用层)
+    ↓ 依赖
+domain (领域层)
+    ↑ 实现接口
+infrastructure (基础设施层)
+```
+
+### Package Structure
+
+```
+{basePackage}.{module}.adapter
+{basePackage}.{module}.app
+{basePackage}.{module}.domain
+{basePackage}.{module}.infrastructure
+```
+
+### Key Components
+
+- **adapter**: Web Controllers, RPC Providers, Job Schedulers, Message Listeners
+- **app**: Executors (Command/Query), Application Services, Extensions
+- **domain**: Entities, Value Objects, Domain Services, Abilities, Gateways, Repository Interfaces
+- **infrastructure**: Repository Implementations, Gateway Implementations, External Clients
+
+### COLA V5 Specific Features
+
+- **Executors**: Command Executors (`CmdExe`) and Query Executors (`QryExe`)
+- **Extensions**: Extension Points for business logic extension
+- **Abilities**: Domain abilities for cross-entity business rules
+- **Gateways**: Domain gateways for external dependencies
+
+### Reference
+
+See: `docs/4、COLA V5 架构详细目录结构参考.md`
+
+## Comparison Table
+
+| Aspect | DDD Classic | Hexagonal | Clean | COLA V5 |
+|--------|-------------|-----------|-------|---------|
+| **Interface Layer** | `interfaces` | `adapter` | `interfaces` | `adapter` |
+| **Application Layer** | `application` | `application` | `application` | `app` |
+| **Domain Layer** | `domain` | `domain` | `domain` | `domain` |
+| **Infrastructure** | `infrastructure` | `infrastructure` | `infrastructure` | `infrastructure` |
+| **Port Concept** | No | Yes (Inbound/Outbound) | Yes (Input/Output) | Yes (Gateways) |
+| **Use Cases** | Application Services | Use Cases | Use Cases | Executors |
+| **Extension** | No | No | No | Yes (Extension Points) |
+| **Ability** | Domain Services | Domain Services | Domain Services | Abilities |
+
+## Choosing an Architecture
+
+### Choose DDD Classic when:
+- Following Eric Evans' DDD book
+- Need clear layer separation
+- Standard DDD implementation
+
+### Choose Hexagonal when:
+- Need technology isolation
+- Multiple driving adapters (Web, CLI, Message)
+- High testability requirements
+
+### Choose Clean Architecture when:
+- Need concentric circle structure
+- High testability requirements
+- Business logic complexity
+
+### Choose COLA V5 when:
+- Need extension mechanism
+- Want ability pattern
+- Alibaba COLA framework users
+
+## Common Principles
+
+All four architectures follow these principles:
+
+1. **Dependency Rule**: Dependencies point inward, domain layer has no external dependencies
+2. **Interface Segregation**: Domain layer defines interfaces, infrastructure implements them
+3. **Separation of Concerns**: Clear layer responsibilities
+4. **Testability**: Domain layer can be tested independently

+ 311 - 0
skills/ddd4j-project-builder/examples/microservices.md

@@ -0,0 +1,311 @@
+# Microservices Structure Example
+
+## Overview
+
+Microservices architecture is suitable for large platforms with multiple business domains and team size of 50+ people.
+
+## Project Configuration
+
+- **groupId**: `io.ddd4j.base`
+- **artifactId**: `ecommerce-platform`
+- **version**: `1.0.0-SNAPSHOT`
+- **parentVersion**: `2023.0.x.20251205-SNAPSHOT` (Spring Boot 3.3.x)
+- **packageBase**: `io.ddd4j.ecommerce`
+- **architecture**: DDD Classic Layered Architecture
+
+## Directory Structure
+
+```
+ecommerce-platform/                                 # 电商平台根目录
+├── pom.xml                                         # 父POM
+├── README.md
+├── .gitignore
+├── LICENSE
+├── mvnw
+├── mvnw.cmd
+│
+├── platform-common/                               # 平台通用模块
+│   ├── pom.xml
+│   └── src/main/java/io/ddd4j/ecommerce/common/
+│       ├── kernel/
+│       │   ├── AggregateRoot.java
+│       │   └── ValueObject.java
+│       ├── util/
+│       └── exception/
+│
+├── services/                                      # 微服务目录
+│   │
+│   ├── user-service/                               # 用户服务
+│   │   ├── pom.xml                                # 服务父POM
+│   │   │
+│   │   ├── user-service-api/                      # API模块
+│   │   │   ├── pom.xml
+│   │   │   └── src/main/java/io/ddd4j/ecommerce/user/api/
+│   │   │       ├── package-info.java
+│   │   │       └── UserService.java
+│   │   │
+│   │   ├── user-service-domain/                   # 领域模块
+│   │   │   ├── pom.xml
+│   │   │   └── src/main/java/io/ddd4j/ecommerce/user/domain/
+│   │   │       ├── package-info.java
+│   │   │       ├── model/
+│   │   │       ├── service/
+│   │   │       └── repository/
+│   │   │
+│   │   ├── user-service-application/             # 应用模块
+│   │   │   ├── pom.xml
+│   │   │   └── src/main/java/io/ddd4j/ecommerce/user/application/
+│   │   │       ├── package-info.java
+│   │   │       ├── service/
+│   │   │       ├── command/
+│   │   │       └── query/
+│   │   │
+│   │   ├── user-service-infrastructure/          # 基础设施模块
+│   │   │   ├── pom.xml
+│   │   │   └── src/main/java/io/ddd4j/ecommerce/user/infrastructure/
+│   │   │       ├── package-info.java
+│   │   │       ├── persistence/
+│   │   │       └── external/
+│   │   │
+│   │   ├── user-service-interfaces/              # 接口模块
+│   │   │   ├── pom.xml
+│   │   │   └── src/main/java/io/ddd4j/ecommerce/user/interfaces/
+│   │   │       ├── package-info.java
+│   │   │       └── web/
+│   │   │           └── controller/
+│   │   │
+│   │   └── user-service-start/                   # 启动模块
+│   │       ├── pom.xml
+│   │       └── src/main/java/io/ddd4j/ecommerce/user/
+│   │           ├── UserApplication.java           # @SpringBootApplication
+│   │           └── package-info.java
+│   │
+│   ├── order-service/                            # 订单服务
+│   │   ├── pom.xml
+│   │   ├── order-service-api/
+│   │   ├── order-service-domain/
+│   │   ├── order-service-application/
+│   │   ├── order-service-infrastructure/
+│   │   ├── order-service-interfaces/
+│   │   └── order-service-start/
+│   │
+│   ├── product-service/                          # 商品服务
+│   │   ├── pom.xml
+│   │   ├── product-service-api/
+│   │   ├── product-service-domain/
+│   │   ├── product-service-application/
+│   │   ├── product-service-infrastructure/
+│   │   ├── product-service-interfaces/
+│   │   └── product-service-start/
+│   │
+│   └── payment-service/                          # 支付服务
+│       ├── pom.xml
+│       ├── payment-service-api/
+│       ├── payment-service-domain/
+│       ├── payment-service-application/
+│       ├── payment-service-infrastructure/
+│       ├── payment-service-interfaces/
+│       └── payment-service-start/
+│
+├── gateway/                                       # 网关服务
+│   ├── pom.xml
+│   └── gateway-start/
+│       └── src/main/java/io/ddd4j/ecommerce/gateway/
+│           ├── GatewayApplication.java
+│           └── package-info.java
+│
+└── docs/
+    └── architecture.md
+```
+
+## Parent pom.xml Example
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>2023.0.x.20251205-SNAPSHOT</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>io.ddd4j.base</groupId>
+    <artifactId>ecommerce-platform</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>ecommerce-platform</name>
+    <description>E-commerce Platform - Microservices Architecture</description>
+
+    <modules>
+        <module>platform-common</module>
+        <module>services</module>
+        <module>gateway</module>
+    </modules>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+</project>
+```
+
+## Service pom.xml Example (user-service)
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>ecommerce-platform</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>user-service</artifactId>
+    <packaging>pom</packaging>
+
+    <name>user-service</name>
+    <description>User Service - Microservice</description>
+
+    <modules>
+        <module>user-service-api</module>
+        <module>user-service-domain</module>
+        <module>user-service-application</module>
+        <module>user-service-infrastructure</module>
+        <module>user-service-interfaces</module>
+        <module>user-service-start</module>
+    </modules>
+</project>
+```
+
+## Service Start Module pom.xml
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>user-service</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>user-service-start</artifactId>
+    <packaging>jar</packaging>
+
+    <name>user-service-start</name>
+    <description>User Service Start Module</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.ddd4j.base</groupId>
+            <artifactId>user-service-interfaces</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.ddd4j.base</groupId>
+            <artifactId>user-service-application</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.ddd4j.base</groupId>
+            <artifactId>user-service-infrastructure</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.ddd4j.base</groupId>
+            <artifactId>platform-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+```
+
+## Package Structure
+
+Each service follows the pattern: `{basePackage}.{serviceName}.{layerName}`
+
+**User Service**:
+- `io.ddd4j.ecommerce.user.api` - API layer
+- `io.ddd4j.ecommerce.user.domain` - Domain layer
+- `io.ddd4j.ecommerce.user.application` - Application layer
+- `io.ddd4j.ecommerce.user.infrastructure` - Infrastructure layer
+- `io.ddd4j.ecommerce.user.interfaces` - Interfaces layer
+
+## Service Dependencies
+
+```
+user-service-start
+    ↓ depends on
+user-service-interfaces → user-service-application → user-service-domain ← user-service-infrastructure
+    ↓                                                                              ↓
+user-service-api                                                                  platform-common
+```
+
+## Key Features
+
+1. **Independent Services**: Each service can be deployed independently
+2. **Service Communication**: Through RPC (Dubbo/gRPC) and message queues (Kafka/RocketMQ)
+3. **Shared Components**: `platform-common` provides common capabilities
+4. **Gateway Entry**: `gateway` service handles routing, authentication, rate limiting
+5. **Independent Databases**: Each service has its own database schema
+6. **Modular Design**: Each service internally organized by DDD four-layer architecture
+
+## Service Communication
+
+```
+Frontend → Gateway → Services (User, Order, Product, Payment)
+                           ↓
+                    Message Queue (Kafka/RocketMQ)
+```
+
+## Usage
+
+This structure is ideal for:
+- Large platforms
+- Multiple business domains
+- Team size 50+ people
+- Independent service deployment
+- Service scalability requirements
+
+## Adding New Services
+
+To add a new service (e.g., `inventory-service`):
+
+1. Create service directory: `services/inventory-service/`
+2. Create service parent `pom.xml`
+3. Create sub-modules:
+   - `inventory-service-api`
+   - `inventory-service-domain`
+   - `inventory-service-application`
+   - `inventory-service-infrastructure`
+   - `inventory-service-interfaces`
+   - `inventory-service-start`
+4. Add to parent `pom.xml` modules list
+5. Follow package naming: `io.ddd4j.ecommerce.inventory.{layer}`

+ 235 - 0
skills/ddd4j-project-builder/examples/multi-module.md

@@ -0,0 +1,235 @@
+# Multi-Module Monolith Structure Example
+
+## Overview
+
+Multi-module monolith is suitable for medium to large applications with multiple business domains and team size of 15-50 people.
+
+## Project Configuration
+
+- **groupId**: `io.ddd4j.base`
+- **artifactId**: `ddd4j-douyin`
+- **version**: `1.0.0-SNAPSHOT`
+- **parentVersion**: `2023.0.x.20251205-SNAPSHOT` (Spring Boot 3.3.x)
+- **packageBase**: `io.ddd4j.douyin`
+- **architecture**: DDD Classic Layered Architecture
+
+## Directory Structure
+
+```
+ddd4j-douyin/
+├── pom.xml                                          # 父POM
+├── README.md
+├── .gitignore
+├── LICENSE
+├── mvnw
+├── mvnw.cmd
+│
+├── ddd4j-douyin-bom/                                # BOM依赖管理
+│   ├── pom.xml
+│   └── src/main/java/io/ddd4j/douyin/bom/
+│       └── package-info.java
+│
+├── ddd4j-douyin-dependencies/                      # 公共依赖
+│   ├── pom.xml
+│   └── src/main/java/io/ddd4j/douyin/dependencies/
+│       └── package-info.java
+│
+├── ddd4j-douyin-api/                               # API业务模块
+│   ├── pom.xml
+│   ├── ddd4j-douyin-api-adapter/                  # 适配器层
+│   │   ├── pom.xml
+│   │   └── src/main/java/io/ddd4j/douyin/api/adapter/
+│   │       ├── package-info.java
+│   │       ├── web/
+│   │       │   ├── controller/
+│   │       │   │   └── ApiController.java
+│   │       │   └── dto/
+│   │       └── rpc/
+│   │
+│   ├── ddd4j-douyin-api-client/                   # 客户端模块
+│   │   ├── pom.xml
+│   │   └── src/main/java/io/ddd4j/douyin/api/client/
+│   │       ├── package-info.java
+│   │       └── ApiClient.java
+│   │
+│   ├── ddd4j-douyin-api-app/                      # 应用层
+│   │   ├── pom.xml
+│   │   └── src/main/java/io/ddd4j/douyin/api/app/
+│   │       ├── package-info.java
+│   │       ├── service/
+│   │       │   └── ApiApplicationService.java
+│   │       ├── command/
+│   │       └── query/
+│   │
+│   ├── ddd4j-douyin-api-domain/                   # 领域层
+│   │   ├── pom.xml
+│   │   └── src/main/java/io/ddd4j/douyin/api/domain/
+│   │       ├── package-info.java
+│   │       ├── model/
+│   │       │   ├── aggregate/
+│   │       │   ├── valueobject/
+│   │       │   └── event/
+│   │       ├── service/
+│   │       └── repository/
+│   │
+│   └── ddd4j-douyin-api-infrastructure/            # 基础设施层
+│       ├── pom.xml
+│       └── src/main/java/io/ddd4j/douyin/api/infrastructure/
+│           ├── package-info.java
+│           ├── persistence/
+│           ├── messaging/
+│           └── external/
+│
+├── ddd4j-douyin-common/                           # 通用模块
+│   ├── pom.xml
+│   ├── ddd4j-douyin-common-domain/               # 通用领域
+│   │   ├── pom.xml
+│   │   └── src/main/java/io/ddd4j/douyin/common/domain/
+│   │       ├── package-info.java
+│   │       └── model/
+│   │
+│   └── ddd4j-douyin-common-infrastructure/       # 通用基础设施
+│       ├── pom.xml
+│       └── src/main/java/io/ddd4j/douyin/common/infrastructure/
+│           ├── package-info.java
+│           └── config/
+│
+└── ddd4j-douyin-start/                            # 启动模块
+    ├── pom.xml
+    └── src/main/java/io/ddd4j/douyin/
+        ├── DouyinApplication.java                  # @SpringBootApplication
+        └── package-info.java
+```
+
+## Parent pom.xml Example
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>2023.0.x.20251205-SNAPSHOT</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>io.ddd4j.base</groupId>
+    <artifactId>ddd4j-douyin</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>ddd4j-douyin</name>
+    <description>Douyin Platform - Multi-Module Monolith</description>
+
+    <modules>
+        <module>ddd4j-douyin-bom</module>
+        <module>ddd4j-douyin-dependencies</module>
+        <module>ddd4j-douyin-api</module>
+        <module>ddd4j-douyin-common</module>
+        <module>ddd4j-douyin-start</module>
+    </modules>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+</project>
+```
+
+## Module pom.xml Example (api-domain)
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>ddd4j-douyin</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>ddd4j-douyin-api-domain</artifactId>
+    <packaging>jar</packaging>
+
+    <name>ddd4j-douyin-api-domain</name>
+    <description>API Domain Layer</description>
+
+    <dependencies>
+        <!-- Common Domain -->
+        <dependency>
+            <groupId>io.ddd4j.base</groupId>
+            <artifactId>ddd4j-douyin-common-domain</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+</project>
+```
+
+## Package Structure
+
+Each module follows the pattern: `{basePackage}.{moduleName}.{layerName}`
+
+**API Module**:
+- `io.ddd4j.douyin.api.adapter` - Adapter layer
+- `io.ddd4j.douyin.api.app` - Application layer
+- `io.ddd4j.douyin.api.domain` - Domain layer
+- `io.ddd4j.douyin.api.infrastructure` - Infrastructure layer
+
+**Common Module**:
+- `io.ddd4j.douyin.common.domain` - Common domain
+- `io.ddd4j.douyin.common.infrastructure` - Common infrastructure
+
+## Module Dependencies
+
+```
+ddd4j-douyin-start
+    ↓ depends on
+ddd4j-douyin-api-adapter → ddd4j-douyin-api-app → ddd4j-douyin-api-domain ← ddd4j-douyin-api-infrastructure
+    ↓                                                                              ↓
+ddd4j-douyin-common-domain ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ddd4j-douyin-common-infrastructure
+    ↓
+ddd4j-douyin-bom
+    ↓
+ddd4j-douyin-dependencies
+```
+
+## Key Features
+
+1. **Multiple Maven Modules**: Each business domain has its own module
+2. **Layer Separation**: Each module contains complete DDD layers
+3. **Shared Common Module**: Reusable domain and infrastructure components
+4. **BOM Management**: Centralized dependency version management
+5. **Dependency Control**: Clear module dependencies
+
+## Usage
+
+This structure is ideal for:
+- Medium to large applications
+- Multiple business domains
+- Team size 15-50 people
+- Need for module isolation
+- Shared component reuse
+
+## Adding New Business Modules
+
+To add a new business module (e.g., `ddd4j-douyin-order`):
+
+1. Create module directory: `ddd4j-douyin-order/`
+2. Create sub-modules:
+   - `ddd4j-douyin-order-adapter`
+   - `ddd4j-douyin-order-app`
+   - `ddd4j-douyin-order-domain`
+   - `ddd4j-douyin-order-infrastructure`
+3. Add to parent `pom.xml` modules list
+4. Follow package naming: `io.ddd4j.douyin.order.{layer}`

+ 213 - 0
skills/ddd4j-project-builder/examples/single-module.md

@@ -0,0 +1,213 @@
+# Single-Module Monolith Structure Example
+
+## Overview
+
+Single-module monolith is suitable for small to medium applications with a single business domain and team size of 5-15 people.
+
+## Project Configuration
+
+- **groupId**: `io.ddd4j.base`
+- **artifactId**: `ddd4j-order`
+- **version**: `1.0.0-SNAPSHOT`
+- **parentVersion**: `2023.0.x.20251205-SNAPSHOT` (Spring Boot 3.3.x)
+- **packageBase**: `io.ddd4j.order`
+- **architecture**: DDD Classic Layered Architecture
+
+## Directory Structure
+
+```
+ddd4j-order/
+├── pom.xml
+├── README.md
+├── .gitignore
+├── LICENSE
+├── mvnw
+├── mvnw.cmd
+│
+├── src/
+│   ├── main/
+│   │   ├── java/
+│   │   │   └── io/ddd4j/order/
+│   │   │       ├── OrderApplication.java              # @SpringBootApplication
+│   │   │       │
+│   │   │       ├── interfaces/                        # 接口层
+│   │   │       │   ├── web/
+│   │   │       │   │   ├── controller/
+│   │   │       │   │   │   ├── OrderController.java
+│   │   │       │   │   │   └── CustomerController.java
+│   │   │       │   │   ├── dto/
+│   │   │       │   │   │   ├── request/
+│   │   │       │   │   │   │   ├── PlaceOrderRequest.java
+│   │   │       │   │   │   │   └── PayOrderRequest.java
+│   │   │       │   │   │   └── response/
+│   │   │       │   │   │       ├── OrderResponse.java
+│   │   │       │   │   │       └── ApiResponse.java
+│   │   │       │   │   └── advice/
+│   │   │       │   │       └── GlobalExceptionHandler.java
+│   │   │       │   │
+│   │   │       │   └── rpc/                           # RPC接口(可选)
+│   │   │       │       ├── OrderRpcProvider.java
+│   │   │       │       └── PaymentRpcConsumer.java
+│   │   │       │
+│   │   │       ├── application/                       # 应用层
+│   │   │       │   ├── service/
+│   │   │       │   │   ├── OrderApplicationService.java
+│   │   │       │   │   └── CustomerApplicationService.java
+│   │   │       │   ├── command/
+│   │   │       │   │   ├── PlaceOrderCommand.java
+│   │   │       │   │   └── PayOrderCommand.java
+│   │   │       │   ├── query/
+│   │   │       │   │   ├── GetOrderQuery.java
+│   │   │       │   │   └── OrderListQuery.java
+│   │   │       │   └── eventhandler/
+│   │   │       │       └── OrderPlacedEventHandler.java
+│   │   │       │
+│   │   │       ├── domain/                            # 领域层
+│   │   │       │   ├── model/
+│   │   │       │   │   ├── aggregate/
+│   │   │       │   │   │   ├── order/
+│   │   │       │   │   │   │   ├── Order.java         # 聚合根
+│   │   │       │   │   │   │   └── OrderItem.java     # 实体
+│   │   │       │   │   │   └── customer/
+│   │   │       │   │   │       └── Customer.java      # 聚合根
+│   │   │       │   │   ├── valueobject/
+│   │   │       │   │   │   ├── Money.java
+│   │   │       │   │   │   ├── Email.java
+│   │   │       │   │   │   └── Address.java
+│   │   │       │   │   └── event/
+│   │   │       │   │       ├── OrderPlacedEvent.java
+│   │   │       │   │       └── OrderPaidEvent.java
+│   │   │       │   ├── service/
+│   │   │       │   │   └── OrderDomainService.java
+│   │   │       │   └── repository/
+│   │   │       │       ├── OrderRepository.java       # 仓储接口
+│   │   │       │       └── CustomerRepository.java
+│   │   │       │
+│   │   │       └── infrastructure/                    # 基础设施层
+│   │   │           ├── persistence/
+│   │   │           │   ├── repository/
+│   │   │           │   │   ├── JpaOrderRepository.java
+│   │   │           │   │   └── JpaCustomerRepository.java
+│   │   │           │   ├── entity/
+│   │   │           │   │   ├── OrderEntity.java
+│   │   │           │   │   └── CustomerEntity.java
+│   │   │           │   └── mapper/
+│   │   │           │       └── OrderMapper.java
+│   │   │           ├── messaging/
+│   │   │           │   └── KafkaEventPublisher.java
+│   │   │           ├── external/
+│   │   │           │   └── payment/
+│   │   │           │       └── AlipayPaymentService.java
+│   │   │           └── config/
+│   │   │               ├── PersistenceConfig.java
+│   │   │               └── MessagingConfig.java
+│   │   │
+│   │   └── resources/
+│   │       ├── application.yml
+│   │       ├── application-dev.yml
+│   │       └── application-prod.yml
+│   │
+│   └── test/
+│       ├── java/
+│       │   └── io/ddd4j/order/
+│       │       ├── unit/
+│       │       │   ├── domain/
+│       │       │   │   └── OrderTest.java
+│       │       │   └── application/
+│       │       │       └── OrderApplicationServiceTest.java
+│       │       └── integration/
+│       │           └── OrderIntegrationTest.java
+│       └── resources/
+│           └── application-test.yml
+│
+└── docs/
+    └── architecture.md
+```
+
+## pom.xml Example
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>io.ddd4j.base</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>2023.0.x.20251205-SNAPSHOT</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>io.ddd4j.base</groupId>
+    <artifactId>ddd4j-order</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>ddd4j-order</name>
+    <description>Order Management System - Single Module Monolith</description>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!-- Spring Boot Starters -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        
+        <!-- Test -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+```
+
+## Package Structure
+
+All packages follow the pattern: `{basePackage}.{layer}`
+
+- `io.ddd4j.order.interfaces` - Interface layer
+- `io.ddd4j.order.application` - Application layer
+- `io.ddd4j.order.domain` - Domain layer
+- `io.ddd4j.order.infrastructure` - Infrastructure layer
+
+## Key Features
+
+1. **Single Maven Module**: All layers in one module
+2. **Clear Layer Separation**: Interfaces → Application → Domain ← Infrastructure
+3. **Complete Structure**: Includes all required directories and files
+4. **Test Structure**: Unit and integration test directories
+5. **Configuration**: Environment-specific configuration files
+
+## Usage
+
+This structure is ideal for:
+- Small to medium applications
+- Single business domain
+- Team size 5-15 people
+- Quick development and deployment
+- Simple maintenance

+ 3 - 0
skills/ddd4j-project-builder/scripts/__init__.py

@@ -0,0 +1,3 @@
+"""
+DDD Project Initialization and Validation Scripts
+"""

+ 336 - 0
skills/ddd4j-project-builder/scripts/check_project.py

@@ -0,0 +1,336 @@
+#!/usr/bin/env python3
+"""
+DDD Project Structure Validation Script
+
+This script analyzes an existing project structure and:
+1. Identifies the project type (single-module, multi-module, microservices)
+2. Validates directory structure compliance
+3. Checks package naming conventions
+4. Verifies layer dependencies
+5. Generates a validation report
+"""
+
+import os
+import sys
+import json
+from pathlib import Path
+from typing import Dict, List, Optional, Tuple
+
+
+class DDDProjectChecker:
+    """DDD Project Structure Checker"""
+    
+    def __init__(self, project_path: str):
+        self.project_path = Path(project_path)
+        self.issues = []
+        self.warnings = []
+        self.project_type = None
+        self.modules = []
+        self.architecture = None
+    
+    def check(self) -> Dict:
+        """Check project structure and return report"""
+        if not self.project_path.exists():
+            return {
+                "status": "error",
+                "message": f"Project path does not exist: {self.project_path}"
+            }
+        
+        # Identify project type
+        self.project_type = self._identify_project_type()
+        
+        # Check structure based on type
+        if self.project_type == "single-module":
+            result = self._check_single_module()
+        elif self.project_type == "multi-module":
+            result = self._check_multi_module()
+        elif self.project_type == "microservices":
+            result = self._check_microservices()
+        else:
+            return {
+                "status": "error",
+                "message": "Could not identify project type"
+            }
+        
+        # Validate common requirements
+        self._check_common_files()
+        self._check_package_naming()
+        
+        return {
+            "status": "success",
+            "projectType": self.project_type,
+            "architecture": self.architecture,
+            "modules": self.modules,
+            "issues": self.issues,
+            "warnings": self.warnings,
+            "compliant": len(self.issues) == 0
+        }
+    
+    def _identify_project_type(self) -> Optional[str]:
+        """Identify project type based on structure"""
+        root_pom = self.project_path / "pom.xml"
+        
+        if not root_pom.exists():
+            return None
+        
+        # Read pom.xml to check for modules
+        try:
+            content = root_pom.read_text(encoding="utf-8")
+            
+            # Check for modules tag
+            if "<modules>" in content:
+                # Check if it's microservices (has services/ directory)
+                services_dir = self.project_path / "services"
+                if services_dir.exists() and services_dir.is_dir():
+                    return "microservices"
+                else:
+                    return "multi-module"
+            else:
+                return "single-module"
+        except Exception as e:
+            self.issues.append(f"Error reading pom.xml: {e}")
+            return None
+    
+    def _check_single_module(self) -> Dict:
+        """Check single-module project structure"""
+        src_main_java = self.project_path / "src" / "main" / "java"
+        
+        if not src_main_java.exists():
+            self.issues.append("Missing src/main/java directory")
+            return {"valid": False}
+        
+        # Identify architecture by checking layer directories
+        layers = self._detect_layers(src_main_java)
+        self.architecture = self._identify_architecture(layers)
+        
+        # Check layer structure
+        for layer in layers:
+            layer_path = src_main_java
+            # Find layer directory (could be at any depth)
+            for part in layer.split("/"):
+                layer_path = layer_path / part
+                if not layer_path.exists():
+                    self.warnings.append(f"Layer '{layer}' not found at expected location")
+                    break
+        
+        # Check package-info.java
+        self._check_package_info_files(src_main_java)
+        
+        return {"valid": True, "layers": layers}
+    
+    def _check_multi_module(self) -> Dict:
+        """Check multi-module project structure"""
+        # Find all modules
+        modules = []
+        for item in self.project_path.iterdir():
+            if item.is_dir() and (item / "pom.xml").exists():
+                # Check if it's a module (has sub-modules or is a business module)
+                pom_content = (item / "pom.xml").read_text(encoding="utf-8")
+                if "<modules>" in pom_content or "-" in item.name:
+                    modules.append(item.name)
+        
+        self.modules = modules
+        
+        # Check each module
+        for module_name in modules:
+            module_path = self.project_path / module_name
+            if module_path.is_dir():
+                self._check_module_structure(module_path, module_name)
+        
+        return {"valid": True, "modules": modules}
+    
+    def _check_microservices(self) -> Dict:
+        """Check microservices project structure"""
+        services_dir = self.project_path / "services"
+        
+        if not services_dir.exists():
+            self.issues.append("Missing services/ directory")
+            return {"valid": False}
+        
+        # Find all services
+        services = []
+        for item in services_dir.iterdir():
+            if item.is_dir() and (item / "pom.xml").exists():
+                services.append(item.name)
+                self._check_service_structure(item, item.name)
+        
+        self.modules = services
+        
+        return {"valid": True, "services": services}
+    
+    def _check_module_structure(self, module_path: Path, module_name: str):
+        """Check structure of a business module"""
+        # Check for sub-modules
+        sub_modules = []
+        for item in module_path.iterdir():
+            if item.is_dir() and (item / "pom.xml").exists():
+                sub_modules.append(item.name)
+        
+        # Expected sub-modules based on architecture
+        if len(sub_modules) > 0:
+            # This is a parent module with sub-modules
+            layers = self._detect_layers_from_module_names(sub_modules)
+            self.architecture = self._identify_architecture_from_modules(sub_modules)
+            
+            # Check each sub-module
+            for sub_module in sub_modules:
+                sub_module_path = module_path / sub_module
+                src_main_java = sub_module_path / "src" / "main" / "java"
+                if src_main_java.exists():
+                    self._check_package_info_files(src_main_java)
+        else:
+            # Single module, check layers directly
+            src_main_java = module_path / "src" / "main" / "java"
+            if src_main_java.exists():
+                layers = self._detect_layers(src_main_java)
+                self.architecture = self._identify_architecture(layers)
+                self._check_package_info_files(src_main_java)
+    
+    def _check_service_structure(self, service_path: Path, service_name: str):
+        """Check structure of a microservice"""
+        # Check for service modules
+        modules = []
+        for item in service_path.iterdir():
+            if item.is_dir() and (item / "pom.xml").exists():
+                modules.append(item.name)
+        
+        # Expected: api, domain, application, infrastructure, interfaces, start
+        expected_modules = ["api", "domain", "application", "infrastructure", "interfaces", "start"]
+        for expected in expected_modules:
+            module_name = f"{service_name}-{expected}"
+            if module_name not in modules:
+                self.warnings.append(f"Service {service_name} missing module: {expected}")
+        
+        # Check each module
+        for module in modules:
+            module_path = service_path / module
+            src_main_java = module_path / "src" / "main" / "java"
+            if src_main_java.exists():
+                self._check_package_info_files(src_main_java)
+    
+    def _detect_layers(self, java_path: Path) -> List[str]:
+        """Detect layer structure from directory"""
+        layers = []
+        
+        # Common layer names
+        layer_names = [
+            "interfaces", "application", "domain", "infrastructure",
+            "adapter", "app", "usecase", "entity", "valueobject"
+        ]
+        
+        def scan_directory(path: Path, depth: int = 0, max_depth: int = 3):
+            if depth > max_depth:
+                return
+            for item in path.iterdir():
+                if item.is_dir():
+                    if item.name in layer_names:
+                        layers.append(item.name)
+                    scan_directory(item, depth + 1, max_depth)
+        
+        scan_directory(java_path)
+        return list(set(layers))
+    
+    def _detect_layers_from_module_names(self, module_names: List[str]) -> List[str]:
+        """Detect layers from module names"""
+        layers = []
+        for name in module_names:
+            # Extract layer suffix (e.g., api-adapter -> adapter)
+            parts = name.split("-")
+            if len(parts) > 1:
+                layers.append(parts[-1])
+        return list(set(layers))
+    
+    def _identify_architecture(self, layers: List[str]) -> str:
+        """Identify architecture pattern from layers"""
+        if "adapter" in layers and "app" in layers:
+            return "cola-v5"
+        elif "adapter" in layers and "application" in layers:
+            return "hexagonal"
+        elif "interfaces" in layers and "application" in layers:
+            if "usecase" in layers:
+                return "clean"
+            else:
+                return "ddd-classic"
+        else:
+            return "unknown"
+    
+    def _identify_architecture_from_modules(self, module_names: List[str]) -> str:
+        """Identify architecture from module names"""
+        if any("adapter" in name and "app" in name for name in module_names):
+            return "cola-v5"
+        elif any("adapter" in name for name in module_names):
+            return "hexagonal"
+        elif any("interfaces" in name or "application" in name for name in module_names):
+            return "ddd-classic"
+        else:
+            return "unknown"
+    
+    def _check_package_info_files(self, java_path: Path):
+        """Check for package-info.java files"""
+        def scan_for_package_info(path: Path):
+            package_info = path / "package-info.java"
+            if not package_info.exists():
+                # Check if this is a meaningful package (has .java files or subdirectories)
+                has_java = any(f.suffix == ".java" for f in path.iterdir() if f.is_file())
+                has_subdirs = any(d.is_dir() for d in path.iterdir())
+                if has_java or has_subdirs:
+                    self.warnings.append(f"Missing package-info.java in {path.relative_to(self.project_path)}")
+            
+            # Recursively check subdirectories
+            for item in path.iterdir():
+                if item.is_dir():
+                    scan_for_package_info(item)
+        
+        scan_for_package_info(java_path)
+    
+    def _check_common_files(self):
+        """Check for common required files"""
+        required_files = [".gitignore", "LICENSE", "README.md"]
+        for file_name in required_files:
+            file_path = self.project_path / file_name
+            if not file_path.exists():
+                self.warnings.append(f"Missing required file: {file_name}")
+        
+        # Check for Maven wrapper
+        mvnw = self.project_path / "mvnw"
+        mvnw_cmd = self.project_path / "mvnw.cmd"
+        if not mvnw.exists() and not mvnw_cmd.exists():
+            self.warnings.append("Missing Maven wrapper files (mvnw, mvnw.cmd)")
+    
+    def _check_package_naming(self):
+        """Check package naming conventions"""
+        src_main_java = self.project_path / "src" / "main" / "java"
+        
+        if not src_main_java.exists():
+            return
+        
+        def check_package_name(path: Path, expected_base: Optional[str] = None):
+            """Recursively check package naming"""
+            for item in path.iterdir():
+                if item.is_dir():
+                    # Check if directory name follows Java package naming (lowercase, no hyphens)
+                    if not item.name.islower() or "-" in item.name:
+                        self.issues.append(
+                            f"Invalid package name: {item.relative_to(src_main_java)} "
+                            f"(should be lowercase, no hyphens)"
+                        )
+                    check_package_name(item)
+        
+        check_package_name(src_main_java)
+
+
+def main():
+    """Main entry point"""
+    if len(sys.argv) < 2:
+        print("Usage: check_project.py <project-path>", file=sys.stderr)
+        sys.exit(1)
+    
+    project_path = sys.argv[1]
+    checker = DDDProjectChecker(project_path)
+    result = checker.check()
+    
+    print(json.dumps(result, indent=2, ensure_ascii=False))
+
+
+if __name__ == "__main__":
+    main()

+ 1049 - 0
skills/ddd4j-project-builder/scripts/init_project.py

@@ -0,0 +1,1049 @@
+#!/usr/bin/env python3
+"""
+DDD Project Initialization Script
+
+This script creates a new DDD project structure based on the selected type:
+- single-module: Single Maven module monolith
+- multi-module: Multi-module monolith
+- microservices: Microservices architecture
+"""
+
+import os
+import sys
+import json
+from pathlib import Path
+from typing import Dict, List, Optional
+
+
+class DDDProjectInitializer:
+    """DDD Project Initializer"""
+    
+    def __init__(self, project_dir: str = "./ddd4j-project"):
+        self.project_dir = Path(project_dir)
+        self.project_dir.mkdir(parents=True, exist_ok=True)
+    
+    def init_single_module(
+        self,
+        group_id: str,
+        artifact_id: str,
+        version: str,
+        parent_version: str,
+        package_base: str,
+        architecture: str = "ddd-classic"
+    ):
+        """Initialize single-module monolith project"""
+        project_path = self.project_dir / artifact_id
+        project_path.mkdir(parents=True, exist_ok=True)
+        
+        # Create directory structure
+        src_main_java = project_path / "src" / "main" / "java" / package_base.replace(".", "/")
+        src_main_resources = project_path / "src" / "main" / "resources"
+        src_test_java = project_path / "src" / "test" / "java" / package_base.replace(".", "/")
+        src_test_resources = project_path / "src" / "test" / "resources"
+        
+        for path in [src_main_java, src_main_resources, src_test_java, src_test_resources]:
+            path.mkdir(parents=True, exist_ok=True)
+        
+        # Create layer directories
+        layers = self._get_layers(architecture)
+        for layer in layers:
+            layer_path = src_main_java / layer
+            layer_path.mkdir(parents=True, exist_ok=True)
+            # Create package-info.java
+            self._create_package_info(layer_path, f"{package_base}.{layer}")
+        
+        # Create pom.xml
+        self._create_single_module_pom(
+            project_path, group_id, artifact_id, version, parent_version
+        )
+        
+        # Create application class
+        app_class_name = self._to_class_name(artifact_id)
+        self._create_application_class(
+            src_main_java, package_base, app_class_name
+        )
+        
+        # Create common files
+        self._create_common_files(project_path, artifact_id)
+        
+        return str(project_path)
+    
+    def init_multi_module(
+        self,
+        group_id: str,
+        artifact_id: str,
+        version: str,
+        parent_version: str,
+        package_base: str,
+        modules: List[str],
+        architecture: str = "ddd-classic"
+    ):
+        """Initialize multi-module monolith project"""
+        project_path = self.project_dir / artifact_id
+        project_path.mkdir(parents=True, exist_ok=True)
+        
+        # Create parent pom.xml
+        self._create_parent_pom(
+            project_path, group_id, artifact_id, version, parent_version, modules
+        )
+        
+        # Create BOM and dependencies modules
+        self._create_bom_module(project_path, group_id, artifact_id, version, package_base)
+        self._create_dependencies_module(project_path, group_id, artifact_id, version, package_base)
+        
+        # Create common module
+        self._create_common_module(project_path, group_id, artifact_id, version, package_base)
+        
+        # Create business modules
+        for module_name in modules:
+            self._create_business_module(
+                project_path, group_id, artifact_id, version, package_base,
+                module_name, architecture
+            )
+        
+        # Create start module
+        self._create_start_module(
+            project_path, group_id, artifact_id, version, package_base, modules
+        )
+        
+        # Create common files
+        self._create_common_files(project_path, artifact_id)
+        
+        return str(project_path)
+    
+    def init_microservices(
+        self,
+        group_id: str,
+        artifact_id: str,
+        version: str,
+        parent_version: str,
+        package_base: str,
+        services: List[str],
+        architecture: str = "ddd-classic"
+    ):
+        """Initialize microservices project"""
+        project_path = self.project_dir / artifact_id
+        project_path.mkdir(parents=True, exist_ok=True)
+        
+        # Create parent pom.xml
+        self._create_microservices_parent_pom(
+            project_path, group_id, artifact_id, version, parent_version, services
+        )
+        
+        # Create platform-common
+        self._create_platform_common(project_path, group_id, artifact_id, version, package_base)
+        
+        # Create services
+        services_dir = project_path / "services"
+        services_dir.mkdir(parents=True, exist_ok=True)
+        
+        for service_name in services:
+            self._create_service(
+                services_dir, group_id, artifact_id, version, package_base,
+                service_name, architecture
+            )
+        
+        # Create gateway
+        self._create_gateway(project_path, group_id, artifact_id, version, package_base)
+        
+        # Create common files
+        self._create_common_files(project_path, artifact_id)
+        
+        return str(project_path)
+    
+    def _get_layers(self, architecture: str) -> List[str]:
+        """Get layer names based on architecture"""
+        layer_map = {
+            "ddd-classic": ["interfaces", "application", "domain", "infrastructure"],
+            "hexagonal": ["adapter", "application", "domain", "infrastructure"],
+            "clean": ["interfaces", "application", "domain", "infrastructure"],
+            "cola-v5": ["adapter", "app", "domain", "infrastructure"]
+        }
+        return layer_map.get(architecture, layer_map["ddd-classic"])
+    
+    def _create_package_info(self, path: Path, package_name: str):
+        """Create package-info.java file"""
+        package_info = path / "package-info.java"
+        content = f"""/**
+ * {package_name}
+ * 
+ * This package contains the {path.name} layer components.
+ */
+package {package_name};
+"""
+        package_info.write_text(content, encoding="utf-8")
+    
+    def _create_single_module_pom(
+        self, project_path: Path, group_id: str, artifact_id: str,
+        version: str, parent_version: str
+    ):
+        """Create single-module pom.xml"""
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>{parent_version}</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>{group_id}</groupId>
+    <artifactId>{artifact_id}</artifactId>
+    <version>{version}</version>
+    <packaging>jar</packaging>
+
+    <name>{artifact_id}</name>
+    <description>DDD Single-Module Monolith Project</description>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+"""
+        (project_path / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_application_class(self, src_main_java: Path, package_base: str, class_name: str):
+        """Create Spring Boot application class"""
+        app_package = src_main_java
+        app_package.mkdir(parents=True, exist_ok=True)
+        
+        app_class = app_package / f"{class_name}Application.java"
+        content = f"""package {package_base};
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * {class_name} Application
+ * 
+ * Main application entry point.
+ */
+@SpringBootApplication
+public class {class_name}Application {{
+
+    public static void main(String[] args) {{
+        SpringApplication.run({class_name}Application.class, args);
+    }}
+}}
+"""
+        app_class.write_text(content, encoding="utf-8")
+    
+    def _create_common_files(self, project_path: Path, artifact_id: str):
+        """Create common files (.gitignore, LICENSE, README.md)"""
+        # .gitignore
+        gitignore_content = """# Maven
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+
+# IDE
+.idea/
+*.iml
+*.iws
+*.ipr
+.vscode/
+.classpath
+.project
+.settings/
+*.swp
+*.swo
+*~
+
+# OS
+.DS_Store
+Thumbs.db
+
+# Logs
+*.log
+logs/
+"""
+        (project_path / ".gitignore").write_text(gitignore_content, encoding="utf-8")
+        
+        # LICENSE
+        license_content = """MIT License
+
+Copyright (c) 2024
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
+        (project_path / "LICENSE").write_text(license_content, encoding="utf-8")
+        
+        # README.md
+        readme_content = f"""# {artifact_id}
+
+DDD (Domain-Driven Design) Project
+
+## Project Structure
+
+This project follows DDD principles with clear layer separation.
+
+## Getting Started
+
+### Prerequisites
+
+- Java 17+
+- Maven 3.6+
+
+### Building
+
+```bash
+mvn clean install
+```
+
+### Running
+
+```bash
+mvn spring-boot:run
+```
+
+## Architecture
+
+This project uses DDD Classic Layered Architecture:
+- **interfaces**: Interface layer (Controllers, DTOs)
+- **application**: Application layer (Application Services, Commands, Queries)
+- **domain**: Domain layer (Aggregates, Entities, Value Objects)
+- **infrastructure**: Infrastructure layer (Repository Implementations, External Services)
+"""
+        (project_path / "README.md").write_text(readme_content, encoding="utf-8")
+    
+    def _to_class_name(self, artifact_id: str) -> str:
+        """Convert artifact_id to class name (e.g., ddd4j-order -> Ddd4jOrder)"""
+        parts = artifact_id.split("-")
+        return "".join(word.capitalize() for word in parts)
+    
+    def _create_parent_pom(
+        self, project_path: Path, group_id: str, artifact_id: str,
+        version: str, parent_version: str, modules: List[str]
+    ):
+        """Create parent pom.xml for multi-module project"""
+        module_list = "\n".join(f"        <module>{artifact_id}-{module}</module>" for module in modules)
+        module_list += f"\n        <module>{artifact_id}-common</module>"
+        module_list += f"\n        <module>{artifact_id}-start</module>"
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>{parent_version}</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>{group_id}</groupId>
+    <artifactId>{artifact_id}</artifactId>
+    <version>{version}</version>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}</name>
+    <description>DDD Multi-Module Monolith Project</description>
+
+    <modules>
+        <module>{artifact_id}-bom</module>
+        <module>{artifact_id}-dependencies</module>
+{module_list}
+    </modules>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+</project>
+"""
+        (project_path / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_bom_module(self, project_path: Path, group_id: str, artifact_id: str, version: str, package_base: str):
+        """Create BOM module"""
+        bom_dir = project_path / f"{artifact_id}-bom"
+        bom_dir.mkdir(parents=True, exist_ok=True)
+        
+        src_main_java = bom_dir / "src" / "main" / "java" / package_base.replace(".", "/") / "bom"
+        src_main_java.mkdir(parents=True, exist_ok=True)
+        self._create_package_info(src_main_java, f"{package_base}.bom")
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-bom</artifactId>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}-bom</name>
+    <description>BOM Dependency Management</description>
+</project>
+"""
+        (bom_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_dependencies_module(self, project_path: Path, group_id: str, artifact_id: str, version: str, package_base: str):
+        """Create dependencies module"""
+        deps_dir = project_path / f"{artifact_id}-dependencies"
+        deps_dir.mkdir(parents=True, exist_ok=True)
+        
+        src_main_java = deps_dir / "src" / "main" / "java" / package_base.replace(".", "/") / "dependencies"
+        src_main_java.mkdir(parents=True, exist_ok=True)
+        self._create_package_info(src_main_java, f"{package_base}.dependencies")
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-dependencies</artifactId>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}-dependencies</name>
+    <description>Common Dependencies</description>
+</project>
+"""
+        (deps_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_common_module(self, project_path: Path, group_id: str, artifact_id: str, version: str, package_base: str):
+        """Create common module"""
+        common_dir = project_path / f"{artifact_id}-common"
+        common_dir.mkdir(parents=True, exist_ok=True)
+        
+        # Create sub-modules
+        for sub_module in ["domain", "infrastructure"]:
+            sub_dir = common_dir / f"{artifact_id}-common-{sub_module}"
+            sub_dir.mkdir(parents=True, exist_ok=True)
+            
+            src_main_java = sub_dir / "src" / "main" / "java" / package_base.replace(".", "/") / "common" / sub_module
+            src_main_java.mkdir(parents=True, exist_ok=True)
+            self._create_package_info(src_main_java, f"{package_base}.common.{sub_module}")
+            
+            pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}-common</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-common-{sub_module}</artifactId>
+    <packaging>jar</packaging>
+
+    <name>{artifact_id}-common-{sub_module}</name>
+    <description>Common {sub_module.capitalize()} Module</description>
+</project>
+"""
+            (sub_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+        
+        # Common parent pom
+        common_pom = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-common</artifactId>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}-common</name>
+    <description>Common Modules</description>
+
+    <modules>
+        <module>{artifact_id}-common-domain</module>
+        <module>{artifact_id}-common-infrastructure</module>
+    </modules>
+</project>
+"""
+        (common_dir / "pom.xml").write_text(common_pom, encoding="utf-8")
+    
+    def _create_business_module(
+        self, project_path: Path, group_id: str, artifact_id: str,
+        version: str, package_base: str, module_name: str, architecture: str
+    ):
+        """Create business module with all layers"""
+        module_dir = project_path / f"{artifact_id}-{module_name}"
+        module_dir.mkdir(parents=True, exist_ok=True)
+        
+        layers = self._get_layers(architecture)
+        layer_suffixes = {
+            "interfaces": "adapter",
+            "application": "app",
+            "domain": "domain",
+            "infrastructure": "infrastructure",
+            "adapter": "adapter",
+            "app": "app"
+        }
+        
+        # Create sub-modules for each layer
+        for layer in layers:
+            layer_suffix = layer_suffixes.get(layer, layer)
+            sub_module_dir = module_dir / f"{artifact_id}-{module_name}-{layer_suffix}"
+            sub_module_dir.mkdir(parents=True, exist_ok=True)
+            
+            src_main_java = sub_module_dir / "src" / "main" / "java" / package_base.replace(".", "/") / module_name / layer
+            src_main_java.mkdir(parents=True, exist_ok=True)
+            self._create_package_info(src_main_java, f"{package_base}.{module_name}.{layer}")
+            
+            pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}-{module_name}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-{module_name}-{layer_suffix}</artifactId>
+    <packaging>jar</packaging>
+
+    <name>{artifact_id}-{module_name}-{layer_suffix}</name>
+    <description>{module_name.capitalize()} {layer.capitalize()} Layer</description>
+"""
+            if layer == "domain":
+                pom_content += f"""
+    <dependencies>
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-common-domain</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+    </dependencies>
+"""
+            elif layer == "infrastructure":
+                pom_content += f"""
+    <dependencies>
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-{module_name}-domain</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-common-infrastructure</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+    </dependencies>
+"""
+            elif layer in ["application", "app"]:
+                pom_content += f"""
+    <dependencies>
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-{module_name}-domain</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+    </dependencies>
+"""
+            elif layer in ["interfaces", "adapter"]:
+                pom_content += f"""
+    <dependencies>
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-{module_name}-app</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+    </dependencies>
+"""
+            
+            pom_content += "</project>\n"
+            (sub_module_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+        
+        # Module parent pom
+        module_list = "\n".join(
+            f"        <module>{artifact_id}-{module_name}-{layer_suffixes.get(layer, layer)}</module>"
+            for layer in layers
+        )
+        module_pom = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-{module_name}</artifactId>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}-{module_name}</name>
+    <description>{module_name.capitalize()} Business Module</description>
+
+    <modules>
+{module_list}
+    </modules>
+</project>
+"""
+        (module_dir / "pom.xml").write_text(module_pom, encoding="utf-8")
+    
+    def _create_start_module(
+        self, project_path: Path, group_id: str, artifact_id: str,
+        version: str, package_base: str, modules: List[str]
+    ):
+        """Create start module"""
+        start_dir = project_path / f"{artifact_id}-start"
+        start_dir.mkdir(parents=True, exist_ok=True)
+        
+        src_main_java = start_dir / "src" / "main" / "java" / package_base.replace(".", "/")
+        src_main_java.mkdir(parents=True, exist_ok=True)
+        
+        app_class_name = self._to_class_name(artifact_id)
+        self._create_application_class(src_main_java, package_base, app_class_name)
+        
+        src_main_resources = start_dir / "src" / "main" / "resources"
+        src_main_resources.mkdir(parents=True, exist_ok=True)
+        (src_main_resources / "application.yml").write_text("spring:\n  application:\n    name: " + artifact_id + "\n", encoding="utf-8")
+        
+        # Dependencies on all business modules
+        dependencies = "\n".join(
+            f"""        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-{module}-adapter</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>"""
+            for module in modules
+        )
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{artifact_id}-start</artifactId>
+    <packaging>jar</packaging>
+
+    <name>{artifact_id}-start</name>
+    <description>Application Start Module</description>
+
+    <dependencies>
+{dependencies}
+        <dependency>
+            <groupId>{group_id}</groupId>
+            <artifactId>{artifact_id}-common-infrastructure</artifactId>
+            <version>${{project.version}}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+"""
+        (start_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_microservices_parent_pom(
+        self, project_path: Path, group_id: str, artifact_id: str,
+        version: str, parent_version: str, services: List[str]
+    ):
+        """Create parent pom.xml for microservices project"""
+        service_modules = "\n".join(f"        <module>services/{service}</module>" for service in services)
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>ddd4j-cloud-parent</artifactId>
+        <version>{parent_version}</version>
+        <relativePath/>
+    </parent>
+
+    <groupId>{group_id}</groupId>
+    <artifactId>{artifact_id}</artifactId>
+    <version>{version}</version>
+    <packaging>pom</packaging>
+
+    <name>{artifact_id}</name>
+    <description>DDD Microservices Platform</description>
+
+    <modules>
+        <module>platform-common</module>
+{service_modules}
+        <module>gateway</module>
+    </modules>
+
+    <properties>
+        <java.version>17</java.version>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+</project>
+"""
+        (project_path / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_platform_common(self, project_path: Path, group_id: str, artifact_id: str, version: str, package_base: str):
+        """Create platform-common module"""
+        common_dir = project_path / "platform-common"
+        common_dir.mkdir(parents=True, exist_ok=True)
+        
+        src_main_java = common_dir / "src" / "main" / "java" / package_base.replace(".", "/") / "common"
+        src_main_java.mkdir(parents=True, exist_ok=True)
+        self._create_package_info(src_main_java, f"{package_base}.common")
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>platform-common</artifactId>
+    <packaging>jar</packaging>
+
+    <name>platform-common</name>
+    <description>Platform Common Module</description>
+</project>
+"""
+        (common_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+    
+    def _create_service(
+        self, services_dir: Path, group_id: str, artifact_id: str,
+        version: str, package_base: str, service_name: str, architecture: str
+    ):
+        """Create microservice with all modules"""
+        service_dir = services_dir / service_name
+        service_dir.mkdir(parents=True, exist_ok=True)
+        
+        layers = self._get_layers(architecture)
+        service_modules = ["api", "domain", "application", "infrastructure", "interfaces", "start"]
+        
+        for module_suffix in service_modules:
+            module_dir = service_dir / f"{service_name}-{module_suffix}"
+            module_dir.mkdir(parents=True, exist_ok=True)
+            
+            if module_suffix == "start":
+                src_main_java = module_dir / "src" / "main" / "java" / package_base.replace(".", "/") / service_name.replace("-service", "")
+                src_main_java.mkdir(parents=True, exist_ok=True)
+                app_class_name = self._to_class_name(service_name.replace("-service", ""))
+                self._create_application_class(src_main_java, f"{package_base}.{service_name.replace('-service', '')}", app_class_name)
+            else:
+                src_main_java = module_dir / "src" / "main" / "java" / package_base.replace(".", "/") / service_name.replace("-service", "") / module_suffix
+                src_main_java.mkdir(parents=True, exist_ok=True)
+                self._create_package_info(src_main_java, f"{package_base}.{service_name.replace('-service', '')}.{module_suffix}")
+            
+            pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{service_name}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{service_name}-{module_suffix}</artifactId>
+    <packaging>jar</packaging>
+
+    <name>{service_name}-{module_suffix}</name>
+    <description>{service_name} {module_suffix.capitalize()} Module</description>
+"""
+            if module_suffix == "start":
+                pom_content += """
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>${service-name}-interfaces</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>${service-name}-application</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>${service-name}-infrastructure</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>platform-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+"""
+            
+            pom_content += "</project>\n"
+            (module_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+        
+        # Service parent pom
+        module_list = "\n".join(f"        <module>{service_name}-{module}</module>" for module in service_modules)
+        service_pom = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>{service_name}</artifactId>
+    <packaging>pom</packaging>
+
+    <name>{service_name}</name>
+    <description>{service_name.replace('-', ' ').title()} Microservice</description>
+
+    <modules>
+{module_list}
+    </modules>
+</project>
+"""
+        (service_dir / "pom.xml").write_text(service_pom, encoding="utf-8")
+    
+    def _create_gateway(self, project_path: Path, group_id: str, artifact_id: str, version: str, package_base: str):
+        """Create gateway service"""
+        gateway_dir = project_path / "gateway"
+        gateway_dir.mkdir(parents=True, exist_ok=True)
+        
+        start_dir = gateway_dir / "gateway-start"
+        start_dir.mkdir(parents=True, exist_ok=True)
+        
+        src_main_java = start_dir / "src" / "main" / "java" / package_base.replace(".", "/") / "gateway"
+        src_main_java.mkdir(parents=True, exist_ok=True)
+        
+        app_class = src_main_java / "GatewayApplication.java"
+        content = f"""package {package_base}.gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Gateway Application
+ */
+@SpringBootApplication
+public class GatewayApplication {{
+
+    public static void main(String[] args) {{
+        SpringApplication.run(GatewayApplication.class, args);
+    }}
+}}
+"""
+        app_class.write_text(content, encoding="utf-8")
+        
+        pom_content = f"""<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>{group_id}</groupId>
+        <artifactId>{artifact_id}</artifactId>
+        <version>{version}</version>
+    </parent>
+
+    <artifactId>gateway</artifactId>
+    <packaging>pom</packaging>
+
+    <name>gateway</name>
+    <description>API Gateway Service</description>
+
+    <modules>
+        <module>gateway-start</module>
+    </modules>
+</project>
+"""
+        (gateway_dir / "pom.xml").write_text(pom_content, encoding="utf-8")
+
+
+def main():
+    """Main entry point"""
+    if len(sys.argv) < 2:
+        print("Usage: init_project.py <project-type> [options]", file=sys.stderr)
+        print("Project types: single-module, multi-module, microservices", file=sys.stderr)
+        sys.exit(1)
+    
+    project_type = sys.argv[1]
+    
+    # Parse configuration from JSON or command line
+    if len(sys.argv) >= 3:
+        config = json.loads(sys.argv[2])
+    else:
+        # Default configuration
+        config = {
+            "groupId": "io.ddd4j.base",
+            "artifactId": "ddd4j-project",
+            "version": "1.0.0-SNAPSHOT",
+            "parentVersion": "2023.0.x.20251205-SNAPSHOT",
+            "packageBase": "io.ddd4j.project",
+            "architecture": "ddd-classic"
+        }
+    
+    initializer = DDDProjectInitializer()
+    
+    if project_type == "single-module":
+        result = initializer.init_single_module(
+            config["groupId"],
+            config["artifactId"],
+            config["version"],
+            config["parentVersion"],
+            config["packageBase"],
+            config.get("architecture", "ddd-classic")
+        )
+        print(json.dumps({"status": "success", "path": result}))
+    
+    elif project_type == "multi-module":
+        modules = config.get("modules", ["api"])
+        result = initializer.init_multi_module(
+            config["groupId"],
+            config["artifactId"],
+            config["version"],
+            config["parentVersion"],
+            config["packageBase"],
+            modules,
+            config.get("architecture", "ddd-classic")
+        )
+        print(json.dumps({"status": "success", "path": result}))
+    
+    elif project_type == "microservices":
+        services = config.get("services", ["user-service", "order-service"])
+        result = initializer.init_microservices(
+            config["groupId"],
+            config["artifactId"],
+            config["version"],
+            config["parentVersion"],
+            config["packageBase"],
+            services,
+            config.get("architecture", "ddd-classic")
+        )
+        print(json.dumps({"status": "success", "path": result}))
+    
+    else:
+        print(json.dumps({"status": "error", "message": f"Unknown project type: {project_type}"}), file=sys.stderr)
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()