database-design
Skill22 starsChanged 9 months agoMITView on GitHub
Database design patterns and data modeling for relational and NoSQL databases. Use when the user asks to design a database schema, normalize or denormalize tables, create indexing strategies, plan schema migrations, model temporal data, implement audit trails, set up table partitioning, or optimize data access patterns. Covers entity relationships, naming conventions, constraint design, migration safety, and performance-oriented schema decisions.
42 other projects use a version of this.
Adopted by
Most recently taken up by
- vekzz-dev/opencode-skillstheir own version, first seen Oct 3, 2026
- hemapriyan-rk/claude-rigor-skillstheir own version, first seen Sep 26, 2026
- ZeroTokenClaw/agents-skillstheir own version, first seen Sep 21, 2026
- KbWen/agentic-ostheir own version, first seen Sep 10, 2026
- RealDougEubanks/ClaudeMarketplacetheir own version, first seen Sep 10, 2026
- VoDaiLocz/kilo-kit-mcptheir own version, first seen Aug 21, 2026
Used with
Projects with it also use intelligent-routing, i18n-localization and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
tiendatworkSkillintelligent-routing
Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.
Also in 3 projects that use this
xfstudioSkilli18n-localization
Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.
Also in 5 projects that use this
xfstudioSkillbehavioral-modes
AI operational modes (brainstorm, implement, debug, review, teach, ship, orchestrate). Use to adapt behavior based on task type.
Also in 3 projects that use this
GenerativeAgentsSkillarchitecture-design
アーキテクチャ設計書を作成するための詳細ガイドとテンプレート。アーキテクチャ設計時にのみ使用。
Also in 8 projects that use this
- +8 more from xfstudio
Other versions42 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 42
- CloudAI-X/claude-workflow-v2★ 1.4ksame name
- MoizIbnYousaf/ai-agent-skills★ 1.1ksame name
- KbWen/agentic-os★ 206same name
- thiientv/godmode★ 96same name
- KbWen/agent-virtual-office★ 35same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
- DauQuangThanh/hanoi-rainbow★ 17same name
- ishandutta2007/Awesome-Claude-Skills★ 15same name
- svngoku/coding-agents-skills★ 11same name
- xfstudio/skills★ 9same name
32 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- accessibilitySkill
- api-designSkill
- cicdSkill
- clean-architectureSkill
- debuggingSkill
- design-patternsSkill
- dispatching-parallel-agentsSkill
- git-workflowSkill
- microservicesSkill
- performanceSkill
- refactoringSkill
- scrumSkill
- securitySkill
- solidSkill
- subagent-driven-developmentSkill
- testingSkill
- verification-before-completionSkill
- composer-dependenciesSkill
- finishing-branchSkill
- php-upgradeSkill
- ticket-deliverySkill
- worktree-opsSkill
- architectSkill
- backend-devSkill
- frontend-devSkill
- product-managerSkill
- project-managerSkill
- qa-engineerSkill
- scrum-masterSkill
- agent-creatorSkill
- agentic-rules-writerSkill
- agent-teamsSkill
- brainstormingSkill
- dispatching-agent-teamsSkill
- image-annotateSkill
- plugin-creatorSkill
- pr-message-writerSkill
- report-writerSkill
- stakeholder-update-writerSkill
- ticket-writerSkill
- using-ecosystemSkill
- web-screenshotSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 41 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 65
Always keep the normalized source of truth - denormalized data is a derived cache
- Distinctive: line 68
Document why the denormalization exists and what access pattern it serves
- Distinctive: line 142
Expand: - add the new structure alongside the old one
- Distinctive: line 144
Switch: - update application code to use the new structure
- Distinctive: line 145
Contract: - remove the old structure once nothing references it
- Distinctive: line 170
Avoid hotspots - do not shard by a value that concentrates writes (e.g., current date)
“Common” is measured: kept by at least 6 in 10 of the 41 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Design
Good database design determines the long-term maintainability, performance, and correctness of any data-driven application. Schema decisions made early are expensive to reverse later. Every table, column, index, and constraint should exist for a reason backed by access patterns and business rules.
Data Modeling Principles
Start from Access Patterns
Design tables around how the application reads and writes data, not around how entities look in a domain model. Two questions drive every schema decision:
- What queries will run most frequently? - these determine table structure, indexes, and denormalization choices
- What consistency guarantees does the data need? - these determine normalization level, constraints, and transaction boundaries
Entity Relationships
| Relationship | Implementation | When to Use |
| One-to-one | Foreign key with UNIQUE constraint on the child table | Splitting rarely-accessed columns into a separate table, or enforcing exactly-one semantics |
| One-to-many | Foreign key on the child table referencing the parent | Orders to order items, users to addresses |
| Many-to-many | Join table with composite primary key | Tags to articles, students to courses |
| Many-to-many with attributes | Join table with its own columns beyond the two foreign keys | Enrollment with grade, membership with role |
| Self-referential | Foreign key referencing the same table | Org charts, category trees, threaded comments |
Naming Conventions
Consistent naming prevents confusion across teams and tools:
- Tables: plural nouns in snake_case (
order_items,user_addresses) - Columns: singular snake_case describing the value (
created_at,total_amount) - Foreign keys:
<referenced_table_singular>_id(user_id,order_id) - Indexes:
idx_<table>_<columns>(idx_orders_user_id_created_at) - Constraints:
chk_<table>_<rule>,uq_<table>_<columns>,fk_<table>_<referenced>
Normalization vs Denormalization
Normal Forms
| Form | Rule | Violation Example |
| 1NF | Every column holds atomic values; no repeating groups | Storing comma-separated tags in a single column |
| 2NF | Every non-key column depends on the entire primary key | In a composite-key table, a column depending on only part of the key |
| 3NF | No non-key column depends on another non-key column | Storing both city and zip_code when zip determines city |
| BCNF | Every determinant is a candidate key | A scheduling table where room determines building but room is not a key |
When to Denormalize
Normalization prevents anomalies but adds JOINs. Denormalize selectively when:
- Read-heavy workloads dominate and JOIN cost is measurable in profiling
- Reporting tables need pre-aggregated data that would otherwise require expensive queries
- Caching a computed value avoids recalculating on every read (e.g.,
order_totalstored on the order row) - Document-oriented access retrieves an entire aggregate in one read
Rules for safe denormalization:
- Always keep the normalized source of truth - denormalized data is a derived cache
- Define how and when the denormalized copy is updated (trigger, application event, batch job)
- Monitor for drift between the source and the copy
- Document why the denormalization exists and what access pattern it serves
Choosing a Database Type
| Type | Strengths | Fits When |
| Relational (PostgreSQL, MySQL) | ACID transactions, complex queries, mature tooling, JOINs | Structured data with relationships, transactional workloads, most CRUD applications |
| Document (MongoDB, DynamoDB) | Flexible schema, nested data, horizontal scaling | Aggregates accessed as a unit, rapidly evolving schemas, per-tenant isolation |
| Key-value (Redis, Memcached) | Sub-millisecond reads, simple data model | Session storage, caching, counters, rate limiting |
| Column-family (Cassandra, ScyllaDB) | High write throughput, wide rows, linear scaling | Time-series, IoT telemetry, append-heavy workloads |
| Graph (Neo4j, Neptune) | Traversal queries, relationship-centric data | Social networks, recommendation engines, fraud detection |
| Time-series (TimescaleDB, InfluxDB) | Optimized for time-stamped data, automatic partitioning | Metrics, monitoring, financial tick data |
Polyglot persistence - using different databases for different parts of the same system - is valid when access patterns genuinely differ. It is not valid as a way to avoid learning one database well.
Indexing Fundamentals
Indexes accelerate reads at the cost of slower writes and additional storage. Every index must justify its existence through query patterns.
Index Types
| Type | Structure | Best For |
| B-tree | Balanced tree, sorted data | Equality and range queries, ORDER BY, most general-purpose indexing |
| Hash | Hash table | Exact equality lookups only; no range support |
| GiST | Generalized search tree | Spatial data, geometric queries, range types, nearest-neighbor |
| GIN | Generalized inverted index | Full-text search, JSONB containment, array membership |
| BRIN | Block range index | Large tables with naturally ordered data (timestamps, sequential IDs) |
Composite Index Design
The order of columns in a composite index matters. The leftmost prefix rule means a composite index on (a, b, c) supports queries filtering on (a), (a, b), or (a, b, c), but not (b, c) alone.
Column ordering guidelines:
- Equality conditions first - columns compared with
= - Range conditions last - columns compared with
>,<,BETWEEN - Most selective column first among equals
Covering and Partial Indexes
- Covering index: includes all columns the query needs, so the database reads only the index. Use
INCLUDE(PostgreSQL) or just add columns to the index key. - Partial index: indexes only rows matching a condition, reducing size and write overhead. Ideal for querying a small subset of a large table (e.g.,
WHERE status = 'pending').
See Indexing Strategies Reference for detailed index types, EXPLAIN analysis, and anti-patterns.
Schema Evolution
Schema changes are inevitable. The question is whether they break running applications.
Backward-Compatible Changes (Safe)
- Adding a new nullable column
- Adding a new table
- Adding a new index (may lock briefly on some engines)
- Widening a column type (e.g.,
VARCHAR(50)toVARCHAR(100))
Breaking Changes (Require Migration Strategy)
- Renaming or removing a column
- Changing a column type in incompatible ways
- Adding a NOT NULL constraint to an existing column with null data
- Splitting or merging tables
The Expand-Contract Pattern
For breaking changes in production with zero downtime:
- Expand - add the new structure alongside the old one
- Migrate - backfill data from old to new, dual-write during transition
- Switch - update application code to use the new structure
- Contract - remove the old structure once nothing references it
See Migration Patterns Reference for zero-downtime strategies, rollback techniques, and multi-tool examples.
Partitioning and Sharding
Table Partitioning (Single Database)
| Strategy | How It Works | Use Case |
| Range | Rows split by value ranges (e.g., by month) | Time-series data, log tables, archival |
| List | Rows split by discrete values (e.g., by region) | Multi-tenant data, geographic segmentation |
| Hash | Rows distributed by hash of a column | Even distribution when no natural range exists |
Sharding (Multiple Databases)
Sharding distributes data across separate database instances. Use it only after single-instance optimizations (indexing, caching, read replicas) are exhausted.
Shard key selection criteria:
- High cardinality - many distinct values to distribute evenly
- Present in most queries - avoids scatter-gather across all shards
- Stable - values that do not change after creation
- Avoid hotspots - do not shard by a value that concentrates writes (e.g., current date)
Quick Reference: Common Design Mistakes
| Mistake | Consequence | Fix |
| No foreign key constraints | Orphaned rows, inconsistent data | Always define foreign keys unless there is a documented reason not to |
| Over-indexing | Slow writes, wasted storage | Index only columns used in WHERE, JOIN, ORDER BY of actual queries |
| Storing computed values without a refresh strategy | Stale data, silent bugs | Define update triggers, events, or batch jobs alongside any denormalization |
| Using ENUM types for values that change | Schema migration for every new value | Use a lookup table with a foreign key instead |
| Storing money as floating-point | Rounding errors | Use DECIMAL/NUMERIC or store as integer cents |
| Missing created_at / updated_at timestamps | No auditability, difficult debugging | Add timestamp columns to every table by default |
Generic type + type_id polymorphism everywhere | No referential integrity, complex queries | Evaluate STI, CTI, or separate tables first |
Reference Files
| Reference | Contents |
| Modeling Patterns | Polymorphic associations (STI/CTI/TPT), soft deletes, audit trails, temporal data, self-referential trees, JSON columns |
| Indexing Strategies | B-tree/hash/GiST/GIN details, composite index design, covering and partial indexes, EXPLAIN analysis, anti-patterns |
| Migration Patterns | Version-based vs state-based migrations, expand-contract, data migrations, rollback strategies, multi-tool examples |
Integration with Other Skills
| Situation | Recommended Skill |
| Optimizing query performance and caching | Install knowledge-virtuoso from krzysztofsurdy/code-virtuoso for performance optimization patterns |
| Designing domain models and aggregates | Install knowledge-virtuoso from krzysztofsurdy/code-virtuoso for clean architecture and DDD guidance |
| Building APIs that expose database-backed resources | Install knowledge-virtuoso from krzysztofsurdy/code-virtuoso for API design principles |
| Testing database interactions | Install knowledge-virtuoso from krzysztofsurdy/code-virtuoso for testing strategies |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

