sagarithm-kit / rules
Cursor rule17 starsChanged 12 days agoApache-2.0View on GitHub
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,183 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository252 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/ai-systems-and-rag.mdcCursor rule
- .cursor/rules/architecture-spec-driven-development.mdcCursor rule
- .cursor/rules/architecture-system-design.mdcCursor rule
- .cursor/rules/backend-distributed-systems.mdcCursor rule
- .cursor/rules/delivery-shipping-and-launch.mdcCursor rule
- .cursor/rules/devops-sre-observability.mdcCursor rule
- .cursor/rules/documentation-architectural-decision-records.mdcCursor rule
- .cursor/rules/engineering-ai-data-remediation-engineer.mdcCursor rule
- .cursor/rules/engineering-ai-engineer.mdcCursor rule
- .cursor/rules/engineering-api-platform-engineer.mdcCursor rule
- .cursor/rules/engineering-autonomous-optimization-architect.mdcCursor rule
- .cursor/rules/engineering-backend-architect.mdcCursor rule
- .cursor/rules/engineering-cms-developer.mdcCursor rule
- .cursor/rules/engineering-codebase-onboarding-engineer.mdcCursor rule
- .cursor/rules/engineering-code-reviewer.mdcCursor rule
- .cursor/rules/engineering-database-optimizer.mdcCursor rule
- .cursor/rules/engineering-data-engineer.mdcCursor rule
- .cursor/rules/engineering-desktop-app-engineer.mdcCursor rule
- .cursor/rules/engineering-devops-automator.mdcCursor rule
- .cursor/rules/engineering-drupal-performance.mdcCursor rule
- .cursor/rules/engineering-drupal-shopping-cart.mdcCursor rule
- .cursor/rules/engineering-email-intelligence-engineer.mdcCursor rule
- .cursor/rules/engineering-embedded-firmware-engineer.mdcCursor rule
- .cursor/rules/engineering-feishu-integration-developer.mdcCursor rule
- .cursor/rules/engineering-filament-optimization-specialist.mdcCursor rule
- .cursor/rules/engineering-finops-engineer.mdcCursor rule
- .cursor/rules/engineering-frontend-developer.mdcCursor rule
- .cursor/rules/engineering-git-workflow-master.mdcCursor rule
- .cursor/rules/engineering-i18n-engineer.mdcCursor rule
- .cursor/rules/engineering-identity-access-engineer.mdcCursor rule
- .cursor/rules/engineering-incident-response-commander.mdcCursor rule
- .cursor/rules/engineering-it-service-manager.mdcCursor rule
- .cursor/rules/engineering-minimal-change-engineer.mdcCursor rule
- .cursor/rules/engineering-mobile-app-builder.mdcCursor rule
- .cursor/rules/engineering-mobile-release-engineer.mdcCursor rule
- .cursor/rules/engineering-multi-agent-systems-architect.mdcCursor rule
- .cursor/rules/engineering-network-engineer.mdcCursor rule
- .cursor/rules/engineering-orgscript-engineer.mdcCursor rule
- .cursor/rules/engineering-payments-billing-engineer.mdcCursor rule
- .cursor/rules/engineering-prompt-engineer.mdcCursor rule
- .cursor/rules/engineering-rapid-prototyper.mdcCursor rule
- .cursor/rules/engineering-realtime-collaboration-engineer.mdcCursor rule
- .cursor/rules/engineering-search-relevance-engineer.mdcCursor rule
- .cursor/rules/engineering-section-508-specialist.mdcCursor rule
- .cursor/rules/engineering-senior-developer.mdcCursor rule
- .cursor/rules/engineering-software-architect.mdcCursor rule
- .cursor/rules/engineering-solidity-smart-contract-engineer.mdcCursor rule
- .cursor/rules/engineering-sre.mdcCursor rule
- .cursor/rules/engineering-technical-writer.mdcCursor rule
- .cursor/rules/engineering-uswds-developer.mdcCursor rule
- .cursor/rules/engineering-video-streaming-engineer.mdcCursor rule
- .cursor/rules/engineering-voice-ai-integration-engineer.mdcCursor rule
- .cursor/rules/engineering-webassembly-engineer.mdcCursor rule
- .cursor/rules/engineering-wechat-mini-program-developer.mdcCursor rule
- .cursor/rules/engineering-wordpress-performance.mdcCursor rule
- .cursor/rules/engineering-wordpress-shopping-cart.mdcCursor rule
- .cursor/rules/frontend-ui-engineering.mdcCursor rule
- The first 60 shown.
The file
We split this database-architecture-and-modeling.mdc into the rules it gives an agent
10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Schema DDL First: Write declarative schema definitions (SQL DDL / Prisma / Drizzle / TypeORM) with explicit types, constraints, and …
- Distinctive: line 18
Prepared Statements: Never concatenate SQL strings.
- Distinctive: line 25
Primary Keys: Use immutable, collision-resistant identifiers: UUIDv7 (time-ordered, index-friendly) or standard auto-incrementing BigInt …
- Very specific: line 30
Covering Indexes: Use INCLUDE columns (in PostgreSQL) to satisfy read queries directly from index leaf pages without table heap fetches …
- Very specific: line 31
Query Plan Verification: Verify queries with EXPLAIN (ANALYZE, BUFFERS) (PostgreSQL) or EXPLAIN ANALYZE (MySQL).
- Distinctive: line 34
Short-Lived Transactions: Keep database transactions as short as possible.
- Distinctive: line 36
Deadlock Prevention: Always acquire locks on multiple rows or tables in a globally consistent order (e.g.
- Distinctive: line 39
Never execute breaking schema changes (renaming columns, removing columns, altering types) in a single deployment:
- Distinctive: line 40
Phase 1 (Expand): Add the new column/table as nullable or with a safe default.
- Distinctive: line 41
Phase 2 (Backfill): Run an asynchronous background migration to copy existing data from old columns to new columns in batches.
≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- SAGARITHM:START - DO NOT EDIT DIRECTLY -->
---
description: "Architect high-performance relational and document schemas, deterministic zero-downtime migrations, B-Tree/GIN indexing strategies, and ACID transaction boundaries."
globs: ["**/*"]
alwaysApply: false
---
# Database Architecture & Data Modeling
# Database Architecture & Data Modeling
## Overview
This skill encodes the expertise of a Lead Database Architect and Principal Data Engineer. It ensures database schemas are normalized, query plans are optimized, data integrity is guaranteed at the database engine level, and all schema evolutions follow zero-downtime expand-contract paradigms.
## 🎯 Token Conservation & High-Yield Heuristics
1. **Schema DDL First**: Write declarative schema definitions (SQL DDL / Prisma / Drizzle / TypeORM) with explicit types, constraints, and defaults. Avoid conversational speculation about database shapes.
2. **Deterministic Index Definitions**: State index types (B-Tree, GIN, Hash) and explain index column ordering ($(\text{filter}, \text{sort})$) directly in code comments.
3. **Prepared Statements**: Never concatenate SQL strings. Always use parameterized queries or type-safe query builders to ensure security and plan caching.
## 📐 Core Engineering Directives
### 1. Relational Modeling & Data Integrity
- **Third Normal Form (3NF) Baseline**: Normalize entities to 3NF to prevent update anomalies and duplicate storage. Only introduce deliberate denormalization when backed by empirical read performance benchmarks.
- **Engine-Level Constraints**: Enforce data integrity in the database engine, not merely in application code. Use `NOT NULL`, `FOREIGN KEY ... ON DELETE RESTRICT/CASCADE`, `CHECK` constraints, and `UNIQUE` indexes.
- **Primary Keys**: Use immutable, collision-resistant identifiers: UUIDv7 (time-ordered, index-friendly) or standard auto-incrementing BigInt keys. Avoid raw UUIDv4 for high-throughput clustered indexes due to B-Tree page fragmentation.
### 2. Indexing Strategy & Query Optimization
- **Index Selectivity Rule**: Index columns used in `WHERE`, `JOIN`, and `ORDER BY` clauses with high cardinality. Avoid indexing low-cardinality columns (e.g. boolean flags) unless part of a composite or partial index.
- **Leftmost Prefix Rule**: For composite indexes on `(A, B, C)`, queries filtering on `A` or `(A, B)` utilize the index; queries filtering solely on `B` or `C` cannot utilize the B-Tree index.
- **Covering Indexes**: Use `INCLUDE` columns (in PostgreSQL) to satisfy read queries directly from index leaf pages without table heap fetches (`Index Only Scan`).
- **Query Plan Verification**: Verify queries with `EXPLAIN (ANALYZE, BUFFERS)` (PostgreSQL) or `EXPLAIN ANALYZE` (MySQL). Eliminate sequential scans on large tables ($> 10{,}000$ rows).
### 3. Concurrency & Transaction Isolation
- **Short-Lived Transactions**: Keep database transactions as short as possible. Never perform external network calls, file I/O, or CPU-intensive tasks inside a database transaction block.
- **Optimistic Locking**: For concurrent updates on frequently modified entities (e.g. inventory balances), use version numbers (`version INT`) with conditional updates (`WHERE id = :id AND version = :version`).
- **Deadlock Prevention**: Always acquire locks on multiple rows or tables in a globally consistent order (e.g. sorted by ID ascending).
### 4. Zero-Downtime Migration Lifecycle (Expand-Contract)
Never execute breaking schema changes (renaming columns, removing columns, altering types) in a single deployment:
1. **Phase 1 (Expand)**: Add the new column/table as nullable or with a safe default. Deploy code that writes to both old and new columns, reading from the old.
2. **Phase 2 (Backfill)**: Run an asynchronous background migration to copy existing data from old columns to new columns in batches.
3. **Phase 3 (Switch)**: Deploy code that reads and writes strictly to the new column.
4. **Phase 4 (Contract)**: Drop the old column/table in a subsequent maintenance deployment once verified.
## 🛑 Anti-Rationalization Matrix
| Agent Excuse / Shortcut | Database Reality | Mandatory Action |
|---|---|---|
| *"I'll just rename this column in the production migration directly."* | Causes downtime, breaks active application instances, and fails rolling deployments. | Use the 4-phase Expand-Contract pattern with backward compatibility. |
| *"I don't need a foreign key constraint; the ORM handles it."* | Data drift, orphan records, and corrupt states inevitably occur during manual updates or batch operations. | Define foreign key constraints at the SQL DDL level with explicit delete rules. |
| *"I'll use `SELECT *` in queries to get all fields."* | Wastes network bandwidth, consumes memory, breaks covering index scans, and risks payload leakage. | Select only the exact columns required by the calling application layer. |
| *"I don't need indexes yet because the development database is small."* | Small test databases hide $O(N)$ sequential scans that cause catastrophic failure in production under load. | Add indexes during schema definition according to access patterns. |
## ✅ Database Verification Checklist
- [ ] Foreign keys and uniqueness constraints defined at the engine level.
- [ ] No sequential scans on high-traffic queries verified via `EXPLAIN ANALYZE`.
- [ ] UUIDv7 or BigInt primary keys utilized for indexed tables.
- [ ] All migrations are reversible (`down` script provided) and non-blocking (`CREATE INDEX CONCURRENTLY` in PostgreSQL).
- [ ] Zero raw string concatenation in SQL queries; 100% parameterized inputs.
<!-- SAGARITHM:END -->
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.

