dafthunk / rules
Cursor rule133 starsChanged 9 months agoMITView 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 1,533 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 repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-persona.mdcCursor rule
- .cursor/rules/01-software-design-guidelines.mdcCursor rule
- .cursor/rules/02-development-environment.mdcCursor rule
- .cursor/rules/03-project-structure.mdcCursor rule
- .cursor/rules/04-code-implementation-guidelines.mdcCursor rule
- .cursor/rules/05-web-development.mdcCursor rule
- .cursor/rules/06-api-development.mdcCursor rule
- .cursor/rules/08-web-routes.mdcCursor rule
- integration-generatorSkill
- node-generatorSkill
- template-generatorSkill
The file
We split this 07-database-development.mdc into the rules it gives an agent
12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Use Drizzle's SQLite helpers (integer(), text(), sqliteTable(), etc.).
- Very specific: line 23
Use .references() in Drizzle to define relationships explicitly.
- Distinctive: line 35
Instead, constrain values manually in your application or through custom Zod validation.
- Very specific: line 39
Use camelCase in TypeScript with InferModel.
- Very specific: line 48
Use SQL-level defaults like CURRENT_TIMESTAMP to avoid time zone mismatches.
- Distinctive: line 49
Avoid setting defaults in TypeScript for critical database fields.
- Very specific: line 52
Always use Drizzle's InferModel to export consistent types.
- Very specific: line 60
Use drizzle-kit to generate and run migrations.
- Distinctive: line 61
Keep migrations version-controlled and consistent across environments.
- Distinctive: line 62
Don't mutate tables manually in production.
- Distinctive: line 65
Prefer strict types to nullable columns.
- Distinctive: line 70
Avoid relying on rapid writes followed immediately by reads (i.e., eventual read-after-write delays).
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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
---
description:
globs: apps/api/src/db/**
alwaysApply: false
---
# Database Design Best Practices
## Use SQL-Compatible Types
- Cloudflare D1 uses SQLite under the hood.
- Use Drizzle's SQLite helpers (`integer()`, `text()`, `sqliteTable()`, etc.).
- Be mindful of SQLite's flexible typing and ensure type safety using Drizzle.
```ts
export const users = sqliteTable("users", {
id: integer("id").primaryKey({ autoIncrement: true }),
email: text("email").notNull().unique(),
createdAt: text("created_at").default(sql`CURRENT_TIMESTAMP`),
});
```
## Model Relationships Carefully
- D1 (SQLite) does support foreign keys, but indexing is crucial for performance.
- Use `.references()` in Drizzle to define relationships explicitly.
```ts
export const posts = sqliteTable("posts", {
id: integer("id").primaryKey({ autoIncrement: true }),
authorId: integer("author_id").references(() => users.id),
title: text("title").notNull(),
});
```
## Use Enums Where Needed (with Caution)
- SQLite does not have native enum support.
- Instead, constrain values manually in your application or through custom Zod validation.
## Use snake_case for SQL Fields
- Stick to `snake_case` in table and column names.
- Use `camelCase` in TypeScript with `InferModel`.
```ts
export const tasks = sqliteTable("tasks", {
createdAt: text("created_at"),
});
```
## Timestamps & Defaults
- Use SQL-level defaults like `CURRENT_TIMESTAMP` to avoid time zone mismatches.
- Avoid setting defaults in TypeScript for critical database fields.
## Type Inference
- Always use Drizzle's `InferModel` to export consistent types.
```ts
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, "insert">;
```
## Migrations
- Use `drizzle-kit` to generate and run migrations.
- Keep migrations version-controlled and consistent across environments.
- Don't mutate tables manually in production.
## Avoid Nullable Unless Necessary
- Prefer strict types to nullable columns.
- Design schema around clear assumptions; nulls can be a source of bugs.
## D1 Considerations
- Cloudflare D1 is a distributed SQLite; consider its eventual consistency.
- Avoid relying on rapid writes followed immediately by reads (i.e., eventual read-after-write delays).
- Be cautious with large data writes or transactions—D1 is optimized for light, edge-ready workloads.
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.

