Package-level Documentation Strategy¶
Status: Canonical Reference
Scope: Documentation standards forpackages/andrunner/
Audience: Maintainers, Contributors
This document defines the documentation strategy for core modules in this project. It establishes a dual-layer README approach that separates engineering context from system-level documentation.
Table of Contents¶
- Core Principle
- Why Dual-layer READMEs
- Package README Specification
- Docs README Specification
- Relationship with runner/
- Anti-patterns
1. Core Principle¶
Packages are the source of truth.
Tools adapt to packages, never the other way around.
Dependency Direction (One-way Only)¶
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Allowed Dependencies β
β β
β ββββββββββββ ββββββββββββββββ β
β β tools/ β βββββββΊ β src/ β β
β ββββββββββββ ββββββββββββββββ β
β β β β
β β βΌ β
β β ββββββββββββββββ β
β βββββββββββββββΊ β runner/ β β
β ββββββββββββββββ β
β β
β β
tools β packages β
β β
tools β runner β
β β packages β tools (FORBIDDEN) β
β β packages β runner (FORBIDDEN) β
β β runner β packages (FORBIDDEN) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Documentation Implication¶
| Layer | Can mention tools? | Can mention packages? |
|---|---|---|
packages/<pkg>/README.md | β NO | β Yes (dependencies only) |
docs/packages/<pkg>/README.md | β NO | β Yes (system interactions) |
tools/<tool>/README.md | β Yes | β Yes (what it uses) |
docs/tools/<tool>/README.md | β Yes | β Yes |
2. Why Dual-layer READMEs¶
The goal is not to write more documentation, but to establish a maintainable documentation system.
| Layer | Location | Role | Audience |
|---|---|---|---|
| Package README | packages/<pkg>/README.md | Local quick reference | Engineers reading code directly |
| Docs README | docs/packages/<pkg>/README.md | System-level specification | People understanding the overall system |
β οΈ Important: Docs must be under
docs/packages/<pkg>/, notdocs/<pkg>/. Scattered files likedocs/codegen.mdare NOT allowed.
Key Distinction¶
These two layers are not mirrors. They are two perspectives of the same module:
| Aspect | Package README | Docs README |
|---|---|---|
| Perspective | Engineering / Local | Architecture / System |
| Syncs with | Code changes | Design changes |
| Contains | API, file structure, dependencies | Why it exists, system fit, workflows |
| Does NOT contain | System diagrams, workflows | API signatures, implementation details |
3. Package README Specification¶
Location: packages/<pkg>/README.md (or runner/README.md)
3.1 Role¶
- Engineering-oriented
- Quick reference
- Syncs with code
- Does NOT describe system flow
- Does NOT describe tools
- Does NOT describe UX
3.2 Language¶
English only (ε ¨θ±ζ)
3.3 Required Structure¶
Every package MUST have these sections:
# <Package Name>
## Overview
One or two sentences describing what this package provides.
## Responsibility
### What this package does
- β
Explicit responsibility 1
- β
Explicit responsibility 2
### What this package does NOT do
- β Explicit non-responsibility 1 (handled by `<other module>`)
- β Explicit non-responsibility 2
## Public API
| Export | Description |
|--------|-------------|
| `function_or_class` | Purpose |
| `AnotherExport` | Purpose |
## File Structure
## Dependencies
| Direction | Package | Purpose |
|-----------|---------|---------|
| Uses β | `leetcode_datasource` | Problem metadata |
| Uses β | `<other package>` | Reason |
> β **Do NOT list tools here.** Tools depend on packages, not vice versa.
## Related Documentation
- **[Complete Specification](../../docs/packages/<pkg>/README.md)** - System-level documentation
---
## Documentation Maintenance
β οΈ **When modifying this package:**
1. Update this README (quick reference)
2. Update `docs/packages/<pkg>/README.md` (complete specification)
3.4 Explicitly Forbidden Content¶
The following MUST NOT appear in Package README:
| β Forbidden | Reason |
|---|---|
tools/ references | Violates dependency direction |
| CLI commands | That's tool-level concern |
| User workflows | That's UX-level concern |
| System diagrams | That belongs in Docs README |
| UX / interaction patterns | Not package responsibility |
4. Docs README Specification¶
Location: docs/packages/<pkg>/README.md (or docs/runner/README.md)
βΉοΈ Why
docs/runner/NOTdocs/packages/runner/? -runner/is at repo root, not underpackages/- Docs structure mirrors code structure - Onlypackages/<pkg>/βdocs/packages/<pkg>/
4.1 Role¶
- System-oriented
- Architecture documentation
- Explains "why this exists"
- Describes interactions with other modules
- Documents design decisions and boundaries
4.2 Language¶
English primarily (θ±ζηΊδΈ»)
May include Traditional Chinese notes in specific sections (e.g., Design Notes, Pitfalls) following the runner/ style.
4.3 Recommended Structure¶
# <Package Name>
> **Status**: Canonical Reference
> **Scope**: `<pkg>/` - <one-line description>
> **Related**: [Package README](https://github.com/lufftw/neetcode/blob/main/packages/<pkg>/README.md)
<Overview paragraph: why this module exists and what problem it solves>
---
## Overview
Expanded description of the module's purpose and place in the system.
## Scope
### What this module handles
- Responsibility 1
- Responsibility 2
### What this module explicitly avoids
- Non-responsibility 1 (handled by `<other>`)
## Interfaces
High-level summary of public APIs. Do NOT duplicate full API docs here.
| Interface | Purpose |
|-----------|---------|
| `main_function()` | Primary entry point |
| `HelperClass` | Supporting functionality |
## How It Fits in the System
| Module | Relationship |
|--------|--------------|
| `leetcode_datasource` | Provides problem metadata |
| `runner` | Executes generated solutions |
## Typical Workflows
### Workflow: <Name>
1. Step 1 description
2. Step 2 description
3. Step 3 description
> **Note:** Describe internal/system workflows, not user CLI flows.
## Key Design Decisions
| Decision | Rationale |
|----------|-----------|
| Stateless design | Enables parallel execution |
| Single Source of Truth | `solutions/` as canonical location |
## Failure Modes and Constraints
| Constraint | Behavior |
|------------|----------|
| Missing dependency | Raises `ConfigError` |
| Invalid input | Returns empty result |
## Related Documentation
| Document | Content |
|----------|---------|
| [Package README](../../packages/<pkg>/README.md) | Quick reference, API |
| [Solution Contract](../contracts/solution-contract.md) | File format requirements |
4.4 Explicitly Forbidden Content¶
| β Forbidden | Reason |
|---|---|
| Full API reference | Belongs in Package README or docstrings |
| Duplicating Package README | Different perspectives, not mirrors |
| Tool usage details | Tools reference packages, not vice versa |
| CLI flags | Unless the module itself is a CLI |
5. Relationship with runner/¶
The runner/ module is the reference implementation for this documentation strategy:
| Aspect | runner/ Example |
|---|---|
| Package README | runner/README.md - Quick Start, Commands, File Structure |
| Docs README | docs/runner/README.md - Specification, Architecture, Workflows |
What "Reference runner/" Means¶
β Style reference: - Clear responsibility definition - Clear non-responsibility statements - README not polluted by tools
β NOT a structural reference: - Does not mean packages should mirror runner's directory structure - Does not imply dependency inversion
6. Anti-patterns¶
β Anti-pattern 1: Mentioning tools in package docs¶
<!-- BAD -->
## Used By
- `tools/codegen-cli` calls this package
<!-- GOOD -->
## Dependencies
| Direction | Package | Purpose |
|-----------|---------|---------|
| Uses β | `leetcode_datasource` | Problem data |
β Anti-pattern 2: Duplicating content between layers¶
<!-- BAD: Same content in both files -->
src/codegen/README.md: "## How It Works: Step 1, Step 2..."
docs/packages/codegen/README.md: "## How It Works: Step 1, Step 2..."
<!-- GOOD: Different perspectives -->
src/codegen/README.md: "## Public API" (what to call)
docs/packages/codegen/README.md: "## Typical Workflows" (system-level flow)
β Anti-pattern 3: Scattered package docs at docs root¶
<!-- BAD: Package docs at docs/ root -->
docs/codegen.md
docs/leetcode_datasource.md
<!-- GOOD: Package docs under docs/packages/ -->
docs/packages/codegen/README.md
docs/packages/leetcode_datasource/README.md
β Anti-pattern 4: Writing CLI docs in package README¶
Public API¶
```Summary¶
| Principle | Description |
|---|---|
| Packages are source of truth | Tools adapt to packages |
| One-way dependency | tools β packages, never reverse |
| Dual-layer, not duplicate | Different perspectives, not mirrors |
| Package README = Engineering | API, structure, local context |
| Docs README = Architecture | System fit, workflows, design decisions |
Related Documents¶
| Document | Content |
|---|---|
| Docs Directory Organization | docs/ folder structure and migration |
| Documentation Architecture | Overall documentation principles |
Appendix: Migration Notes¶
When migrating existing documentation to this dual-layer structure:
- Identify API-heavy content β Move to Package README (
packages/<pkg>/README.md) - Identify system context β Keep/move to Docs README (
docs/packages/<pkg>/README.md) - Chinese content β Gradually convert to English primarily; Chinese notes acceptable in specific sections
- Avoid duplication β Each layer serves a different audience and purpose