agentleFS
golid-aigolid-ai/golid/.cursor/rules/document-module.mdc

golid / rules

Cursor rule40 starsChanged 6 months agoMITView on GitHub

Document an existing module — use when asked to spec, document, or map a module that's already built

The file

We split this document-module.mdc into the rules it gives an agent

10 rules. About 0 are common, 7 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every business rule must be marked:

    line 23
  2. Distinctive:

    Do NOT invent business rules.

    line 26
  3. Very specific:

    Use function names in [Verified:] annotations, not line numbers.

    line 27
  4. Distinctive:

    Never put exact line numbers in Known Issues: Use function names or describe the pattern.

    line 37
  5. Very specific:

    Use docs/modules/_templates/spec.md.

    line 41
  6. Very specific:

    Run @audit-codebase against the spec to verify:

    line 65
  7. Distinctive:

    Every FK dependency has a Depends On entry

    line 66
  8. Distinctive:

    Every Scope Includes item has matching content

    line 67
  9. Distinctive:

    When code changes a documented contract (state machine transition, enum value, business rule, side effect, API shape), update the spec in …

    line 73
  10. Distinctive:

    If the spec doesn't mention the thing you changed, no sync needed.

    line 84

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

Keep what fits and drop the rest. Your version, ready for your agents.
Files
document-module.mdc
---
description: Document an existing module — use when asked to spec, document, or map a module that's already built
alwaysApply: false
---

# Document a Module

> **Thesis:** Use this when documenting an existing module. `plan-feature.mdc`
> plans forward. This documents backward — capturing what was built, why, and
> how it behaves.

## Order of Operations

1. **Schema first** — read the migrations in `backend/migrations/` to understand tables, enums, relationships, indexes
2. **Service logic** — each service module lives in its own subpackage at `backend/internal/service/<module>/`. Read `<module>.go` (plus split files like `auth_password.go`, `auth_verify.go`) for business rules, auth checks, transactions, status transitions
3. **Handler surface** — read `backend/internal/handler/*.go` for request validation and response shapes; route registration lives in `backend/internal/wire/routes.go`
4. **Frontend routes** — read `frontend/src/routes/(private)/*.tsx` for pages, modals, state management
5. **Write the spec** — fill `docs/modules/_templates/spec.md` and save it to
   `docs/modules/{module}/spec.md`

## Evidence Standards

- Every business rule must be marked:
  - `[Verified: service/auth/auth.go, Refresh()]` — confirmed by reading the code
  - `[NEEDS VERIFICATION]` — inferred from naming or partial evidence
- Do NOT invent business rules. If you can't confirm it, mark it unverified.
- Use **function names** in `[Verified:]` annotations, not line numbers. Line numbers drift with every PR; function names are stable.
- File paths are good — they can be verified with `ls` or `glob`. Include them freely.

## Anti-Rot Rules

These are the #1 source of documentation staleness. Follow strictly:

- **Never put exact line counts** in docs. Use complexity tiers (Low/Medium/High/Critical) or approximate scale (`~3k lines`). Exact counts are wrong after the next PR.
- **Never list code quality issues** (missing error handling, unused imports, dead code) in docs. Those are linter/grep concerns, not documentation. They go stale the moment someone cleans up code.
- **Do list architectural concerns** (file too large for splitting, duplicated utility, drift risk between frontend/backend). These change rarely and help future developers.
- **Never put exact line numbers in Known Issues**. Use function names or describe the pattern.

## Template Reference

Use `docs/modules/_templates/spec.md`. Do not recreate the template by memory;
copy it first, then fill it with verified evidence.

## Complexity Ratings

| Rating | Criteria |
|--------|----------|
| Low | < 500 lines, simple CRUD, no state machine, 0-1 integrations |
| Medium | 500-1,500 lines, has state machine or moderate rules, 1-2 integrations |
| High | 1,500-3,000 lines, complex state machines, financial calcs, 2+ integrations |
| Critical | 3,000+ lines, polymorphic entities, cross-system deps, data migration risks |

## Output

Save to `docs/modules/{module}/spec.md`. Create the directory if it doesn't exist.

**After updating a spec,** regenerate the reverse dependency map
(`docs/dependency-graph.md`) if Depends On entries changed. Check
`docs/flows.md` for flows involving this module and update if transaction
boundaries or failure modes changed. If endpoint auth logic changed,
update `docs/permissions.md`.

## After Writing

Run `@audit-codebase` against the spec to verify:
1. Every FK dependency has a Depends On entry
2. Every Scope Includes item has matching content
3. Business rules cite actual file paths
4. No `[NEEDS VERIFICATION]` items that can be resolved from code

## Same-Commit Spec Sync

When code changes a documented contract (state machine transition, enum value, business rule, side effect, API shape), update the spec **in the same commit**. Spec drift is the single largest source of doc rot in this repo.

What counts as "documented contract":

- A row in the State Machine table.
- An enum literal listed under Entities.
- A bullet under Business Rules with `[Verified: ...]`.
- A `created_via` / `source` / `status` enum value.
- A side effect listed under Side Effects (email, webhook, SSE event).
- A row in the API Surface table.

If the spec doesn't mention the thing you changed, no sync needed. If it does, the spec change goes in the same commit as the code change.

To verify before opening a PR: `scripts/check_spec_drift.sh`. The script flags handler/service files changed without a matching spec change. If the drift is intentional (refactor, rename, no behavior change), include `[skip-spec(<module>): <one-line reason>]` in any commit message in the range, or `[skip-spec: <reason>]` to skip all modules. See `ci-workflow` "Spec-Drift Gate" for the full mapping and CI wiring.

## Anti-Rationalization

| Excuse | Counter |
|---|---|
| "I'll update the spec in a follow-up doc commit" | Spec-drift follow-ups produced `2b6568e`, `9294451`, `c9ba50d`, `a4e9405` — four separate commits that should have been zero. Sync in the same commit costs 30 seconds. |
| "The spec is auto-generated from code" | It isn't. Specs in this repo are hand-written narrative + `[Verified:]` annotations. They don't auto-update. |
| "The change is too small to matter to the spec" | If it's small enough that the spec doesn't need updating, the spec already covers it. If the spec is silent on the thing you changed, the spec is now wrong. |
| "Someone will catch it in audit" | They will. That's the cleanup commit you're trying to avoid. |

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.