Java COLA architecture guide - Alibaba COLA clean, layered architecture framework. For Java/Spring Boot projects it provides DDD layered design, code structure conventions, and application architecture refactoring. Trigger conditions: COLA, Java DDD, Spring Boot architecture, layered architecture, clean architecture, hexagonal architecture, onion architecture, code layering, module partitioning, Gateway pattern, Repository pattern, CQRS, architecture refactoring, separation of responsibilities, Maven multi-module. Automatically applies COLA directory structure and naming conventions when creating Java files.
COLA = Clean Object-Oriented and Layered Architecture(整洁面向对象分层架构)
┌─────────────────────────────────────┐
Driving Adapter: │ 浏览器 │ 定时器 │ 消息队列 │
└─────────────────────────────────────┘
↓
VO ←─────────────── ┌─────────────────────────────────────┐
(View Object) │ Adapter 层 │
│ controller │ scheduler │ consumer │
└─────────────────────────────────────┘
↓
DTO ←────────────── ┌─────────────────────────────────────┐
(Data Transfer │ App 层 │
Object) │ service │ executor │
└─────────────────────────────────────┘
↓
Entity ←─────────── ┌─────────────────────────────────────┐
│ Domain 层 │
│ gateway │ model │ ability │
└─────────────────────────────────────┘
↑
DO ←─────────────── ┌─────────────────────────────────────┐
(Data Object) │ Infrastructure 层 │
│ gatewayImpl │ mapper │ config │
└─────────────────────────────────────┘
↓
Driven Adapter: │ DB │ Search │ RPC │
Adapter → App → Domain ← Infrastructure
↘ ↙
Client
| 层 | 职责 | 实现 | |---|------|------| | Adapter | 接收外部请求 | Controller, Scheduler, Consumer | | App | 用例编排 | ServiceImpl, CmdExe, QryExe | | Domain | 核心业务逻辑 | Entity, ValueObject, Gateway, Ability | | Infrastructure | 技术实现 | GatewayImpl, Mapper, Config | | Client | DTO 定义 | Command, Query, CO, ServiceI |
project-name/
├── project-adapter/ # Controller
│ └── com/company/project/web/
├── project-app/ # Service 实现
│ └── com/company/project/
│ ├── command/ # *CmdExe.java
│ │ └── query/ # *QryExe.java
│ └── service/ # *ServiceImpl.java
├── project-client/ # API 定义
│ └── com/company/project/
│ ├── api/ # *ServiceI.java
│ └── dto/
│ ├── command/ # *Cmd.java
│ ├── query/ # *Qry.java
│ └── clientobject/ # *CO.java
├── project-domain/ # 领域层
│ └── com/company/project/domain/
│ ├── {aggregate}/ # Entity, ValueObject
│ └── gateway/ # *Gateway.java
├── project-infrastructure/ # 基础设施
│ └── com/company/project/
│ ├── gatewayimpl/ # *GatewayImpl.java
│ └── convertor/ # *Convertor.java
└── start/ # 启动模块
| 类型 | 后缀 | 位置 |
|------|------|------|
| 命令 | Cmd | client/dto/command |
| 查询 | Qry | client/dto/query |
| 命令执行器 | CmdExe | app/command |
| 查询执行器 | QryExe | app/command/query |
| 客户端对象 | CO | client/dto/clientobject |
| 数据对象 | DO | infrastructure |
| 服务接口 | ServiceI | client/api |
| 服务实现 | ServiceImpl | app/service |
| 网关接口 | Gateway | domain/gateway |
| 网关实现 | GatewayImpl | infrastructure/gatewayimpl |
| 转换器 | Convertor | infrastructure/convertor |
COLA 提供两种 Archetype:
适用于 Adapter 和后端服务一体的 Web 应用:
mvn archetype:generate \
-DgroupId=com.company.project \
-DartifactId=my-web-app \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.company.project \
-DarchetypeArtifactId=cola-framework-archetype-web \
-DarchetypeGroupId=com.alibaba.cola \
-DarchetypeVersion=5.0.0
生成结构:
my-web-app/
├── my-web-app-adapter/ # Controller、定时任务、消息监听
├── my-web-app-app/ # Service 实现、执行器
├── my-web-app-client/ # API 接口、DTO
├── my-web-app-domain/ # 领域模型、Gateway 接口
├── my-web-app-infrastructure/ # Gateway 实现、Mapper
└── start/ # 启动模块
适用于纯后端服务(无 Web 层):
mvn archetype:generate \
-DgroupId=com.company.project \
-DartifactId=my-service \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.company.project \
-DarchetypeArtifactId=cola-framework-archetype-service \
-DarchetypeGroupId=com.alibaba.cola \
-DarchetypeVersion=5.0.0
生成结构:
my-service/
├── my-service-app/ # Service 实现、执行器
├── my-service-client/ # API 接口、DTO(供其他服务调用)
├── my-service-domain/ # 领域模型、Gateway 接口
├── my-service-infrastructure/ # Gateway 实现、Mapper
└── start/ # 启动模块
| 组件 | 功能 |
|------|------|
| cola-component-dto | Response, Command, Query, PageResponse |
| cola-component-exception | BizException, SysException, ErrorCode |
| cola-component-catchlog-starter | @CatchAndLog 异常捕获和日志 |
| cola-component-extension-starter | 扩展点机制(多业务线支持) |
| cola-component-statemachine | 状态机(订单流转等) |
| cola-component-domain-starter | Spring 托管领域实体 |
| cola-component-ruleengine | 规则引擎 |
| cola-component-test-container | 测试容器 |
详细代码示例请参考:
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer