Agent skill
create-api-module
Creates a new API module following Clean Architecture with TDD. Use when adding new API endpoints, creating backend features, implementing domain entities, or when the user says "create module", "add endpoint", "new backend feature".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/create-api-module
SKILL.md
Create API Module
Creates a new backend module following Clean Architecture with API, Domain, and Infrastructure layers.
Workflow
- Create directory structure at
back/src/api/{module}/ - Create infrastructure layer: models, repository (interface + implementation), dependencies
- Create domain layer: business logic functions, exceptions
- Create API layer: router, schemas
- Register router in
back/src/api/routes.py - Create tests in
back/tests/api/{module}/ - Create migration:
docker compose exec back uv run alembic revision --autogenerate -m "Add {module} table"
Directory Structure
back/src/api/{module}/
├── api/
│ ├── router.py # FastAPI endpoints
│ └── schemas.py # Pydantic request/response models
├── domain/
│ ├── exception.py # Domain exceptions
│ └── {action}.py # Business logic functions
└── infrastructure/
├── models.py # SQLModel database models
├── repository.py # Repository interface + implementation
└── dependencies.py # FastAPI dependency injection
Quick Scaffold
Generate boilerplate structure:
python .claude/skills/create-api-module/scripts/scaffold_module.py {module_name}
Code Patterns
For detailed code patterns, see PATTERNS.md.
Real Examples
For complete working examples from this codebase, see EXAMPLES.md.
Important Conventions
- Table names: plural, lowercase (
items,users,notifications) - Model class names:
{Entity}Db(ItemDb,UserDb) - Router names:
{entity}_router(item_router,user_router) - Test names:
test_when_{condition}_then_{outcome} - Always use UUID for primary keys
- Soft delete: Use
deleted_atfield instead of hard delete - Type hints: Required everywhere, use
|for union types (notOptional)
After Creating Module
- Run tests:
uv run pytest tests/api/{module}/ -v - Format code:
task format - Create migration if needed
- Test endpoints via
/docslocally
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?