Guides

Generating documentation with Grok Build

View as Markdown

Grok Build reads your code and generates documentation that reflects what the code does: READMEs, API docs, design documents, and architecture overviews. Codebase search helps it capture how components interact across your project, not only within open files.

READMEs and project documentation

Agent example: Generate README
This project has no documentation. Look through the code and generate a comprehensive README covering: purpose, architecture overview, setup instructions, configuration options, and common development tasks.
See the agent's response
Listed project root
Read package.json
Searched codebase main entry points and architecture
Read src/index.ts
Read docker-compose.yml
Thought for 2s
This is a Node.js API with PostgreSQL and Redis. Uses Express with TypeScript. I'll document the setup process based on the actual config files.
CreatedREADME.md+145
# Payment Processing API

A REST API for processing payments with Stripe integration.

## Quick Start

```bash
cp .env.example .env
docker-compose up -d
npm install && npm run dev
```
Generated README.md with:
•Overview: Purpose and tech stack (Node.js, Express, PostgreSQL, Redis)
•Quick Start: 3-step setup from your docker-compose.yml
•Architecture: Service layer diagram from actual code structure
•API Reference: Endpoints from your route files
•Configuration: All env vars from .env.example with descriptions
•Development: Scripts from package.json with explanations

Grok Build can generate READMEs for new projects, update stale READMEs to match current code, or fill in gaps where documentation never existed. The generated docs pull from actual code paths, configuration files, and package dependencies rather than assumptions about how things should work.

For existing projects, ask Grok Build to compare your README against the current codebase and identify what is out of date. This is often faster than reading through docs trying to spot inaccuracies.

Onboarding documentation

New developers spend significant time figuring out how things work: what services exist, how to run them locally, what the common workflows are. Grok Build can generate onboarding docs that answer these questions directly from the codebase.

Agent example: Onboarding guide
Write a getting started guide for new developers joining this project. Cover: cloning the repo, setting up the dev environment, running the app locally, running tests, and making a first change. Document the gotchas that aren't obvious from the code.
See the agent's response
Listed project root
Read package.json
Read docker-compose.yml
Read .env.example
Searched codebase common development workflows
Thought for 2s
I'll document the onboarding steps based on actual config files. The .env.example shows required credentials, docker-compose shows service dependencies.
CreatedGETTING_STARTED.md+185
# Getting Started

Welcome! This guide gets you from zero to running in 15 minutes.

## Prerequisites
- Node.js 18+ (we use 20 in production)
- Docker and Docker Compose
- Access to 1Password vault 'Engineering'

## Step 1: Clone and Install
```bash
git clone [email protected]:company/api.git
cd api && npm install
```
Generated onboarding guide covering:
Prerequisites
•Required tools with version numbers
•Access requirements (1Password, GitHub)
Setup Steps
1.Clone and install
2.Configure environment (with 1Password CLI shortcut)
3.Start services (Postgres, Redis, LocalStack)
4.Run migrations
5.Seed development data
First Tasks
•Run the test suite
•Make a sample API call
•Create your first branch
Gotchas Section
•M1 Mac Docker memory settings
•VPN required for staging APIs
•Slack channel for questions

New developers can get up to speed faster when accurate documentation exists. See also Understanding Unfamiliar Code for how team members can use Grok Build to explore the codebase directly.

Design documents from code

Sometimes you need to document the design of a system that was never formally designed. The implementation exists, but there is no spec explaining why it works the way it does.

Agent example: Design doc from implementation
Reverse-engineer a design document for our payment processing system. Explain the architecture, the key decisions reflected in the code, the constraints it operates under, and how the components interact.
See the agent's response
Searched codebase payment processing system architecture
Read src/services/PaymentService.ts
Read src/services/RefundService.ts
Read src/workers/PaymentWebhookWorker.ts
Thought for 3s
The payment system has three main flows: charge, refund, and webhook handling. Uses idempotency keys for safety. I'll document the design decisions implied by this structure.
Createdpayment-system.md+210
# Payment System Design Document

## Overview
This document describes the payment processing architecture...

## Key Design Decisions
### Idempotency
All payment operations use idempotency keys to prevent...
Generated design document covering:
Architecture
•Component diagram showing PaymentService → Stripe → WebhookWorker flow
•Database schema for payment records
Key Decisions
•Idempotency: Why we use client-generated keys
•Async webhooks: Why payment confirmation is eventual
•Retry strategy: Exponential backoff with jitter
Constraints
•PCI compliance requirements reflected in code
•Rate limits from Stripe integration
Known Limitations
•Multi-currency support is partial (from TODOs in code)

This is useful when onboarding new team members, preparing for audits, or creating handoff documentation for enterprise customers. The design document captures the intent that is implicit in the code but not written down anywhere.

PRDs and specs for handoffs

Product documentation often needs to be generated from existing implementations, especially when handing off to other teams or creating customer-facing specs.

Agent example: PRD from code
Generate a PRD for the user authentication feature based on the current implementation. Include: user stories it supports, technical requirements, API contracts, and any limitations or known issues.
See the agent's response
Searched codebase user authentication feature
Read src/auth/AuthProvider.tsx
Read src/services/AuthService.ts
Read src/middleware/authMiddleware.ts
Thought for 2s
Authentication supports email/password, Google OAuth, and magic links. MFA is implemented but only for admin roles. I'll document user stories and technical requirements.
Createdauthentication.md+156
# Authentication Feature - PRD

## User Stories

### Sign Up
- As a new user, I can sign up with email/password
- As a new user, I can sign up with Google
- As a new user, I receive a verification email

### Sign In
- As a returning user, I can sign in with email/password
- As a returning user, I can request a magic link
Generated PRD from authentication implementation:
User Stories (12 total)
•Sign up: email/password, Google OAuth, email verification
•Sign in: credentials, magic link, remember me
•Session: persistent login, logout, device management
•Security: password reset, MFA for admins
Technical Requirements
•JWT tokens with 7-day expiry
•Refresh token rotation every 24h
•Sessions tracked in Redis for revocation
•Rate limiting: 5 failed attempts → 15 min lockout
API Contracts
•POST /auth/login, /auth/register, /auth/logout
•GET /auth/me, /auth/verify-email
Known Limitations
•MFA only available for admin roles
•No SSO/SAML support yet

This works well when you need to document what was built for product managers, create Confluence pages for stakeholders, or generate Jira tickets that accurately reflect implementation details. See MCP integrations below for connecting Grok Build to these external systems.

API documentation

Agent example: Generate OpenAPI spec
Generate an OpenAPI spec for our REST API. Look at the route handlers in src/routes/ and document each endpoint with its parameters, request body, response schema, and possible error codes.
See the agent's response
Found files src/routes/**/*.ts
Read src/routes/users.ts
Read src/routes/orders.ts
Read src/middleware/validation.ts
Thought for 2s
Found 4 route files with 18 endpoints total. The validation middleware uses Zod schemas - I can extract the request/response shapes from those.
Createdopenapi.yaml+425
openapi: 3.0.3
info:
  title: E-commerce API
  version: 1.0.0
paths:
  /api/users:
    get:
      summary: List users
Generated OpenAPI spec with 18 endpoints:
Users (5 endpoints)
•GET/POST /users, GET/PATCH/DELETE /users/:id
Orders (6 endpoints)
•CRUD plus POST /orders/:id/refund, GET /orders/:id/status
Products (4 endpoints)
•CRUD operations
Webhooks (3 endpoints)
•Stripe, inventory sync, shipping updates
Each endpoint includes request body schemas (from Zod), response shapes, and error codes.

API documentation drifts from implementation faster than almost any other docs. Grok Build can compare your API docs against actual route handlers and flag discrepancies: endpoints that exist but are not documented, documented endpoints that no longer exist, and parameter mismatches.

For internal APIs, this comparison catches breaking changes before they surprise consumers. For external APIs, it ensures your public documentation matches what customers experience.

Keeping documentation current

Documentation drifts from code over time. Grok Build can compare your docs against current implementation and flag what needs updating.

Ask mode example: Find stale documentation
Compare our documentation in docs/ with the current code. What's out of date? What's missing? Prioritize by how likely someone is to encounter the outdated information.
See the agent's response
Found files docs/**/*.md
Read docs/api/authentication.md
Searched codebase authentication implementation
Read docs/setup.md
Read package.json
Documentation Audit Results
Critical (High Impact)
1.docs/api/authentication.md - References /api/auth/login but endpoint changed to /api/v2/auth/login
2.docs/setup.md - Still mentions Node 16, package.json requires Node 18+
3.docs/api/users.md - Missing 3 new endpoints added in last sprint
Moderate (Confusing)
4.README.md - Docker Compose instructions use old service names
5.docs/architecture.md - Diagram shows deprecated Worker service
Low (Minor)
6.docs/testing.md - Jest config path changed
7.CONTRIBUTING.md - Branch naming convention outdated
Missing Documentation
•No docs for the new /api/webhooks endpoints
•Feature flags system undocumented
•Error codes not listed anywhere

The most effective way to keep docs current is to make documentation part of your code review process. Add documentation checks to your Bugbot rules so missing or outdated docs get flagged automatically:

Bugbot rules example: Documentation Checks

Text

# Documentation checks

When reviewing PRs:
- If public API changes, require API docs update
- If new features are added, require README updates
- Flag outdated code comments that reference changed behavior
- Require JSDoc on new exported functions

This catches documentation debt at the source rather than letting it accumulate.

MCP integrations for documentation workflows

MCP integrations connect Grok Build to external documentation systems. If your team uses Confluence, Notion, or similar tools, you can generate documentation and push it directly to where your team expects to find it.

Browse the Marketplace for integrations with Confluence, Jira, Notion, and other documentation platforms. With these connected, you can:

  • Generate a design doc and create a Confluence page in one workflow
  • Create Jira tickets from implementation details
  • Keep external documentation in sync with code changes

This is especially valuable for enterprise teams where documentation lives outside the repository.

Documentation for compliance and audits

Enterprise customers and regulated industries often require formal documentation of systems: how data flows, what security controls exist, how access is managed.

Agent example: Compliance documentation
Generate compliance documentation for our user data handling. Document: what personal data we collect, where it's stored, how it's encrypted, who has access, and how long it's retained. Reference the actual code paths.
See the agent's response
Searched codebase personal data handling and storage
Read src/models/User.ts
Read src/services/DataRetentionService.ts
Read src/middleware/encryption.ts
Grepped encrypt|decrypt|hash
Thought for 3s
User model stores email, name, and hashed password. Encryption middleware uses AES-256-GCM. Data retention service handles GDPR deletion requests.
Createddata-handling.md+178
# Data Handling Documentation

## Personal Data Inventory

| Field | Location | Encrypted | Retention |
|-------|----------|-----------|-----------|
| Email | users.email | No (hashed for lookup) | Account lifetime |
| Password | users.password_hash | Yes (bcrypt) | Account lifetime |
| Name | users.name | No | Account lifetime |
Generated compliance documentation:
Personal Data Inventory
•Table of all PII fields with location, encryption status, retention period
•References actual code paths (User.ts, Profile.ts)
Encryption Details
•At rest: AES-256-GCM for sensitive fields
•In transit: TLS 1.3 required
•Key management: AWS KMS with annual rotation
Access Controls
•Role-based access documented from authMiddleware.ts
•Admin audit logging from AuditService.ts
Data Subject Rights
•Export: DataExportService.ts (JSON/CSV)
•Deletion: DataRetentionService.ts (30-day soft delete, then purge)
•Correction: Standard API endpoints
Retention Schedule
•Active accounts: Indefinite
•Deleted accounts: 30 days
•Audit logs: 7 years
•Session data: 24 hours

Grok Build can trace through your actual implementation to generate documentation that auditors need, grounded in what the code does rather than what a policy document claims it does.

Setting up documentation conventions

Use rules files to ensure consistent documentation across your project.

Create a .cursor/rules/documentation.mdc file:

Rules example: Documentation Conventions

Text

# Documentation Conventions

## READMEs
- Use sentence case for headings
- Include a "Quick Start" section that gets someone running in 5 minutes
- Code examples should be complete and runnable

## Code comments
- Use JSDoc for all exported functions
- Document "why" not "what" in inline comments
- Don't comment obvious code

## API documentation
- Use OpenAPI 3.0 format
- Include example requests and responses
- Document error responses, not just success cases

Getting started

  1. Start with what is missing. Ask Grok Build what documentation your project needs. It will identify gaps based on the code.

  2. Generate from code, then edit. The first draft will be accurate but may lack context only you have. Add the "why" that is not obvious from implementation.

  3. Set up documentation rules. Specify your conventions so generated docs are consistent.

  4. Connect external systems. Use MCP integrations to push documentation to Confluence, Notion, or wherever your team reads docs.

  5. Make docs part of code review. Add Bugbot rules so documentation updates are flagged when code changes.


Last updated: November 23, 2026