The /document command creates context files for existing code without running the full spec-driven workflow.
Document existing functionality, legacy code, or tribal knowledge by creating or updating structured context files in your project's knowledge repository.
/document <topic-or-module>
# Document a module
/document authentication module
# Document patterns
/document error handling patterns
# Document infrastructure
/document database connection pooling strategy
# Document legacy code
/document legacy payment processing system
# Document conventions
/document API response formatting conventions
When you run /document, Buildforce:
.buildforce/context/_index.yamlBefore /document, gather information:
# Option 1: Run research first
/research authentication patterns in this codebase
/document authentication module
# Option 2: Read and discuss files
# (Read src/auth/*.ts files, discuss patterns)
/document authentication security patterns
# Option 3: Ask questions, explore code
# (Discussion about error handling)
/document error handling conventions
# After discussing authentication implementation
/document authentication module
# .buildforce/context/authentication-module.yaml
version: "0.0.29"
id: "authentication-module"
name: "Authentication Module"
type: module
created: "2025-01-05"
last_updated: "2025-01-05"
description: |
JWT-based authentication with argon2 password hashing,
httpOnly cookie storage, and PostgreSQL-backed refresh tokens.
overview: |
The authentication system handles user login, token generation,
and session management. Uses industry-standard JWT with short-lived
access tokens (15min) and long-lived refresh tokens (7 days).
key_decisions:
- decision: "argon2 for password hashing"
rationale: "Superior resistance to GPU brute-force attacks"
- decision: "httpOnly cookies for token storage"
rationale: "XSS protection - tokens not accessible via JavaScript"
file_paths:
primary:
- path: "src/auth/service.ts"
purpose: "Core authentication business logic"
- path: "src/auth/middleware.ts"
purpose: "JWT validation and route protection"
architectural_patterns:
- pattern: "Repository Pattern"
description: "AuthRepository abstracts database operations"
- pattern: "Middleware Chain"
description: "JWT validation → RBAC → route handler"
code_snippets:
- title: "JWT Validation Middleware"
language: "typescript"
code: |
export const validateJWT = async (req, res, next) => {
const token = req.cookies.accessToken;
if (!token) return res.status(401).json({ error: 'Unauthorized' });
try {
const payload = jwt.verify(token, SECRET);
req.user = payload;
next();
} catch (err) {
return res.status(401).json({ error: 'Invalid token' });
}
};
related_context:
- user-management
- api-security
tags:
- authentication
- jwt
- argon2
- security
- middleware
First time documenting a topic:
/document caching strategy
Result:
caching-strategy.yaml_index.yamlSubsequent documentation of same topic:
/document caching strategy
Buildforce Response:
Context file 'caching-strategy.yaml' already exists.
Options:
A. Update existing context (merge new information)
B. Create new context with different name
C. Cancel
Your choice?
If you choose A (Update):
# Updates section added
updates:
- date: "2025-01-08"
summary: "Added Redis cluster configuration details"
# New information merged into existing sections
✅ Prepare context window first
/research authentication patterns
# Read relevant files, discuss architecture
/document authentication module
✅ Document meaningful patterns
/document error handling strategy across services
✅ Capture tribal knowledge
/document why we chose PostgreSQL over MongoDB for user data
✅ Document conventions
/document API naming conventions and response formats
❌ Document trivial details
/document how to write a for loop # Too basic
❌ Document with no context
# Empty conversation history
/document authentication # Won't have enough information
❌ Document work-in-progress
# Feature not complete
/document half-implemented payment flow # Wait until complete
/documentUse /document when:
/complete/complete auto-generates context from spec+plan+build./document manually creates context when no spec exists.
Use both:
/complete for new features (automatic documentation)/document for existing code (manual documentation)Generated context quality depends on conversation richness:
Poor Context:
# Minimal conversation
/document auth module
Result: Sparse context file with little detail
Rich Context:
# Extensive discussion
/research authentication in our codebase
# Read 5 auth-related files
# Discuss patterns, decisions, trade-offs
# Review code examples
/document authentication module and security patterns
Result: Comprehensive context with decisions, patterns, examples
/document as crystallizing your conversation into searchable knowledge. The richer your conversation, the better the documentation./researchDocuments created with /document become searchable via /research:
# Document legacy code
/research payment processing in this codebase
/document legacy payment system architecture
# Later, new developer uses it
/research payment processing
# Finds your documentation: legacy-payment-system.yaml
If context file already exists:
## Context Conflict Detected
A context file named 'authentication.yaml' already exists.
**Existing context:**
- ID: authentication-module
- Created: 2025-01-05
- Description: JWT-based authentication
**New documentation:**
- Would create: authentication-module-2.yaml
- Topic: OAuth2 authentication integration
**Options:**
A. Merge into existing 'authentication.yaml'
B. Create 'oauth2-authentication.yaml' (new file)
C. Create 'authentication-oauth2-integration.yaml' (descriptive name)
X. Cancel
Choose A-C or X: