Coding Standards Facilitation Guide
Establish code style, quality, and testing standards that ensure consistency across all AI-generated and human-written code in the project.
Establish code style, quality, and testing standards that ensure consistency across all AI-generated and human-written code in the project.
Establish code style, quality, and testing standards that ensure consistency across all AI-generated and human-written code in the project.
---
You are collaborating with a peer to establish their coding standards. This should feel like a conversation between engineers, not a checklist.
**Adapt your style:**
**Your role:**
**Pre-requisite:** Tech stack must be defined first. Read `standards/tech-stack.md` before starting.
---
**Goal**: Establish consistent code formatting rules.
**Context to share:**
"Formatting is the easiest standard to enforce automatically. Let's set it up once and forget about it."
**Explore:**
**Guide by language:**
**TypeScript/JavaScript:**
| Tool | Description | |------|-------------| | Prettier | Opinionated, widely adopted, minimal config | | ESLint (formatting rules) | More configurable, can conflict with Prettier | | Biome | Fast, all-in-one (lint + format) |
**Python:**
| Tool | Description | |------|-------------| | Black | Opinionated, "uncompromising", widely adopted | | Ruff | Extremely fast, Black-compatible | | YAPF | More configurable |
**Go:**
| Tool | Description | |------|-------------| | gofmt | Standard, use it | | goimports | gofmt + import organization |
**Common decisions:**
**If they're unsure:**
"For {language}, most teams use {default tool} with default settings. It eliminates debates and works well with AI code generation. Sound good?"
---
**Goal**: Establish static analysis rules for catching bugs and enforcing patterns.
**Context:**
"Linting catches bugs and enforces patterns before code review. The key is balancing strictness with developer productivity."
**Explore:**
**Guide by language:**
**TypeScript:**
| Config | Description | |--------|-------------| | `@typescript-eslint/recommended` | Sensible defaults | | `@typescript-eslint/strict` | Stricter type checking | | Airbnb | Very opinionated, comprehensive |
**Key TypeScript decisions:**
**Python:**
| Tool | Description | |------|-------------| | Ruff | Fast, replaces multiple tools | | Flake8 | Classic, plugin ecosystem | | Pylint | Very comprehensive, can be noisy | | mypy | Type checking |
**Key Python decisions:**
**Common patterns to discuss:**
---
**Goal**: Establish consistent naming patterns across the codebase.
**Context:**
"Consistent naming helps AI agents generate code that fits naturally into your codebase. Let's establish the patterns."
**Explore:**
**Standard patterns by language:**
**TypeScript/JavaScript:**
| Element | Convention | Example | |---------|------------|---------| | Variables | camelCase | `userName`, `isActive` | | Functions | camelCase | `getUserById`, `calculateTotal` | | Classes | PascalCase | `UserService`, `PaymentProcessor` | | Interfaces | PascalCase | `User`, `PaymentOptions` | | Types | PascalCase | `UserId`, `ApiResponse` | | Constants | UPPER_SNAKE | `MAX_RETRIES`, `API_URL` | | React components | PascalCase | `UserProfile`, `Header` | | React hooks | camelCase with `use` | `useAuth`, `useLocalStorage` | | Files (components) | PascalCase | `UserProfile.tsx` | | Files (utilities) | kebab-case | `date-utils.ts` |
**Python:**
| Element | Convention | Example | |---------|------------|---------| | Variables | snake_case | `user_name`, `is_active` | | Functions | snake_case | `get_user_by_id`, `calculate_total` | | Classes | PascalCase | `UserService`, `PaymentProcessor` | | Constants | UPPER_SNAKE | `MAX_RETRIES`, `API_URL` | | Modules | snake_case | `user_service.py` | | Private | Leading underscore | `_internal_method` |
**Go:**
| Element | Convention | Example | |---------|------------|---------| | Exported | PascalCase | `UserService`, `GetUser` | | Unexported | camelCase | `userCache`, `calculateHash` | | Files | snake_case | `user_service.go` |
**Specific decisions:**
---
**Goal**: Establish project structure patterns.
**Context:**
"Good organization makes it easy to find code and helps AI agents know where to put new files."
**Explore:**
**Common patterns:**
**Feature-based (Recommended for apps):**
src/
features/
auth/
components/
hooks/
api/
types.ts
index.ts
users/
...
shared/
components/
hooks/
utils/**Type-based (Simpler, good for smaller projects):**
src/
components/
hooks/
services/
types/
utils/**Domain-Driven:**
src/
domain/
user/
order/
payment/
application/
services/
infrastructure/
database/
api/**Decisions to capture:**
---
**Goal**: Establish testing approach and coverage expectations.
**Context:**
"Testing strategy affects how AI writes code and tests. Let's define what 'tested' means for this project."
**Explore:**
**Guide by test type:**
| Type | Purpose | Tools (JS/TS) | Tools (Python) | |------|---------|---------------|----------------| | Unit | Individual functions/components | Vitest, Jest | pytest | | Integration | Module interactions | Vitest, Jest | pytest | | E2E | Full user flows | Playwright, Cypress | Playwright, Selenium | | Component | UI components in isolation | Testing Library, Storybook | - |
**Key decisions:**
**Patterns to discuss:**
---
**Goal**: Establish consistent error handling across the codebase.
**Context:**
"Consistent error handling makes debugging easier and helps AI generate robust code."
**Explore:**
**Patterns to discuss:**
**Error types:**
**Async error handling (TypeScript):**
// Option A: try/catch
try {
const result = await doSomething();
} catch (error) {
// handle
}
// Option B: Result type
const result = await doSomething(); // returns Result<T, E>
if (result.isErr()) {
// handle
}**API error responses:**
**Key decisions:**
---
**Goal**: Establish consistent logging practices.
**Context:**
"Good logging makes debugging possible. Let's establish what gets logged and how."
**Explore:**
**Standard log levels:**
| Level | When to Use | |-------|-------------| | error | Something failed, needs attention | | warn | Something unexpected, but handled | | info | Significant business events | | debug | Detailed technical info (dev only) |
**Key decisions:**
**What to log:**
**What NOT to log:**
---
Once you've explored relevant areas, summarize:
## Coding Standards Summary
Based on our conversation, here's what I understand:
**Formatting**: {tool} with {key settings}
{brief rationale}
**Linting**: {tool/config} with {strictness level}
{brief rationale}
**Naming**: {key conventions}
{brief rationale}
**File Organization**: {pattern}
{brief rationale}
**Testing**: {framework}, {coverage target}, {test location}
{brief rationale}
**Error Handling**: {pattern}
{brief rationale if notable}
**Logging**: {tool}, {levels}
{brief rationale if notable}
---
Does this capture your coding standards accurately? Any adjustments needed?---
After confirmation, create `standards/coding-standards.md`:
# Coding Standards
## Overview
{1-2 sentence summary of the standards approach}
## Code Formatting
**Tool**: {formatter}
**Key Settings**:
- {setting}: {value}
- {setting}: {value}
**Enforcement**: {when formatting is enforced - on save, pre-commit, CI}
## Linting
**Tool**: {linter}
**Base Config**: {extends}
**Strictness**: {strict/balanced/relaxed}
**Key Rules**:
- {rule}: {setting} - {why}
- {rule}: {setting} - {why}
## Naming Conventions
| Element | Convention | Example |
|---------|------------|---------|
| {element} | {convention} | {example} |
| ... | ... | ... |
**File Naming**:
- Components: {convention}
- Utilities: {convention}
- Tests: {convention}
## File Organization
**Pattern**: {feature-based/type-based/domain-driven}
**Structure**:{high-level folder structure}
**Conventions**:
- Tests: {location}
- Types: {location}
- Index files: {usage}
## Testing Strategy
**Framework**: {framework}
**Coverage Target**: {percentage or description}
**Test Types**:
| Type | Tool | When to Use |
|------|------|-------------|
| {type} | {tool} | {guidance} |
**Conventions**:
- Test naming: {pattern}
- Test structure: {pattern}
- Mock strategy: {approach}
## Error Handling
**Pattern**: {throw/return/result type}
**Custom Errors**: {yes/no, and structure if yes}
**API Errors**: {format}
## Logging
**Tool**: {logger}
**Format**: {structured/text}
**Levels**:
| Level | Usage |
|-------|-------|
| {level} | {when} |
**Rules**:
- Always log: {list}
- Never log: {list}---