|
| 1 | +--- |
| 2 | +name: backend-systems-guidance |
| 3 | +description: Canonical overlay for server-side networked code that needs stronger architecture, testing, reliability, and security discipline. Use alongside the repo's implementation skill when implementing or reviewing backend services, APIs, middleware, queues, repositories, or backend refactors. |
| 4 | +--- |
| 5 | + |
| 6 | +# Backend Systems Guidance |
| 7 | + |
| 8 | +This is a composable overlay, not a standalone workflow. |
| 9 | +Use alongside the repo's implementation skill when the change touches backend |
| 10 | +code. |
| 11 | + |
| 12 | +This is the canonical backend overlay in this repo. |
| 13 | +It extends the thin baseline `backend-guidance` overlay with stronger guidance |
| 14 | +for non-trivial service boundaries, repositories, reliability, and trust |
| 15 | +boundaries. |
| 16 | + |
| 17 | +Prefer it over `backend-guidance` when the task includes new endpoints or |
| 18 | +consumers, multi-layer refactors, repository or transaction work, auth or |
| 19 | +trust-boundary logic, or backend review that needs explicit testing and |
| 20 | +reliability checks. |
| 21 | + |
| 22 | +Use the bundled references only when needed: |
| 23 | + |
| 24 | +- [references/trigger-evals.md](references/trigger-evals.md) for lightweight |
| 25 | + prompt checks when revising the trigger or scope |
| 26 | + |
| 27 | +## When to use |
| 28 | + |
| 29 | +- the repo has server-side networked code such as HTTP handlers, gRPC methods, |
| 30 | + webhooks, queue consumers, or message producers |
| 31 | +- the task adds or reshapes routes, controllers, services, repositories, |
| 32 | + middleware, or request-processing boundaries |
| 33 | +- the task changes auth, authorization, validation, idempotency, retries, |
| 34 | + external requests, caching, or observability |
| 35 | +- the task needs backend review beyond basic handler thinness, especially for |
| 36 | + security, data access, or missing tests |
| 37 | + |
| 38 | +## Not for |
| 39 | + |
| 40 | +- HTTP client code, CLI tooling, offline batch scripts, or data pipelines with |
| 41 | + no request or consumer boundary |
| 42 | +- frontend-only work |
| 43 | +- threat modeling or security audit work where `security` should be the primary |
| 44 | + workflow skill |
| 45 | + |
| 46 | +Do not fold infrastructure deployment workflows, outbound-client-only guidance, |
| 47 | +or full security-audit checklists into this skill. Keep this overlay centered |
| 48 | +on backend request and consumer systems plus their immediate reliability and |
| 49 | +trust boundaries. |
| 50 | + |
| 51 | +## Core workflow |
| 52 | + |
| 53 | +1. Read the touched backend files and map the request or consumer path end to |
| 54 | + end: boundary, service logic, data access, external calls, and state |
| 55 | + changes. |
| 56 | +2. Pick the mode before changing code: |
| 57 | + - baseline backend change when the work is mostly a thin handler or small |
| 58 | + service fix |
| 59 | + - service-boundary change when responsibilities, data access, or dependency |
| 60 | + direction may need to move |
| 61 | + - reliability-hardening or review mode when the main risk is missing tests, |
| 62 | + auth gaps, retries, observability, or unsafe failure handling |
| 63 | +3. Keep the boundary thin: decode input, authenticate and authorize, validate, |
| 64 | + call a service, map transport errors, and serialize output. Business |
| 65 | + decisions belong in service code that can run without the transport layer. |
| 66 | +4. Place persistence and external integrations deliberately: |
| 67 | + - repositories or data adapters own query shape, batching, and transaction |
| 68 | + details when that improves clarity or testing |
| 69 | + - services coordinate business rules, idempotency, retries, and side-effect |
| 70 | + ordering |
| 71 | + - handlers and controllers do not reach directly into ORM or network clients |
| 72 | + unless the change is truly trivial and stays trivial |
| 73 | +5. Harden cross-cutting concerns at the edge: |
| 74 | + - validate external input once at the boundary |
| 75 | + - enforce auth and authorization before business actions |
| 76 | + - set timeouts, retry rules, and destination allowlists for outbound calls |
| 77 | + - use structured logging, correlation identifiers, and explicit error |
| 78 | + mapping for observable failure paths |
| 79 | +6. Choose the smallest test set that proves the change: |
| 80 | + - unit tests for service logic and decision branches |
| 81 | + - integration tests for handlers, consumers, repositories, and transaction |
| 82 | + behavior |
| 83 | + - auth and permission tests for protected flows |
| 84 | + - contract or schema tests when the change alters external API or event |
| 85 | + shapes |
| 86 | + - load or concurrency tests only for changed hotspots, queue throughput, or |
| 87 | + latency-sensitive paths |
| 88 | +7. Review the result for boundary leaks, unsafe defaults, data-access |
| 89 | + inefficiency, and missing verification before finishing. |
| 90 | + |
| 91 | +## Decision rules |
| 92 | + |
| 93 | +- Start with `backend-guidance` for ordinary backend edits. Use this overlay |
| 94 | + when the task needs stronger design pressure, harder review, or explicit |
| 95 | + backend quality gates. |
| 96 | +- Keep handlers thin in responsibility, not by literal line count. If a |
| 97 | + handler or consumer owns business decisions, retries, transaction branching, |
| 98 | + or query orchestration, extract inward. |
| 99 | +- Keep business logic transport-free. If testing a rule requires booting HTTP, |
| 100 | + gRPC, or queue infrastructure, the logic is in the wrong place. |
| 101 | +- Add a repository or data-access interface when it reduces duplication, |
| 102 | + isolates non-trivial queries, helps transaction composition, or makes tests |
| 103 | + materially simpler. Do not add one for single-call trivial CRUD. |
| 104 | +- Prefer one validation pass at the outer edge plus typed internal data. Avoid |
| 105 | + repeated validation in every layer unless a trust boundary changes. |
| 106 | +- Treat retries as a design choice, not a default. Only retry idempotent or |
| 107 | + explicitly deduplicated work, and pair retries with deadlines or backoff. |
| 108 | +- Use idempotency keys or duplicate-detection for retried creates, webhook |
| 109 | + handlers, and queue consumers that can be re-delivered. |
| 110 | +- Every outbound request needs a timeout and failure policy. For user-controlled |
| 111 | + destinations, apply allowlists or equivalent SSRF protections. |
| 112 | +- Keep error handling explicit: domain code returns or throws domain-level |
| 113 | + failures; boundary code maps them to HTTP, gRPC, queue, or job semantics. |
| 114 | +- Measure before adding caching. Cache only stable read paths with clear |
| 115 | + invalidation or bounded staleness. |
| 116 | + |
| 117 | +## Validation |
| 118 | + |
| 119 | +A backend change is done when, in addition to the base implementation skill's |
| 120 | +validation: |
| 121 | + |
| 122 | +- handlers or consumers stay as boundary glue and delegate business decisions to |
| 123 | + testable service code |
| 124 | +- data access and external I/O live behind clear seams when the change is |
| 125 | + non-trivial |
| 126 | +- external input, auth, and transport-specific error mapping stay at the edge |
| 127 | +- retries, idempotency, timeouts, and failure handling are explicit where the |
| 128 | + change can duplicate work or call remote systems |
| 129 | +- tests cover the changed behavior at the correct level, including integration |
| 130 | + coverage for boundary behavior and permission or failure cases when relevant |
| 131 | +- new high-risk paths emit enough evidence to debug production behavior |
0 commit comments