|
| 1 | +--- |
| 2 | +name: typescript-bun-drizzle-quality |
| 3 | +description: Build or review Bun fullstack TypeScript code with Drizzle-backed SQL. Use for backend or cross-layer changes touching API/domain logic, schema or query design, migrations, runtime/type debugging, and boundary validation between contracts, business rules, and persistence. |
| 4 | +--- |
| 5 | + |
| 6 | +# TypeScript Bun Drizzle Quality |
| 7 | + |
| 8 | +Use this as an umbrella fullstack skill for Bun + TypeScript + Drizzle work. |
| 9 | + |
| 10 | +For slop-reduction/refactor passes focused on deleting custom helpers/types/assertions, use |
| 11 | +[`../desloppify/SKILL.md`](../desloppify/SKILL.md) alongside this skill. |
| 12 | + |
| 13 | +Deliver production-grade code by optimizing for: |
| 14 | + |
| 15 | +- type safety and clarity |
| 16 | +- predictable runtime behavior in Bun |
| 17 | +- correct and reversible data changes with Drizzle |
| 18 | +- clean contract boundaries between API, domain logic, and persistence |
| 19 | + |
| 20 | +## Repository Overrides (Required When Present) |
| 21 | + |
| 22 | +Always follow repository-level agent rules (for example `AGENTS.md`) when they are stricter than this skill. |
| 23 | + |
| 24 | +In this repository, enforce these defaults while using this skill: |
| 25 | + |
| 26 | +- keep things in one function unless extraction is clearly reusable |
| 27 | +- avoid `try`/`catch` where practical; prefer explicit control flow |
| 28 | +- avoid `else`; prefer early returns |
| 29 | +- avoid `any` and broad assertions |
| 30 | +- prefer single-word names when possible |
| 31 | +- avoid unnecessary destructuring; prefer dot access |
| 32 | +- prefer functional array methods over loops when practical |
| 33 | +- prefer Bun-native APIs like `Bun.file()` where practical |
| 34 | +- run tests from package directories, not repository root, when root test is guarded |
| 35 | + |
| 36 | +## Track Selection |
| 37 | + |
| 38 | +Choose the track before coding: |
| 39 | + |
| 40 | +1. App/API logic track |
| 41 | + - Use when changing handlers, services, orchestration, auth, or domain rules. |
| 42 | +2. Data layer track |
| 43 | + - Use when changing Drizzle schema, migrations, indexes, transactions, or query shape. |
| 44 | +3. Fullstack integration track |
| 45 | + - Use when changes cross boundaries (API contract + domain behavior + database effects). |
| 46 | + |
| 47 | +If multiple tracks apply, run App/API first, then Data layer, then Integration checks. |
| 48 | + |
| 49 | +## 1) Define Constraints First |
| 50 | + |
| 51 | +Before coding, pin down: |
| 52 | + |
| 53 | +- runtime: Bun version and package manager commands |
| 54 | +- database: SQL dialect (Postgres/MySQL/SQLite/Turso) and migration flow |
| 55 | +- API shape: request/response contracts and error model |
| 56 | +- compatibility: expected behavior changes vs strict backward compatibility |
| 57 | + |
| 58 | +If context is missing, ask only for blocking details. Otherwise proceed with explicit assumptions. |
| 59 | + |
| 60 | +## 2) Adapt to the Host Repository |
| 61 | + |
| 62 | +Distill practices into the target repository instead of assuming fixed commands or structure. |
| 63 | + |
| 64 | +Before implementation or review: |
| 65 | + |
| 66 | +- inspect workspace scripts to discover quality gates (typecheck, lint/format, test) |
| 67 | +- inspect CI workflows to confirm which checks are required in pull requests |
| 68 | +- identify local test taxonomy and map commands to: |
| 69 | + - unit tests |
| 70 | + - integration tests |
| 71 | + - e2e tests |
| 72 | +- run only the smallest relevant subset for touched code paths |
| 73 | + |
| 74 | +Do not assume naming conventions like `test:unit` or `test:e2e`; infer from scripts and workflow usage. |
| 75 | + |
| 76 | +## 3) Fullstack Testing with Bun (Required) |
| 77 | + |
| 78 | +Treat test design and test execution as first-class implementation work. |
| 79 | + |
| 80 | +Use this decision flow: |
| 81 | + |
| 82 | +1. classify repository test commands by behavior into unit, integration, and e2e |
| 83 | +2. map touched files/modules to the smallest package/service-local commands |
| 84 | +3. if root `test` is guarded (for example intentionally fails), do not run tests from root |
| 85 | +4. run required layers in order: unit -> integration -> e2e, based on scope/risk |
| 86 | +5. ensure CI-required checks for pull requests are represented in local verification |
| 87 | +6. if no explicit integration suite exists, treat boundary tests (API + real DB or equivalent) as integration coverage and call it out |
| 88 | + |
| 89 | +Technical expectations for Bun repositories: |
| 90 | + |
| 91 | +- use Bun test runner features intentionally (`bun test`, `--watch`, `--preload`, `--timeout`, path filters) |
| 92 | +- keep unit tests deterministic and fast; avoid network and global time randomness |
| 93 | +- for integration tests, run real migrations/schema setup and isolate test data |
| 94 | +- for e2e, run realistic app wiring and capture artifacts on failure |
| 95 | + |
| 96 | +Do not mark work complete unless one of these is true: |
| 97 | + |
| 98 | +- relevant tests were executed and results were recorded |
| 99 | +- execution was blocked by environment constraints and the block + residual risk were stated explicitly |
| 100 | + |
| 101 | +For deeper guidance, read `references/testing-patterns.md`. |
| 102 | +For copyable boundary snippets, read `references/examples/integration-boundary-test.md`. |
| 103 | + |
| 104 | +## 4) App/API Logic Track |
| 105 | + |
| 106 | +Prefer: |
| 107 | + |
| 108 | +- narrow, composable functions with explicit inputs and outputs |
| 109 | +- inferred types where clear, explicit types at boundaries (public functions, adapters, exported utilities) |
| 110 | +- discriminated unions for branching states |
| 111 | +- `unknown` + schema validation for untrusted input |
| 112 | +- early returns over deeply nested branching |
| 113 | + |
| 114 | +Avoid: |
| 115 | + |
| 116 | +- `any` unless unavoidable and scoped with justification |
| 117 | +- broad `as` assertions that bypass type checks |
| 118 | +- duplicated business logic between handlers, services, and tests |
| 119 | + |
| 120 | +Use Zod (or equivalent) to enforce runtime contracts at process boundaries. |
| 121 | +For copyable handler patterns, read `references/examples/api-boundary.md`. |
| 122 | + |
| 123 | +Use Bun-native patterns when they simplify runtime behavior: |
| 124 | + |
| 125 | +- file I/O: `Bun.file`, `Bun.write` |
| 126 | +- scripting and process execution: Bun shell APIs |
| 127 | +- tests and fixtures: Bun test runner patterns |
| 128 | + |
| 129 | +Keep Node compatibility shims only when required by dependencies or deployment targets. |
| 130 | + |
| 131 | +## 5) Data Layer Track |
| 132 | + |
| 133 | +When touching schema, models, or queries: |
| 134 | + |
| 135 | +- keep naming stable and consistent across schema and code |
| 136 | +- preserve backward compatibility unless migration plan explicitly breaks it |
| 137 | +- create reversible migrations where possible |
| 138 | +- include indexes/constraints intentionally, not implicitly |
| 139 | +- validate nullability/default changes against existing data |
| 140 | + |
| 141 | +For deeper patterns, read `references/drizzle-patterns.md`. |
| 142 | +For copyable transaction/query patterns, read `references/examples/drizzle-transaction.md`. |
| 143 | + |
| 144 | +## 6) Fullstack Integration Track |
| 145 | + |
| 146 | +When a change crosses boundaries, explicitly validate: |
| 147 | + |
| 148 | +- API contract to domain mapping (validation, defaults, and error translation) |
| 149 | +- domain rules to persistence behavior (transactions, consistency, rollback behavior) |
| 150 | +- persistence results to API output shape (including empty and partial data cases) |
| 151 | +- backward compatibility for clients and existing data |
| 152 | +- corresponding test coverage across unit/integration/e2e layers where applicable |
| 153 | + |
| 154 | +Use the review rubric in `references/quality-checklist.md` to structure findings. |
| 155 | +For end-to-end mapping examples, read `references/examples/fullstack-flow.md`. |
| 156 | + |
| 157 | +## Output Format |
| 158 | + |
| 159 | +Use this as the canonical output template for this skill: |
| 160 | + |
| 161 | +1. What changed and why |
| 162 | +2. Risk assessment (behavioral, data, performance) |
| 163 | +3. Verification performed or intentionally skipped |
| 164 | +4. Required fixes vs optional improvements |
| 165 | +5. Remaining gaps or follow-ups |
| 166 | + |
| 167 | +Keep output concise and concrete. Avoid generic "looks good" conclusions without evidence. |
| 168 | + |
| 169 | +## Canonical Documentation |
| 170 | + |
| 171 | +Use official docs when clarifying edge behavior: |
| 172 | + |
| 173 | +- Bun docs: https://bun.sh/docs |
| 174 | +- Drizzle ORM docs: https://orm.drizzle.team/docs/overview |
| 175 | +- Drizzle migrations docs: https://orm.drizzle.team/docs/migrations |
| 176 | +- Zod docs: https://zod.dev |
| 177 | +- Turbo docs: https://turbo.build/repo/docs |
0 commit comments