agentleFS
waynesuttonwaynesutton/markdown-site/.cursor/rules/convex-doctor.mdc

markdown-site / rules

Cursor rule628 starsChanged 7 months agoMITView on GitHub

Convex doctor code quality standards maintained at 100/100 score

The file

Show its rules and text

We split this convex-doctor.mdc into the rules it gives an agent

15 rules. About 0 are common, 9 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    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
  1. Very specific:

    Never use api.* for server-to-server calls.

    line 13
  2. Distinctive:

    All HTTP actions and public endpoints must check authentication unless they are intentionally public (RSS, sitemap, CORS preflight).

    line 14
  3. Distinctive:

    Never expose Node actions directly to the browser.

    line 15
  4. Very specific:

    Never use Date.now() inside a query function.

    line 20
  5. Very specific:

    Use .unique() for lookups on indexes that enforce uniqueness by design.

    line 21
  6. Very specific:

    Never use .collect().filter().

    line 22
  7. Distinctive:

    Use indexes for all query patterns.

    line 28
  8. Distinctive:

    Avoid N+1 query patterns. Batch document fetches into internal queries that accept arrays of IDs.

    line 29
  9. Distinctive:

    Add indexes for foreign key fields that have query patterns against them.

    line 34
  10. Distinctive:

    Do not add indexes for foreign keys inside nested arrays (Convex cannot index into arrays).

    line 35
  11. Distinctive:

    Remove redundant indexes that are prefixes of existing compound indexes.

    line 36
  12. Distinctive:

    Keep handlers focused. Extract helper functions for email templates, data transformation, and multi-step logic.

    line 40
  13. Very specific:

    Use ConvexError instead of throw new Error(...) in user-facing handlers when the error message should reach the client.

    line 43
  14. Very specific:

    Create a job table in convex/schema.ts with status, result, error fields

    line 49
  15. Distinctive:

    Run after any changes to Convex functions, schema, or HTTP routes.

    line 66

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
convex-doctor.mdc
---
description: Convex doctor code quality standards maintained at 100/100 score
globs:
alwaysApply: true
---

# Convex doctor code quality

This codebase maintains a 100/100 convex-doctor score. All new Convex code must follow these patterns to avoid regressions.

## Security

- Never use `api.*` for server-to-server calls. Always use `internal.*` references.
- All HTTP actions and public endpoints must check authentication unless they are intentionally public (RSS, sitemap, CORS preflight).
- Never expose Node actions directly to the browser. Use mutation-scheduled internal actions with a job table for status tracking.
- Public functions use `query`, `mutation`, `action`. Internal functions use `internalQuery`, `internalMutation`, `internalAction`.

## Correctness

- Never use `Date.now()` inside a query function. It breaks caching and reactivity. Accept a `now` argument or compute timestamps in mutations/actions.
- Use `.unique()` for lookups on indexes that enforce uniqueness by design. Use `.first()` only for intentional ordered picks where multiple rows are expected.
- Never use `.collect().filter()`. Use `.withIndex()` and iterate directly, or use `.take(n)` for bounded results.

## Performance

- Bound all public `.collect()` calls with `.take(n)` or pagination.
- Batch sequential `ctx.runQuery` and `ctx.runMutation` calls in actions. Create a single internal query that returns all needed data instead of making multiple separate calls.
- Use indexes for all query patterns. Never scan full tables.
- Avoid N+1 query patterns. Batch document fetches into internal queries that accept arrays of IDs.

## Schema

- Name indexes with `by_` prefix and snake_case: `by_slug`, `by_published`, `by_session_and_context`.
- Add indexes for foreign key fields that have query patterns against them.
- Do not add indexes for foreign keys inside nested arrays (Convex cannot index into arrays).
- Remove redundant indexes that are prefixes of existing compound indexes.

## Architecture

- Keep handlers focused. Extract helper functions for email templates, data transformation, and multi-step logic.
- Per-handler auth checks are intentional in this codebase. Do not extract auth into middleware or shared wrappers.
- Organize files by domain (posts, pages, newsletter, stats). Do not split purely for file size.
- Use `ConvexError` instead of `throw new Error(...)` in user-facing handlers when the error message should reach the client.

## Queued job pattern

For any background work triggered from the browser:

1. Create a job table in `convex/schema.ts` with `status`, `result`, `error` fields
2. Public mutation inserts a pending job and calls `ctx.scheduler.runAfter(0, internal...)`
3. Public query returns job status for the UI
4. Internal action processes the job and updates status on success or failure

Examples: `aiImageJobs.ts`, `importJobs.ts`, `semanticSearchJobs.ts`

## Suppression config

Intentional suppressions live in `convex-doctor.toml` at the repo root. Each suppression includes rationale. Do not add new suppressions without documenting why.

## Running convex-doctor

```bash
npx convex-doctor@latest
```

Run after any changes to Convex functions, schema, or HTTP routes. The score must stay at 100/100 with 0 errors and 0 warnings.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.