Python COLA architecture guide - adapts Alibaba's COLA (Clean Object‑Oriented and Layered Architecture) to Python/Flask/FastAPI projects. For Python backend DDD layered architecture design, code structure standards, and application architecture refactoring. Applicable scenarios: Python DDD, Flask architecture, FastAPI architecture, Python layered architecture, clean architecture, hexagonal architecture, onion architecture, COLA, code layering, module partitioning, Gateway pattern, Repository pattern, CQRS, architecture refactoring, separation of concerns. Automatically applies COLA directory structure and naming conventions when creating Python files.
COLA = Clean Object-Oriented and Layered Architecture(整洁面向对象分层架构)
Adapter → Application → Domain ← Infrastructure
↘ ↙
Client
| 层 | 职责 | Python 实现 | |---|------|------------| | Adapter | 接收外部请求 | Flask Blueprint / FastAPI Router | | Application | 用例编排 | Service, CmdExe, QryExe | | Domain | 核心业务逻辑 | Entity, ValueObject, Gateway 接口 | | Infrastructure | 技术实现 | Gateway 实现, SQLAlchemy | | Client | DTO 定义 | Command, Query, CO |
project/
├── adapter/routes/ # Flask Blueprint
├── application/
│ ├── command/ # *_cmd_exe.py
│ ├── query/ # *_qry_exe.py
│ └── service/ # *_service.py
├── client/
│ ├── api/ # *_service_i.py (Protocol)
│ └── dto/
│ ├── command/ # *_cmd.py
│ ├── query/ # *_qry.py
│ └── co/ # *_co.py
├── domain/
│ ├── {aggregate}/ # entity.py, value_object.py
│ └── gateway/ # *_gateway.py (ABC)
├── infrastructure/
│ ├── gateway_impl/ # *_gateway_impl.py
│ ├── convertor/ # *_convertor.py
│ └── repository/ # models.py
└── app.py
| 类型 | 后缀 | 位置 |
|------|------|------|
| 命令 | _cmd | client/dto/command |
| 查询 | _qry | client/dto/query |
| 命令执行器 | _cmd_exe | application/command |
| 查询执行器 | _qry_exe | application/query |
| 客户端对象 | _co | client/dto/co |
| 服务接口 | _service_i | client/api |
| 服务实现 | _service | application/service |
| 网关接口 | _gateway | domain/gateway |
| 网关实现 | _gateway_impl | infrastructure/gateway_impl |
| 转换器 | _convertor | infrastructure/convertor |
详细代码示例请参考:
| Java | Python |
|------|--------|
| interface | Protocol 或 ABC |
| @Autowired | 构造函数注入 |
| @CatchAndLog | @catch_and_log 装饰器 |
| @Data | @dataclass |
| @RestController | Flask Blueprint |
npx skills add jackjin1997/python-cola-skill下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
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