database-design
Production-grade database design skill for SQL/NoSQL selection, schema design, indexing, and query optimization
What this skill does
# Database Design Skill
> **Purpose**: Atomic skill for database architecture with comprehensive parameter validation and optimization patterns.
## Skill Identity
| Attribute | Value |
|-----------|-------|
| **Scope** | Schema Design, Indexing, Query Optimization |
| **Responsibility** | Single: Data modeling and storage patterns |
| **Invocation** | `Skill("database-design")` |
## Parameter Schema
### Input Validation
```yaml
parameters:
database_context:
type: object
required: true
properties:
use_case:
type: string
enum: [oltp, olap, htap, time_series, document, graph]
required: true
data_characteristics:
type: object
required: true
properties:
volume:
type: string
pattern: "^\\d+[KMGTP]B$"
velocity:
type: string
pattern: "^\\d+[KM]?\\s*(reads?|writes?)/s$"
variety:
type: string
enum: [structured, semi_structured, unstructured]
access_patterns:
type: array
items:
type: object
properties:
query_type: { type: string }
frequency: { type: string, enum: [high, medium, low] }
latency_sla: { type: string, pattern: "^\\d+ms$" }
consistency:
type: string
enum: [strong, eventual, read_your_writes]
default: strong
validation_rules:
- name: "oltp_latency"
rule: "use_case == 'oltp' implies latency_sla <= '100ms'"
error: "OLTP workloads typically require <100ms latency"
- name: "volume_velocity_match"
rule: "high_volume implies adequate_velocity"
error: "Volume and velocity constraints may be incompatible"
```
### Output Schema
```yaml
output:
type: object
properties:
database_recommendation:
type: object
properties:
primary: { type: string }
secondary: { type: string }
rationale: { type: string }
schema:
type: object
properties:
tables: { type: array }
relationships: { type: array }
constraints: { type: array }
indexes:
type: array
items:
type: object
properties:
table: { type: string }
columns: { type: array }
type: { type: string }
rationale: { type: string }
optimization_tips:
type: array
items: { type: string }
```
## Core Patterns
### Database Selection Matrix
```
OLTP (Transactional):
├── PostgreSQL
│ ├── Best for: Complex queries, ACID, JSON support
│ ├── Scale: Vertical + read replicas
│ └── Limit: ~10TB effective, 10K TPS
├── MySQL/MariaDB
│ ├── Best for: Web applications, simple queries
│ ├── Scale: Read replicas, ProxySQL
│ └── Limit: Similar to PostgreSQL
└── CockroachDB/TiDB
├── Best for: Distributed ACID
├── Scale: Horizontal auto-sharding
└── Trade-off: Higher latency
OLAP (Analytical):
├── ClickHouse
│ ├── Best for: Real-time analytics, columnar
│ ├── Performance: 1B+ rows/second
│ └── Use: Log analysis, metrics
├── Snowflake/BigQuery
│ ├── Best for: Data warehouse, serverless
│ ├── Scale: Unlimited, pay-per-query
│ └── Use: BI, reporting
└── DuckDB
├── Best for: Embedded analytics
└── Use: Edge, single-machine analytics
NoSQL:
├── MongoDB
│ ├── Best for: Documents, flexible schema
│ └── Pattern: Embedding, denormalization
├── Cassandra
│ ├── Best for: Write-heavy, wide-column
│ └── Pattern: Partition key design
├── Redis
│ ├── Best for: Cache, sessions, pub/sub
│ └── Limit: Memory-bound
└── Neo4j
├── Best for: Graph relationships
└── Pattern: Cypher queries
```
### Schema Design Patterns
```
Normalization (OLTP):
├── 1NF: Atomic values
├── 2NF: No partial dependencies
├── 3NF: No transitive dependencies
└── BCNF: Strict key dependencies
Denormalization (OLAP/NoSQL):
├── Embedding
│ ├── Nest related documents
│ ├── Best for: 1:few relationships
│ └── Avoid: Large arrays, frequent updates
├── Bucketing
│ ├── Group time-series data
│ ├── Reduce document count
│ └── Improve write performance
└── Materialized Views
├── Pre-computed aggregates
├── Trade: Storage vs query time
└── Refresh: Incremental or full
```
### Indexing Strategies
```
Index Types:
├── B-tree (default)
│ ├── Range queries, sorting
│ ├── Overhead: ~10% storage
│ └── Example: WHERE date BETWEEN x AND y
├── Hash
│ ├── Equality only
│ ├── Faster lookup
│ └── Example: WHERE id = 123
├── GIN (PostgreSQL)
│ ├── Full-text, JSONB, arrays
│ ├── Higher write cost
│ └── Example: WHERE tags @> '{redis}'
├── BRIN (Block Range)
│ ├── Large sorted tables
│ ├── Minimal storage
│ └── Example: Time-series data
└── Composite
├── Multi-column index
├── Order matters (leftmost prefix)
└── Example: (user_id, created_at DESC)
Index Selection Rules:
├── Query frequency > 10% of total
├── Selectivity > 10% (filter out 90%)
├── Write overhead acceptable
└── Index size < table size
```
## Retry Logic
### Connection & Query Retry
```yaml
retry_config:
connection:
max_attempts: 3
initial_delay_ms: 100
max_delay_ms: 5000
multiplier: 2.0
query:
max_attempts: 2
timeout_ms: 30000
retry_on:
- CONNECTION_LOST
- DEADLOCK
- LOCK_TIMEOUT
abort_on:
- SYNTAX_ERROR
- CONSTRAINT_VIOLATION
- PERMISSION_DENIED
transaction:
retry_on_deadlock: true
max_deadlock_retries: 3
isolation_level: READ_COMMITTED
```
## Logging & Observability
### Log Format
```yaml
log_schema:
level: { type: string }
timestamp: { type: string, format: ISO8601 }
skill: { type: string, value: "database-design" }
event:
type: string
enum:
- schema_analyzed
- index_recommended
- query_optimized
- capacity_estimated
- migration_planned
context:
type: object
properties:
table: { type: string }
query: { type: string }
execution_time_ms: { type: number }
rows_affected: { type: integer }
example:
level: INFO
event: index_recommended
context:
table: orders
columns: [user_id, status, created_at]
type: composite
rationale: "Covers 80% of queries"
```
### Metrics
```yaml
metrics:
- name: query_duration_seconds
type: histogram
labels: [query_type, table]
buckets: [0.001, 0.01, 0.1, 1, 10]
- name: index_usage_ratio
type: gauge
labels: [index_name, table]
- name: table_size_bytes
type: gauge
labels: [table, database]
- name: connection_pool_usage
type: gauge
labels: [pool_name]
```
## Troubleshooting
### Common Issues
| Issue | Cause | Resolution |
|-------|-------|------------|
| Slow queries | Missing index | Add appropriate index |
| Lock waits | Long transactions | Split or optimize |
| Connection exhaustion | Pool too small | Increase pool, add pooler |
| Replication lag | Heavy writes | Add replicas, optimize queries |
| Disk full | Bloat, no vacuum | VACUUM, archival |
### Debug Checklist
```
□ EXPLAIN ANALYZE run?
□ Index usage verified?
□ Connection pool monitored?
□ Lock contention checked?
□ Table statistics current?
□ Slow query log enabled?
```
## Unit Test Templates
### Schema Validation Tests
```python
# test_database_design.py
def test_valid_oltp_schema():
params = {
"database_context": {
"use_case": "oltp",
"data_characteristics": {
"volume": "100GB",
"velocity": "10K writes/s",
"variety": "structured"
},
"access_patterns": [
{"query_type": "point_lookup", "frequency": "high", "latency_sla": "10ms"}
]
}
}
result = validate_parameters(params)
assert result.valid == True
def test_oltp_latency_validation():
params = {
"database_context": {
"use_case": "oltp",
"access_patterns": [
{"latency_sla":Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.