Generate Comprehensive Style Guide
Perform a deep analysis of this codebase and generate (or regenerate) a STYLE_GUIDE.md file with full evidence citations for every convention.
When to use this vs /setup-ai: /setup-ai generates a quick-pass style guide as part of initial project setup. This skill is for when you need the thorough version — 17 sections, every convention backed by specific file citations, inconsistencies flagged for human decision. Run this after /setup-ai for more depth, or independently when conventions have drifted.
Rules
- ONLY document patterns you actually observe in the code. Never hallucinate or assume conventions.
- When patterns are inconsistent across the codebase, note the inconsistency and ask the user which convention to standardize on.
- Cite specific files as evidence: "Based on
src/services/UserService.ts, src/services/OrderService.ts..."
- If a STYLE_GUIDE.md already exists, read it first and improve/incorporate rather than overwriting.
Analysis Process
Step 1: Detect Tech Stack
Search for dependency and config files:
| File |
Stack |
package.json |
Node.js / JavaScript / TypeScript |
tsconfig.json |
TypeScript specifically |
Gemfile |
Ruby |
requirements.txt, pyproject.toml, Pipfile |
Python |
go.mod |
Go |
Cargo.toml |
Rust |
composer.json |
PHP |
pom.xml, build.gradle |
Java / Kotlin |
*.csproj, *.sln |
C# / .NET |
Read the dependency file to identify: language version, framework and version, key libraries, build tools, testing framework, linter/formatter configuration.
Step 2: Read Existing Configuration
Check for existing style/convention docs that define rules:
.eslintrc, .eslintrc.json, .eslintrc.js
.prettierrc, .prettierrc.json
.rubocop.yml
.editorconfig
biome.json, biome.jsonc
ruff.toml, pyproject.toml (ruff/black sections)
CLAUDE.md, AGENTS.md, .cursorrules
These are authoritative — extract rules from them directly.
Step 3: Sample Code for Patterns
Read 10-15 representative files — sample strategically, don't try to read everything:
- 3-4 "core" files (models, services, controllers, components)
- 2-3 test files
- 1-2 configuration/setup files
- 1-2 utility/helper files
- 1 entry point or router file
For each file, extract patterns for:
- Naming: camelCase, snake_case, PascalCase, kebab-case — for variables, functions, classes, files
- File naming:
*.service.ts, *_controller.rb, *.spec.js, etc.
- Imports: ordering (stdlib → external → internal), style (named vs default), path aliases
- Exports: named exports, default exports, module.exports, barrel files
- Error handling: try/catch, Result types, error middleware, rescue blocks
- Comments: style, density, JSDoc/RDoc/docstrings
- Types: TypeScript strict mode, JSDoc annotations, Python type hints, none
- Functions: arrow vs declaration, parameter patterns, return style, async/await
Step 4: Identify Testing Patterns
From the test files:
- Framework (Jest, Vitest, RSpec, pytest, Go testing, etc.)
- File naming convention (
*_test.rb, *.spec.ts, *.test.js, test_*.py)
- Test structure (describe/it, test(), class-based, table-driven)
- Fixture/factory patterns
- Mocking approach (jest.mock, factory_bot, unittest.mock)
- Assertion style (expect().toBe, assert, should)
- Test file co-location vs separate directory
Step 5: Check Git History (if available)
Run git log --oneline -20 to see:
- Commit message format (conventional commits? Ticket refs? Free-form?)
Run git branch -a | head -20 to see:
- Branch naming convention (feature/, fix/, etc.)
Generate: STYLE_GUIDE.md
Write to the project root. Use this structure:
# Coding Style Guide
> Auto-generated from codebase analysis on [date]. Review and adjust — these patterns were extracted from your existing code. Where patterns were inconsistent, the most common convention was chosen.
## Language & Formatting
[Indentation: tabs or spaces, width. Line length limit. Semicolons. Quote style. Trailing commas.]
**Evidence:** Based on [cite 2-3 representative files]
## Naming Conventions
### Files & Directories
[Pattern with real examples from the codebase]
### Variables & Functions
[camelCase / snake_case / etc. with real examples]
### Classes, Types & Interfaces
[PascalCase / etc. with real examples]
### Constants
[UPPER_SNAKE_CASE / etc.]
### Database
[Column naming (snake_case?), table naming (plural?), migration naming]
## Code Organization
### File Structure
[Standard order within a file: imports → types → constants → main logic → helpers → exports]
**Evidence:** [cite a file that exemplifies this pattern]
### Import Ordering
[Standard order: stdlib/framework → external packages → internal modules → relative imports]
[Are there path aliases? (@/ or ~/)]
## Function Patterns
[Arrow functions vs declarations. When to use each. Parameter destructuring. Return style. Async/await conventions.]
**Evidence:** [cite examples]
## Error Handling
[The standard error handling pattern — with a real code example copied from the codebase]
## Testing Standards
### File Naming
[Pattern: `*.spec.ts`, `*_test.rb`, etc.]
### Test Structure
[describe/it blocks, test() calls, class-based — with skeleton example]
### What to Test
[Unit tests for what, integration tests for what, what coverage is expected]
### Fixtures & Mocking
[How test data is set up. How external dependencies are mocked.]
## API Patterns
[Endpoint naming. Request validation. Response format (envelope? direct?). Error response format. Status code conventions.]
## Database Patterns
[Migration style. Model/schema definitions. Query conventions. Transactions.]
## Component Patterns (if frontend)
[Component file structure. Props patterns. State management. Styling approach.]
## Git Conventions
[Commit message format. Branch naming. PR description expectations.]
## Anti-Patterns — Do NOT Replicate
[Patterns found in the codebase that should NOT be followed in new code. Legacy approaches being phased out. Inconsistencies being resolved.]
After Generation
- Present a summary to the user: what you found, what looks solid, what was ambiguous
- Highlight any inconsistencies that need a human decision
- Tell the user: "Review this file. I extracted these patterns from your code but your team knows the intent. Edit anything that's wrong or aspirational rather than actual."
- If AGENTS.md doesn't exist yet, suggest: "Run
/setup-ai to generate your AGENTS.md and CLAUDE.md, then it will reference STYLE_GUIDE.md automatically."
- Suggest: "Run
/review-style-guide before PRs to automatically check new code against this style guide."
1---2name: generate-comprehensive-style-guide3description: Deep codebase analysis to generate or regenerate STYLE_GUIDE.md with full evidence citations. Use when /setup-ai's quick pass isn't thorough enough, when conventions have drifted, or after a major refactor. Produces a 17-section style guide citing specific files as evidence.4---56# Generate Comprehensive Style Guide78Perform a deep analysis of this codebase and generate (or regenerate) a **STYLE_GUIDE.md** file with full evidence citations for every convention.910> **When to use this vs `/setup-ai`:** `/setup-ai` generates a quick-pass style guide as part of initial project setup. This skill is for when you need the thorough version — 17 sections, every convention backed by specific file citations, inconsistencies flagged for human decision. Run this after `/setup-ai` for more depth, or independently when conventions have drifted.1112## Rules1314- **ONLY document patterns you actually observe in the code.** Never hallucinate or assume conventions.15- When patterns are inconsistent across the codebase, note the inconsistency and ask the user which convention to standardize on.16- Cite specific files as evidence: "Based on `src/services/UserService.ts`, `src/services/OrderService.ts`..."17- If a STYLE_GUIDE.md already exists, read it first and improve/incorporate rather than overwriting.1819## Analysis Process2021### Step 1: Detect Tech Stack2223Search for dependency and config files:2425| File | Stack |26|------|-------|27| `package.json` | Node.js / JavaScript / TypeScript |28| `tsconfig.json` | TypeScript specifically |29| `Gemfile` | Ruby |30| `requirements.txt`, `pyproject.toml`, `Pipfile` | Python |31| `go.mod` | Go |32| `Cargo.toml` | Rust |33| `composer.json` | PHP |34| `pom.xml`, `build.gradle` | Java / Kotlin |35| `*.csproj`, `*.sln` | C# / .NET |3637Read the dependency file to identify: language version, framework and version, key libraries, build tools, testing framework, linter/formatter configuration.3839### Step 2: Read Existing Configuration4041Check for existing style/convention docs that define rules:42- `.eslintrc`, `.eslintrc.json`, `.eslintrc.js`43- `.prettierrc`, `.prettierrc.json`44- `.rubocop.yml`45- `.editorconfig`46- `biome.json`, `biome.jsonc`47- `ruff.toml`, `pyproject.toml` (ruff/black sections)48- `CLAUDE.md`, `AGENTS.md`, `.cursorrules`4950These are authoritative — extract rules from them directly.5152### Step 3: Sample Code for Patterns5354Read 10-15 representative files — sample strategically, don't try to read everything:55- 3-4 "core" files (models, services, controllers, components)56- 2-3 test files57- 1-2 configuration/setup files58- 1-2 utility/helper files59- 1 entry point or router file6061For each file, extract patterns for:62- **Naming:** camelCase, snake_case, PascalCase, kebab-case — for variables, functions, classes, files63- **File naming:** `*.service.ts`, `*_controller.rb`, `*.spec.js`, etc.64- **Imports:** ordering (stdlib → external → internal), style (named vs default), path aliases65- **Exports:** named exports, default exports, module.exports, barrel files66- **Error handling:** try/catch, Result types, error middleware, rescue blocks67- **Comments:** style, density, JSDoc/RDoc/docstrings68- **Types:** TypeScript strict mode, JSDoc annotations, Python type hints, none69- **Functions:** arrow vs declaration, parameter patterns, return style, async/await7071### Step 4: Identify Testing Patterns7273From the test files:74- Framework (Jest, Vitest, RSpec, pytest, Go testing, etc.)75- File naming convention (`*_test.rb`, `*.spec.ts`, `*.test.js`, `test_*.py`)76- Test structure (describe/it, test(), class-based, table-driven)77- Fixture/factory patterns78- Mocking approach (jest.mock, factory_bot, unittest.mock)79- Assertion style (expect().toBe, assert, should)80- Test file co-location vs separate directory8182### Step 5: Check Git History (if available)8384Run `git log --oneline -20` to see:85- Commit message format (conventional commits? Ticket refs? Free-form?)8687Run `git branch -a | head -20` to see:88- Branch naming convention (feature/, fix/, etc.)8990## Generate: STYLE_GUIDE.md9192Write to the project root. Use this structure:9394```markdown95# Coding Style Guide9697> Auto-generated from codebase analysis on [date]. Review and adjust — these patterns were extracted from your existing code. Where patterns were inconsistent, the most common convention was chosen.9899## Language & Formatting100[Indentation: tabs or spaces, width. Line length limit. Semicolons. Quote style. Trailing commas.]101**Evidence:** Based on [cite 2-3 representative files]102103## Naming Conventions104105### Files & Directories106[Pattern with real examples from the codebase]107108### Variables & Functions109[camelCase / snake_case / etc. with real examples]110111### Classes, Types & Interfaces112[PascalCase / etc. with real examples]113114### Constants115[UPPER_SNAKE_CASE / etc.]116117### Database118[Column naming (snake_case?), table naming (plural?), migration naming]119120## Code Organization121122### File Structure123[Standard order within a file: imports → types → constants → main logic → helpers → exports]124**Evidence:** [cite a file that exemplifies this pattern]125126### Import Ordering127[Standard order: stdlib/framework → external packages → internal modules → relative imports]128[Are there path aliases? (@/ or ~/)]129130## Function Patterns131[Arrow functions vs declarations. When to use each. Parameter destructuring. Return style. Async/await conventions.]132**Evidence:** [cite examples]133134## Error Handling135[The standard error handling pattern — with a real code example copied from the codebase]136137## Testing Standards138139### File Naming140[Pattern: `*.spec.ts`, `*_test.rb`, etc.]141142### Test Structure143[describe/it blocks, test() calls, class-based — with skeleton example]144145### What to Test146[Unit tests for what, integration tests for what, what coverage is expected]147148### Fixtures & Mocking149[How test data is set up. How external dependencies are mocked.]150151## API Patterns152[Endpoint naming. Request validation. Response format (envelope? direct?). Error response format. Status code conventions.]153154## Database Patterns155[Migration style. Model/schema definitions. Query conventions. Transactions.]156157## Component Patterns (if frontend)158[Component file structure. Props patterns. State management. Styling approach.]159160## Git Conventions161[Commit message format. Branch naming. PR description expectations.]162163## Anti-Patterns — Do NOT Replicate164[Patterns found in the codebase that should NOT be followed in new code. Legacy approaches being phased out. Inconsistencies being resolved.]165```166167## After Generation1681691. Present a summary to the user: what you found, what looks solid, what was ambiguous1702. Highlight any inconsistencies that need a human decision1713. Tell the user: "Review this file. I extracted these patterns from your code but your team knows the intent. Edit anything that's wrong or aspirational rather than actual."1724. If AGENTS.md doesn't exist yet, suggest: "Run `/setup-ai` to generate your AGENTS.md and CLAUDE.md, then it will reference STYLE_GUIDE.md automatically."1735. Suggest: "Run `/review-style-guide` before PRs to automatically check new code against this style guide."