This skill governs how code is documented at every level — from individual file headers to global architecture docs. Apply it consistently across all projects. When in doubt: document the why, not the what. The code already says what it does.
/docs/ in both frontend and backend. Note what's
present, missing, or stale.Apply to every file that is ≥ 20 lines OR is imported by other modules.
The very first line of every source file must be a comment containing the file's full path from the project root. Use the comment syntax appropriate to the language.
js
// src/services/auth/tokenService.js
py
# src/services/auth/token_service.py
Immediately after the path comment, add a header block. Use the language's block comment syntax. This block is mandatory and must be kept accurate.
text
/**
* File: src/services/auth/tokenService.js
*
* Overview:
* Issues, validates, and refreshes JWT tokens for authenticated sessions.
* Exists to centralise all token logic so Auth routes stay thin.
*
* Exports:
* - issueToken(userId, role) → signed JWT string
* - verifyToken(token) → decoded payload or throws
* - refreshToken(oldToken) → new signed JWT string
*
* Imported By:
* - src/routes/auth.js
* - src/middleware/requireAuth.js
*
* Imports:
* - jsonwebtoken — signing/verification
* - config/env — JWT_SECRET, TOKEN_TTL
*
* Notes:
* - Tokens expire in 15 min; refresh window is 7 days.
* - verifyToken throws on expiry — callers must handle.
*/
Rules:
Top of every non-trivial function (any function with logic beyond a single expression):
js
/**
* Signs a new JWT for the given user. Embeds userId and role in payload.
* Throws if JWT_SECRET is not set in env.
*/
function issueToken(userId, role) { ... }
Rules:
Allowed (rare exceptions only):
js
const TIMEOUT = 5000 // 5 seconds
Prohibited — remove on sight:
PatternExampleWhy bannedRestating the code// enable proxy above proxy: trueZero informationRemoved/old code notes// removed legacy handlerUse git for historyChange log comments// changed to use v2 APINot a changelogSection dividers// ---- helpers ----Use modules insteadObvious steps// loop through users above a users.forEachNoise
If you encounter these, delete them. They are clutter that erodes trust in real comments.
See references/subsystem-doc.md for the full template and field-by-field instructions.
One .md file per subsystem, located at:
/backend/docs/<subsystem>.md/frontend/docs/<subsystem>.mdSubsystem identification heuristics:
auth, billing, search, notifications, api-layer, data-layer,
file-upload, websockets, admin, onboardingDiscovery checklist — identify a subsystem when you find:
If a subsystem doc already exists:
Location: /docs/architecture.md (or /backend/docs/architecture.md depending on repo layout)
See references/architecture-doc.md for the full template.
Required sections:
.mdRequired if a backend exists. Location: /backend/docs/api.md
For large backends: one file per subsystem, e.g. /backend/docs/api-auth.md,
/backend/docs/api-billing.md, then an index in /backend/docs/api.md.
See references/api-reference.md for the full endpoint template.
Every endpoint must document:
After writing or updating docs, audit them:
text
## Documentation Audit
### Missing
- List any subsystem without a doc
### Outdated
- List any doc that references removed files, functions, or endpoints
### Incorrect
- List any wrong dependency, wrong export name, wrong flow description
### Recommendations
- Specific fixes with file locations
Do not skip this pass. Stale documentation is worse than none — it actively misleads.
These apply any time you touch code:
api.md..md..md from the template in
references/subsystem-doc.md.Never leave documentation in a state that describes code that doesn't exist.
ConcernLocationFile path + module summaryTop of every source fileFunction purposeTop of every non-trivial functionSubsystem deep-dive/[frontend|backend]/docs/<name>.mdSystem-wide architecture/docs/architecture.mdAPI contracts/backend/docs/api.md (or per-subsystem)
references/subsystem-doc.md — Full subsystem doc template + instructionsreferences/architecture-doc.md — Full architecture.md templatereferences/api-reference.md — Full API endpoint documentation template