production-engineering-practices
Error-handling, security, logging and performance bar for production code. Use when writing or changing production code, before the run ends.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 122
- Forks
- 18
01 前言 Front Matter
- name
- production-engineering-practices
- category
- quality
- description
- Error-handling, security, logging and performance bar for production code. Use when writing or changing production code, before the run ends.
03 SKILL.md 正文
Production Engineering Practices
Overview
Acceptance criteria describe the happy path. Production is the unhappy paths: bad input, failed dependencies, concurrent access, hostile users. This skill is the non-negotiable bar every change clears in addition to its AC — the things a reviewer at code_review will bounce you for even when the feature "works."
Core principle: Code isn't done when it works; it's done when it fails safely, leaves a trace, and can't be abused.
The bar
Error handling
- No swallowed errors. Every error is either handled explicitly or propagated with context. An empty catch/
if err != nil { }that continues is a review-blocking defect. - Wrap with context at each layer so the log names where it broke:
fmt.Errorf("create task: %w", err). - User-facing errors are actionable and safe; internal detail (stack, ids) goes to logs, never to the client.
Logging & observability
- Log at the failure site with structured fields (entity id, operation, not free-text).
- Never log secrets, tokens, passwords, or full request bodies that may contain them.
- Log the decision, not the novel — one structured line beats ten prose lines.
Security
- Validate and bound every external input at the boundary: length, type, range, allowed set. Reject early.
- Secrets come from config/env — never hardcoded, never committed, never logged.
- A new endpoint/route gets the SAME auth/authorization guard as its neighbors. Copy the guard, don't omit it.
Performance
- No N+1 queries or requests — batch, join, preload, or cache. A loop issuing one call per row is a defect.
- Bound every result set: pagination or explicit limits on list endpoints and list views.
- Don't load unbounded data into memory; stream or page.
Per stack
| Stack | Adds |
|---|---|
| Backend | Parameterized queries only — no string-concatenated SQL, ever. |
| Web | No dangerouslySetInnerHTML / innerHTML with unsanitised data. Nothing secret in VITE_* / NEXT_PUBLIC_* — those ship to the browser. Every fetch has error and timeout/abort handling, and every route has an error boundary. No token in localStorage unless the repository already does it that way. |
| Mobile | Tokens in Keychain/Keystore (flutter_secure_storage), never in plain prefs. Explicit offline and timeout paths — a request with no network is a state, not a crash. No PII in logs. Permissions requested at the point of use, not on launch. |
Quick self-review before code_review
| Check | Pass condition |
|---|---|
| Errors | None swallowed; all wrapped with context |
| Input | Every external field validated and bounded |
| Secrets | None in code, logs, or commits |
| Auth | New endpoints/routes guarded like neighbors |
| Queries/requests | No N+1; result sets bounded |
| Tests | Behavior change ships with a test in this task |
Worked Example
Adding GET /projects/:id/tasks. The AC just says "return the project's tasks." The production bar adds:
- Validate
:idis a UUID → 400 on garbage, before any DB call. - The query filters by
project_idwith a bound parameter and aLIMIT/offset — notSELECT * FROM tasks. - The handler reuses the project's auth middleware so a user can't read another tenant's tasks.
- A structured log line on the DB error path with
project_id. - Tests: happy path, invalid id → 400, and the pagination bound.
The feature "worked" after the first bullet; it was done after all five.
Handoff
See your prompt's closing step for how to end the run — this skill only sets the bar the diff clears before you get there.
Red Flags
- "I'll add validation/error handling later" — later is the review bounce.
- A
catch/if err != nilblock that does nothing. - A list endpoint or list view with no limit.
- Copying an endpoint or screen but dropping its auth guard.
- A secret read from
VITE_*/NEXT_PUBLIC_*, or a token written to plain prefs on mobile.
04 同仓库更多 Skills
visual-craft
暂无简介
ux-copy
Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check
screen-mockup-html
Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task
performance-awareness
How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.
design-variants
Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision
design-system-authoring
Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns