skills/schema/SKILL.md
Design database schemas and API contracts at system boundaries. Use when creating or modifying database tables, API endpoints, or data serialization formats. Make sure to use this skill whenever the user adds database migrations, designs REST/GraphQL APIs, creates DTOs, defines request/response shapes, or works on data serialization — even for adding a single column or endpoint.
npx skillsauth add elct9620/ai-coding-skills schemaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Condition | Pass | Fail | |-----------|------|------| | Database structure change | Adding/modifying tables, columns, or indexes | No persistence changes | | API contract work | Designing or changing request/response shapes | No API boundary changes | | Data boundary crossing | Serialization/deserialization between layers | Data stays within single layer | | Schema restructuring | Normalizing, denormalizing, or optimizing existing schemas | No structural changes needed |
Apply when: Any condition passes
| Principle | Description | Violation Sign | |-----------|-------------|----------------| | Single Source of Truth | Each fact stored exactly once | Same data duplicated across tables without clear denormalization rationale | | Explicit Contracts | Schemas defined clearly, with non-obvious values (status codes, control bytes, enum semantics) described inline at the boundary | Implicit structures, untyped fields, or values that require service code to interpret | | Boundary Alignment | Schema matches system boundary responsibilities | Schema leaks internal details or couples unrelated concerns | | Minimal Exposure | Expose only what consumers need | Internal fields visible in API responses, over-fetching by default |
| Type | Clean Architecture Layer | Purpose | Boundary with Domain Modeling | |------|--------------------------|---------|-------------------------------| | Database Schema | Infrastructure | Persist and query data efficiently | Translates domain entities into storage format | | API Contract | Interface Adapters | Define external communication shape | Maps domain output to external representation | | DTO | Interface Adapters | Transfer data between layers | Decouples domain model from transport format |
| Factor | Normalize | Denormalize | |--------|-----------|-------------| | Write frequency | High writes, frequent updates | Read-heavy, rare updates | | Data consistency | Critical consistency required | Eventual consistency acceptable | | Query complexity | Simple joins acceptable | Complex joins causing performance issues | | Storage | Minimize redundancy | Trade storage for speed |
| Scenario | Index Type | When to Use | |----------|------------|-------------| | Exact lookups | B-tree (default) | Primary keys, foreign keys, unique constraints | | Text search | Full-text / GIN | Search within text content | | Range queries | B-tree | Date ranges, numeric ranges | | Multi-column filter | Composite | Frequently queried column combinations |
Before adding an index, check whether existing indexes already cover the query:
| Redundant | Why | Covered By | |-----------|-----|------------| | INDEX on (a, b) when PK is (a, b) | PK already creates a B-tree index | Primary key | | INDEX on (a) when composite index (a, b) exists | Leading prefix of composite index covers single-column lookups | Composite index | | INDEX on (a, b, c) identical to PK (a, b, c) | Exact duplicate | Primary key | | UNIQUE constraint + separate INDEX on same columns | UNIQUE already creates an index | Unique constraint | | INDEX on (a) when UNIQUE on (a, b) exists | Leading prefix of unique index covers single-column lookups | Unique constraint's B-tree |
Rule of thumb: Every index has write-cost overhead. Only add an index when you have a specific query pattern it serves that isn't already covered by existing PKs, unique constraints, or composite indexes with matching leading columns.
| Principle | REST | GraphQL / RPC | |-----------|------|---------------| | Structure | Model endpoints around resources | Model around operations or queries | | Naming | Plural nouns, consistent casing | Verb-based or domain-aligned naming | | Status/errors | Match HTTP status codes to outcomes | Use typed error responses | | Pagination | Paginate collection endpoints | Use cursor-based pagination | | Consistency | Uniform error format across endpoints | Uniform error format across operations |
| Strategy | Pros | Cons | Best For |
|----------|------|------|----------|
| URL path (/v1/) | Simple, explicit | URL pollution | Public APIs with clear major versions |
| Header-based | Clean URLs | Less discoverable | Internal APIs with frequent changes |
| Query parameter | Easy to test | Caching complexity | Transitional versioning |
| Aspect | Schema (this skill) | Domain Modeling | |--------|---------------------|-----------------| | Focus | Data structure at boundaries | Business concepts and rules | | Layer | Infrastructure / Interface Adapters | Domain (Entities) | | Artifacts | Tables, columns, indexes, API contracts, DTOs | Entities, Value Objects, Aggregates | | Question answered | How is data stored and transmitted? | What are the business rules and concepts? |
| Criterion | Pass | Fail | |-----------|------|------| | Purpose confirmed | Schema purpose and consumers identified | Unclear who uses this schema or why | | Existing structure reviewed | Current schema/contracts examined | Designing without knowing existing state | | Naming convention | Follows project naming conventions | Inconsistent or arbitrary naming | | Backward compatibility | Breaking changes identified and planned | Unaware of downstream impact |
| Criterion | Pass | Fail | |-----------|------|------| | Domain model independence | Schema can change without altering domain | Domain entities shaped by storage format | | Constraint correctness | NOT NULL, foreign keys, unique constraints match business rules | Missing constraints or overly permissive schema | | Contract completeness | All required fields, types, and validation documented | Partial or ambiguous contract definition | | Minimal exposure | Only necessary fields exposed to consumers | Internal details leaked through API or schema |
| Criterion | Pass | Fail | |-----------|------|------| | Contract verified | API contracts tested with request/response examples | No contract verification | | No domain leakage | Storage/transport details absent from domain layer | Domain layer references DB columns or API fields | | Documentation updated | Schema changes reflected in docs/migrations | Undocumented schema changes |
development
Plan how a system is structured — which layers, modules, or contexts exist and how code is laid out — driven by the forces at play, not by a fixed pattern. The default is to add no extra structure; structure is introduced only when complexity calls for it, and the chosen shape (Clean Architecture, DDD, DCI, or another) is judged in the moment. Use this skill when following a recorded structure in docs/architecture.md, or when deciding the structural shape for a non-trivial feature, a new module, or a restructuring — especially after a design-forces memo recommends a layered or partitioned structure.
development
Surface design forces and lay out the option space — including framework defaults, scaffolds, and deferring — before committing to Clean Architecture, DDD, or any heavier pattern. Produces a Design Analysis Memo at the start of /write, /refactor, or non-trivial /fix. Make sure to use this skill whenever the user starts a non-trivial feature, restructures code, or asks "do we really need Clean Architecture / DDD / pattern X here".
development
Write tests using TDD (Red-Green-Refactor) and AAA pattern. Use for every new feature, behavior change, or bug fix. Covers unit, integration, and E2E test selection. Make sure to use this skill whenever the user asks to add tests, fix a bug (tests should come first), implement a feature with test coverage, or asks about what kind of tests to write — even for small one-line changes or trivial-looking fixes.
development
Prevent security vulnerabilities through threat modeling, trust boundary analysis, and defense in depth. Use when writing code that crosses trust boundaries, handles authentication or authorization, processes external input, manages secrets, or stores sensitive data. Make sure to use this skill whenever the user works on login flows, processes data from external sources, builds interfaces between systems, manages credentials, or writes code that moves data across trust zones — even for seemingly simple changes like accepting a new parameter or calling an external service.