Backend Engineering Workflow
Repository planning gate
When this repository's CLAUDE.md classifies the request as complex or high-impact, the primary agent must invoke plan-tasks before entering this workflow's Inspect or Plan phase. A subagent must return control to the primary agent rather than create a competing plan or edit target files. Resume this workflow only after an approved docs/plans/PLAN_<descriptive-name>.md maps the relevant A-* to backend-engineering-workflow, its assigned role, worktree isolation, and verification. This skill's seven phases implement an approved action; they never replace user approval.
Use this skill for backend implementation, backend setup, API construction, optimization, detection, refactoring, and rewriting.
Follow seven phases:
- Inspect
- Diagnose
- Plan
- Contract
- Implement
- Verify
- Report
Backend changes affect data, security, runtime behavior, and client contracts. Ground decisions in project files, schemas, tests, local conventions, official documentation, or explicit user confirmation.
Resource Guide
Load these references only when needed:
references/project-recon.md: Use during Inspect to identify framework, runtime, commands, routes, tests, database, auth, and docs.
references/task-diagnosis.md: Use during Diagnose to classify the task as build, feature, API, bug, optimization, security, refactor, rewrite, or tests.
references/api-development.md: Use for endpoint-focused REST, GraphQL, RPC, controller, route, request/response, OpenAPI, or HTTP verification work.
references/api-contract.md: Use whenever the task changes API behavior, request/response schemas, auth, status codes, or side effects.
references/implementation-patterns.md: Use during Implement for layering, validation, errors, logging, external calls, docs, and dependency rules.
references/optimization-workflow.md: Use for performance, query, memory, latency, throughput, cache, or N+1 work.
references/rewrite-workflow.md: Use for refactors and rewrites that must preserve behavior.
references/security-review.md: Use whenever auth, user data, tenant boundaries, files, webhooks, secrets, payment, or external services are involved.
references/database-and-migrations.md: Use whenever models, schema, migrations, indexes, transactions, queries, or data shape are involved.
references/testing-strategy.md: Use when adding or choosing tests.
references/verification-checklist.md: Use during Verify and before final response.
Use these scripts as black-box helpers. Run each with --help before use:
scripts/inspect_backend.py: Project reconnaissance report in JSON.
scripts/verify_api.py: Generic HTTP smoke checks for local or remote endpoints.
scripts/scan_backend_risks.py: Static scan for common backend risk patterns.
scripts/benchmark_endpoint.py: Basic endpoint latency benchmark for optimization work.
For high-risk backend changes, use the discoverable project subagents in .claude/agents/ when available:
api-contract-reviewer
security-reviewer
test-coverage-reviewer
They are read-only reviewers. Run them in parallel when their inputs are independent, then address their findings before final verification. The legacy prompt copies in this skill's agents/ folder are retained only as reference material; the root .claude/agents/ definitions are canonical.
Phase 1: Inspect
Inspect before editing. Do not guess the framework, ORM, auth system, route layout, validation library, test command, or deployment shape.
Find:
- Runtime, language, framework, and package manager
- App entrypoint, route/controller/resolver layout, and service layers
- Database/ORM schema, migrations, repositories, and generated types
- Auth middleware, guards, policies, roles, tenant scoping, and session/current-user handling
- Validation and serialization patterns
- Error response shape and logging conventions
- Existing tests and fixtures
- Build, typecheck, lint, test, and dev server commands
- API documentation or schema generation
Run scripts/inspect_backend.py for a first pass, then read the relevant files it identifies. For detailed guidance, read references/project-recon.md.
Phase 2: Diagnose
Classify the task before planning. Determine whether it is:
- Backend setup or new service construction
- Feature implementation
- API addition or modification
- Bug investigation and fix
- Performance optimization
- Security hardening
- Refactor
- Rewrite
- Test coverage improvement
- Documentation or schema update
The task type changes the workflow. For example, bug fixes need reproduction, optimizations need baseline measurements, and rewrites need behavior-locking tests.
For endpoint-focused API work, load references/api-development.md after diagnosis and use it with references/api-contract.md.
For detailed guidance, read references/task-diagnosis.md.
Phase 3: Plan
Choose the smallest implementation path that satisfies the request.
Plan:
- Files likely to change
- Behavior that must remain unchanged
- Contracts or schemas that must be updated
- Tests needed
- Verification commands
- Risks and facts that still need confirmation
Prefer existing patterns. Avoid broad refactors, new dependencies, framework swaps, or unrelated style churn.
Phase 4: Contract
Use a contract phase whenever the work touches an API, database behavior, permission rule, external side effect, background job, or public module behavior.
Define:
- Inputs
- Outputs
- Validation
- Errors
- Auth and permission rules
- Database reads and writes
- Side effects
- Backward compatibility
- Tests and verification
For API work, read references/api-contract.md.
Phase 5: Implement
Implement according to the contract and local codebase style.
Rules:
- Reuse local framework, routing, validation, error, logging, service, repository, and test patterns.
- Keep business logic in the layer where the project already puts it.
- Validate all user-controlled inputs.
- Use existing auth and permission mechanisms.
- Preserve public behavior unless the user requested a breaking change.
- Use transactions for multi-step writes that must remain consistent.
- Avoid raw SQL string interpolation.
- Avoid leaking secrets, stack traces, tokens, or private data.
- Add or update focused tests when a test path exists.
Load the relevant reference files for the task type.
Phase 6: Verify
Do not finish after writing code. Verify with the strongest checks available.
Run applicable commands:
- Typecheck or compile
- Lint or format check
- Unit tests
- Integration or route tests
- Build
- API schema generation
- HTTP smoke checks
- Risk scan
- Benchmark when optimizing
Use scripts/verify_api.py for generic HTTP checks and scripts/scan_backend_risks.py for risk scanning. Use scripts/benchmark_endpoint.py only when measuring endpoint performance.
For detailed guidance, read references/verification-checklist.md.
Phase 7: Report
Final response should include:
- What changed
- Key files touched
- Contract or behavior summary
- Tests and checks run
- HTTP or benchmark verification run, if applicable
- Any checks that could not run and why
- Remaining risks or facts that could not be confirmed
Keep the response concise and factual.
1---2name: backend-engineering-workflow3description: End-to-end backend engineering workflow for building backend services, creating, modifying, optimizing, debugging, testing, and documenting server endpoints, detecting backend risks, refactoring or rewriting backend code, and verifying server behavior. Use when the user asks to build a backend, create a server, implement backend features, add or adjust REST APIs, GraphQL resolvers, RPC handlers, controllers, routes, request validation, response schemas, authentication, authorization, pagination, filtering, sorting, OpenAPI/Swagger specs, backend integration tests, performance/error handling, database logic, or backend quality hardening. Do NOT use for frontend-only work, deployment-only tasks with no backend code change, database-only analysis with no service change, or high-level architecture discussion with no implementation.4---56# Backend Engineering Workflow78## Repository planning gate910When this repository's `CLAUDE.md` classifies the request as complex or high-impact, the primary agent must invoke `plan-tasks` before entering this workflow's Inspect or Plan phase. A subagent must return control to the primary agent rather than create a competing plan or edit target files. Resume this workflow only after an approved `docs/plans/PLAN_<descriptive-name>.md` maps the relevant `A-*` to `backend-engineering-workflow`, its assigned role, worktree isolation, and verification. This skill's seven phases implement an approved action; they never replace user approval.1112Use this skill for backend implementation, backend setup, API construction, optimization, detection, refactoring, and rewriting.1314Follow seven phases:15161. Inspect172. Diagnose183. Plan194. Contract205. Implement216. Verify227. Report2324Backend changes affect data, security, runtime behavior, and client contracts. Ground decisions in project files, schemas, tests, local conventions, official documentation, or explicit user confirmation.2526## Resource Guide2728Load these references only when needed:2930- `references/project-recon.md`: Use during Inspect to identify framework, runtime, commands, routes, tests, database, auth, and docs.31- `references/task-diagnosis.md`: Use during Diagnose to classify the task as build, feature, API, bug, optimization, security, refactor, rewrite, or tests.32- `references/api-development.md`: Use for endpoint-focused REST, GraphQL, RPC, controller, route, request/response, OpenAPI, or HTTP verification work.33- `references/api-contract.md`: Use whenever the task changes API behavior, request/response schemas, auth, status codes, or side effects.34- `references/implementation-patterns.md`: Use during Implement for layering, validation, errors, logging, external calls, docs, and dependency rules.35- `references/optimization-workflow.md`: Use for performance, query, memory, latency, throughput, cache, or N+1 work.36- `references/rewrite-workflow.md`: Use for refactors and rewrites that must preserve behavior.37- `references/security-review.md`: Use whenever auth, user data, tenant boundaries, files, webhooks, secrets, payment, or external services are involved.38- `references/database-and-migrations.md`: Use whenever models, schema, migrations, indexes, transactions, queries, or data shape are involved.39- `references/testing-strategy.md`: Use when adding or choosing tests.40- `references/verification-checklist.md`: Use during Verify and before final response.4142Use these scripts as black-box helpers. Run each with `--help` before use:4344- `scripts/inspect_backend.py`: Project reconnaissance report in JSON.45- `scripts/verify_api.py`: Generic HTTP smoke checks for local or remote endpoints.46- `scripts/scan_backend_risks.py`: Static scan for common backend risk patterns.47- `scripts/benchmark_endpoint.py`: Basic endpoint latency benchmark for optimization work.4849For high-risk backend changes, use the discoverable project subagents in `.claude/agents/` when available:5051- `api-contract-reviewer`52- `security-reviewer`53- `test-coverage-reviewer`5455They are read-only reviewers. Run them in parallel when their inputs are independent, then address their findings before final verification. The legacy prompt copies in this skill's `agents/` folder are retained only as reference material; the root `.claude/agents/` definitions are canonical.5657## Phase 1: Inspect5859Inspect before editing. Do not guess the framework, ORM, auth system, route layout, validation library, test command, or deployment shape.6061Find:6263- Runtime, language, framework, and package manager64- App entrypoint, route/controller/resolver layout, and service layers65- Database/ORM schema, migrations, repositories, and generated types66- Auth middleware, guards, policies, roles, tenant scoping, and session/current-user handling67- Validation and serialization patterns68- Error response shape and logging conventions69- Existing tests and fixtures70- Build, typecheck, lint, test, and dev server commands71- API documentation or schema generation7273Run `scripts/inspect_backend.py` for a first pass, then read the relevant files it identifies. For detailed guidance, read `references/project-recon.md`.7475## Phase 2: Diagnose7677Classify the task before planning. Determine whether it is:7879- Backend setup or new service construction80- Feature implementation81- API addition or modification82- Bug investigation and fix83- Performance optimization84- Security hardening85- Refactor86- Rewrite87- Test coverage improvement88- Documentation or schema update8990The task type changes the workflow. For example, bug fixes need reproduction, optimizations need baseline measurements, and rewrites need behavior-locking tests.9192For endpoint-focused API work, load `references/api-development.md` after diagnosis and use it with `references/api-contract.md`.9394For detailed guidance, read `references/task-diagnosis.md`.9596## Phase 3: Plan9798Choose the smallest implementation path that satisfies the request.99100Plan:101102- Files likely to change103- Behavior that must remain unchanged104- Contracts or schemas that must be updated105- Tests needed106- Verification commands107- Risks and facts that still need confirmation108109Prefer existing patterns. Avoid broad refactors, new dependencies, framework swaps, or unrelated style churn.110111## Phase 4: Contract112113Use a contract phase whenever the work touches an API, database behavior, permission rule, external side effect, background job, or public module behavior.114115Define:116117- Inputs118- Outputs119- Validation120- Errors121- Auth and permission rules122- Database reads and writes123- Side effects124- Backward compatibility125- Tests and verification126127For API work, read `references/api-contract.md`.128129## Phase 5: Implement130131Implement according to the contract and local codebase style.132133Rules:134135- Reuse local framework, routing, validation, error, logging, service, repository, and test patterns.136- Keep business logic in the layer where the project already puts it.137- Validate all user-controlled inputs.138- Use existing auth and permission mechanisms.139- Preserve public behavior unless the user requested a breaking change.140- Use transactions for multi-step writes that must remain consistent.141- Avoid raw SQL string interpolation.142- Avoid leaking secrets, stack traces, tokens, or private data.143- Add or update focused tests when a test path exists.144145Load the relevant reference files for the task type.146147## Phase 6: Verify148149Do not finish after writing code. Verify with the strongest checks available.150151Run applicable commands:152153- Typecheck or compile154- Lint or format check155- Unit tests156- Integration or route tests157- Build158- API schema generation159- HTTP smoke checks160- Risk scan161- Benchmark when optimizing162163Use `scripts/verify_api.py` for generic HTTP checks and `scripts/scan_backend_risks.py` for risk scanning. Use `scripts/benchmark_endpoint.py` only when measuring endpoint performance.164165For detailed guidance, read `references/verification-checklist.md`.166167## Phase 7: Report168169Final response should include:170171- What changed172- Key files touched173- Contract or behavior summary174- Tests and checks run175- HTTP or benchmark verification run, if applicable176- Any checks that could not run and why177- Remaining risks or facts that could not be confirmed178179Keep the response concise and factual.