Add backend development

From brabos-ai/code-addiction · View interactive version

Add backend development is an AI agent skill from the GitHub repository brabos-ai/code-addiction. Backend API architecture: Clean Architecture, SOLID, DTOs, Services, Repositories, RESTful — stack-agnostic.

How to use this skill

Skill file

Backend Development

<!-- uses:

-->

Skill for backend API implementation following universal architectural principles.

Use for: Routes/Controllers, Services, DTOs, Domain logic, Data access, Error handling

Not for: Frontend (ux-design), Database migrations (database-development), Security (security-audit)

Stack resolution: Project conventions: follow {{addpath:wiki/conventions.md}} → ## Stack Conventions (+ {{addpath:wiki/domains/<area>.md}}); a one-line critical rule may live in AGENTS.md. If absent, apply the agnostic defaults and follow the nearest existing code; never impose tenancy, DI registration or barrels unless the project uses them. Apply these principles using the framework's idiomatic patterns. The AI already knows each framework's syntax — this skill teaches architecture, not framework tutorials.

Reference: Conventions come from the wiki first; AGENTS.md is the fallback for general project standards.


Project Conventions First

Read in this order: {{addpath:wiki/conventions.md}} → ## Stack Conventions (+ the area page under {{addpath:wiki/domains/<area>.md}}), then AGENTS.md ## Architecture Contract / ## Technical Spec for stack facts. In a tiny wiki the same table sits in {{addpath:wiki/index.md}} → ### Stack Conventions. A recorded row wins over the default below. A row that says none (or no, for Tenancy and Barrels) means the project does not use the thing: follow the nearest existing code.

Agnostic defaults, used only when nothing is recorded (the other dev skills link here and do not copy this list):


When NOT to Use


Clean Architecture

One common layering, given as an example. The project's own layering ({{addpath:wiki/architecture.md}} / row Layering) wins.

domain → application → infrastructure → presentation

| Layer | Allowed deps | Content |

|---|---|---|

| domain | zero | entities, value objects, enums, types, domain errors |

| application | domain only | service interfaces, use cases, DTOs |

| infrastructure | domain, application | repository implementations, external services, config |

| presentation | all | routes/controllers, middleware, error mapping |

Rules:


SOLID Principles


RESTful Standards

| Method | Use | Idempotent | Body | Status |

|---|---|---|---|---|

| GET | read | yes | no | 200 |

| POST | create | no | yes | 201 |

| PUT | full update | yes | yes | 200 |

| PATCH | partial | yes | yes | 200 |

| DELETE | remove | yes | no | 204 |

URL rules:

Do:

Don't:

Params:

Status codes:

| Code | Meaning |

|---|---|

| 200 | GET, PUT, PATCH ok |

| 201 | POST created |

| 204 | DELETE ok |

| 400 | validation |

| 401 | no auth |

| 403 | no permission |

| 404 | not found |

| 409 | conflict |


Dependency Injection / IoC

Principles:

Common DI errors (with a container): Unresolved dependency = not registered. Cross-module failure = not exported. Route 404 = module not loaded. Consult framework docs for idiomatic registration.


Naming Conventions

Follow the project's naming. The tables below are examples, not a mandate.

File naming (example, one stack):

| Type | Pattern |

|---|---|

| Controller / Route | kebab.controller.ts or kebab.routes.ts |

| Service | kebab.service.ts |

| Repository | PascalRepository.ts |

| Interface | IPascalRepository.ts |

| Entity | Pascal.ts |

| Enum | PascalCase.ts |

| DTO | PascalDto.ts |

Casing rules:

| Element | Casing |

|---|---|

| Files | kebab-case or PascalCase (follow project convention) |

| Classes | PascalCase |

| Interfaces | I + PascalCase (example; only if the project uses the prefix) |

| DB columns | snake_case |

| Variables | camelCase |

Paths and aliases: Follow the project's existing import aliases and directory structure. Do not invent new aliases — check the project's alias config (e.g. tsconfig.json paths) and existing code.


DTOs

DTO naming:

| Action | Pattern |

|---|---|

| create | Create[Entity]Dto |

| update | Update[Entity]Dto |

| patch | Patch[Entity]Dto |

| response | [Entity]ResponseDto |

| list | [Entity]ListResponseDto |

| query | [Entity]QueryDto |

Rules:


Services


Repository Pattern

Use a repository (and a mapper such as toEntity) only when the project already uses them or persistence naming differs from domain naming (row ORM / data access). Otherwise follow the project's data-access style.

When used:


Error Handling

| Layer | Responsibility |

|---|---|

| domain | Throw domain-specific errors (NotFoundError, BusinessRuleViolationError, ConflictError). No HTTP concepts. |

| application | Let domain errors propagate. Add application-level errors if needed (ValidationError). |

| presentation | Map domain/application errors to HTTP status codes. This is the ONLY layer that knows about HTTP. |

Error mapping:

| Domain | HTTP |

|---|---|

| NotFoundError | 404 |

| ValidationError | 400 |

| UnauthorizedError | 401 |

| ForbiddenError | 403 |

| ConflictError | 409 |

| BusinessRuleViolationError | 422 |

Rule: Services throw domain errors. The presentation layer (middleware, error handler, or framework mechanism) maps them to HTTP responses. Never import HTTP concepts into services.


Module / Feature Structure

Organize code by domain/feature, not by technical role. Each feature module contains its own controllers, services, DTOs, and domain logic. The tree below is one example layout; the project's structure wins.

[feature]/
├── dtos/
│   ├── Create[Feature]Dto.ts
│   ├── Update[Feature]Dto.ts
│   └── [Feature]ResponseDto.ts
├── [feature].controller.ts (or routes.ts)
├── [feature].service.ts
└── [feature].module.ts (or index.ts)

DDD-lite principles:


Multi-Tenancy

Only when row Tenancy = yes. Without it, do not add tenancy; raise it as a planning question instead.


Configuration

Rules:


KISS and YAGNI


Validation Checklist

RESTful Standards

Clean Architecture

Dependency Injection

DTOs

Error Handling

Multi-Tenancy

Configuration

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.