|
| 1 | +# Doc — Component (Level 3) |
| 2 | + |
| 3 | +Generate or update component-level documentation colocated with the target file or directory. |
| 4 | + |
| 5 | +## What I'll Do |
| 6 | + |
| 7 | +1. Detect the project stack by inspecting project files |
| 8 | +2. Identify the target from the argument, or infer from current file context / recent changes |
| 9 | +3. Read the target file(s) to understand the public API, behavior, and edge cases |
| 10 | +4. Create or update a `<name>.md` file colocated next to the target |
| 11 | +5. Tailor content to the detected stack profile |
| 12 | + |
| 13 | +## How to Use |
| 14 | + |
| 15 | +``` |
| 16 | +/doc-component # infer from current file |
| 17 | +/doc-component src/components/Button.tsx # target a specific file |
| 18 | +/doc-component lib/utils/parser.js # target a utility |
| 19 | +/doc-component internal/auth/ # target a directory (documents all files in it) |
| 20 | +``` |
| 21 | + |
| 22 | +## Stack Detection |
| 23 | + |
| 24 | +Inspect the project root to determine the stack profile: |
| 25 | + |
| 26 | +| Profile | Detected by | |
| 27 | +|---------|------------| |
| 28 | +| **frontend** | `package.json` with react / vue / angular / svelte / nextjs / nuxt dependency | |
| 29 | +| **backend-node** | `package.json` without a frontend framework | |
| 30 | +| **backend-typed** | `go.mod` (Go), `Cargo.toml` (Rust), `pom.xml` or `build.gradle` (Java) | |
| 31 | +| **scripting** | `requirements.txt` or `pyproject.toml` (Python), `Gemfile` (Ruby), `composer.json` (PHP) | |
| 32 | +| **generic** | None of the above | |
| 33 | + |
| 34 | +## Output: `<target-name>.md` colocated with the target |
| 35 | + |
| 36 | +If the target is `src/components/Button.tsx`, create `src/components/Button.md`. |
| 37 | +If the target is `internal/auth/`, create `internal/auth/README.md`. |
| 38 | +If the doc file already exists, update in place. |
| 39 | + |
| 40 | +### Structure to generate: |
| 41 | + |
| 42 | +```markdown |
| 43 | +# <ComponentName / ModuleName> |
| 44 | + |
| 45 | +## Purpose |
| 46 | +[One sentence: what this does] |
| 47 | + |
| 48 | +## API / Props |
| 49 | +[table or list of inputs, parameters, or exported symbols] |
| 50 | + |
| 51 | +## Usage |
| 52 | +[code example(s)] |
| 53 | + |
| 54 | +## Behavior & Edge Cases |
| 55 | +[non-obvious logic, error states, boundary conditions] |
| 56 | + |
| 57 | +## Where It's Used |
| 58 | +[list of known consumers — files that import this] |
| 59 | +``` |
| 60 | + |
| 61 | +### Artifacts by stack profile: |
| 62 | + |
| 63 | +**frontend** (React / Vue / Angular / Svelte) |
| 64 | +- Props table: name, type, required, default, description |
| 65 | +- Emits / events (Vue) |
| 66 | +- Slots (Vue/Svelte) or children patterns (React) |
| 67 | +- Usage code example with JSX/template |
| 68 | +- CSS/Tailwind class notes if relevant |
| 69 | + |
| 70 | +**backend-node** |
| 71 | +- Exported function signatures |
| 72 | +- Parameters and return values |
| 73 | +- Middleware signature if applicable |
| 74 | +- Usage example |
| 75 | + |
| 76 | +**backend-typed** (Go / Rust / Java) |
| 77 | +- Exported types, structs, interfaces, traits |
| 78 | +- Function/method signatures with types |
| 79 | +- Usage example in the target language |
| 80 | + |
| 81 | +**scripting** (Python / Ruby / PHP) |
| 82 | +- Class/function signatures |
| 83 | +- Parameters with types (type hints if available) |
| 84 | +- Usage example |
| 85 | + |
| 86 | +**generic** |
| 87 | +- Exported symbols and descriptions |
| 88 | +- Usage example if discernible |
| 89 | + |
| 90 | +## Standards Applied |
| 91 | + |
| 92 | +- `.contextkit/standards/architecture.md` — 3-level documentation hierarchy (Component Level) |
0 commit comments