| name | python-docs |
| description | Create, update, and sync Python project documentation from source code. Use when asked to document a module, generate API references, create architecture diagrams with Mermaid, update docs after code changes, or keep documentation in sync with source. Triggers include "document", "write docs", "update docs", "sync docs", "architecture diagram", "module docs", "API reference", "document this module", "docs are outdated", or when code changes require corresponding documentation updates. |
Python Documentation
Generate and maintain documentation for Python projects by analyzing source code.
Docs Folder Layout
docs/
โโโ README.md # Project-level documentation index
โโโ artalk/ # ARTalk package docs (maps to src/artalk/)
โ โโโ README.md # ARTalk docs index with module table
โ โโโ architecture.md # System architecture with Mermaid diagrams
โ โโโ core.md # Core types, config, constants
โ โโโ pipeline.md # High-level orchestration API
โโโ modules/ # Non-ARTalk module docs (maps to other src/ packages)
โโโ _template.md # Template for new module docs
โโโ logging_utils.md # Logging utilities (maps to src/logging_utils/)
โโโ segmentation.md # Segmentation module (maps to src/segmentation/)
File Placement Rules
| Source location | Doc location | Index to update |
|---|
src/artalk/ | docs/artalk/<module>.md | docs/artalk/README.md module table |
src/artalk/ (architecture) | docs/artalk/architecture.md | docs/artalk/README.md module table |
src/<other_pkg>/ | docs/modules/<pkg>.md | docs/README.md structure tree |
- ARTalk sub-module docs go in
docs/artalk/ (e.g., motion.md, renderer.md, tracking.md)
- Non-ARTalk package docs go in
docs/modules/
- New module doc template lives at
docs/modules/_template.md
- Cross-references between artalk docs use relative paths:
[core.md](core.md)
- Cross-references from modules/ to artalk/ use:
[artalk](../artalk/)
After Creating/Moving Any Doc
- Update the relevant index (
docs/artalk/README.md or docs/README.md)
- Fix all cross-reference links affected by the change
- Verify no broken relative links remain
Workflow Selection
| Request | Workflow |
|---|
| Document a module | Create Module Doc |
| Architecture / system diagram | Create Architecture Doc |
| Code changed, update docs | Sync Docs |
| Check doc accuracy | Sync Docs (audit mode) |
Create Module Doc
- Determine doc location โ use the file placement rules above
- Explore the module โ read
__init__.py, all .py files, identify public classes, functions, protocols, constants
- Extract structure:
- Classes: name, bases, fields (with types and defaults), methods (with signatures)
- Functions: name, params, return type, docstring summary
- Constants: name, value, type
- Protocols/ABCs: interface contracts
- Identify relationships โ imports between modules, inheritance, composition, protocol implementations
- Write the doc using the template in references/module-template.md
- Update the index โ add entry to
docs/artalk/README.md module table or docs/README.md structure tree
- Verify accuracy โ cross-check every class name, method signature, and constant value against source
Key rules:
- Only document public API (no
_private members unless they are essential)
- Include runnable code examples with expected output
- Use exact types from source โ do not generalize or simplify
- Link to related module docs with relative paths
Create Architecture Doc
- Map the package โ identify all top-level modules and sub-modules
- Trace dependencies โ grep imports to build the dependency graph
- Identify data flow โ follow primary data types through the pipeline, noting tensor shapes or type transformations
- Select diagrams from patterns in references/architecture-template.md:
- System overview (flowchart TD)
- Module dependency graph (flowchart TD)
- Data flow with types/shapes (flowchart TD)
- Configuration hierarchy (classDiagram)
- Subsystem detail (flowchart TD per subsystem)
- Write the doc โ place in the appropriate package docs dir (e.g.,
docs/artalk/architecture.md)
- Update the index โ ensure architecture doc is listed in the package README
- Validate Mermaid โ ensure all
```mermaid blocks use valid syntax: correct diagram type keyword, quoted labels with special characters, proper arrow syntax
Mermaid quick reference:
flowchart TD โ top-down flowchart
flowchart LR โ left-right flowchart
classDiagram โ class/config hierarchy
sequenceDiagram โ temporal interactions
graph LR/TD โ simple directed graph
Node syntax: ID["Label with<br/>line break"], ID{Decision}, ID([Rounded])
Edge syntax: A --> B, A -->|label| B, A -.->|dashed| B
Subgraphs: subgraph "Title" ... end
Sync Docs
When source code changes, update corresponding documentation.
- Detect changes โ use
git diff (or compare source vs docs) to identify what changed:
- New classes, functions, or modules
- Renamed or removed public API
- Changed signatures, types, or default values
- New constants or configuration fields
- Map changes to docs โ use the source-to-doc mapping in references/sync-workflow.md
- Apply updates following the checklist in references/sync-workflow.md
- Verify โ confirm every change in source is reflected in docs, and no stale references remain
Priority order for sync:
- Breaking changes โ removed/renamed API, changed signatures
- New public API โ new classes, functions, modules
- Value changes โ updated constants, defaults, config fields
- Diagrams โ update architecture diagrams if module structure or data flow changed
- Index files โ update
docs/artalk/README.md and docs/README.md if structure changed
Documentation Style
- Heading hierarchy:
# doc title, ## sections, ### subsections, #### items
- Tables for API references (method, description), config options, constants
- Code blocks with language tag (
python, bash, yaml, mermaid)
- Cross-references as relative markdown links:
[core.md](core.md)
- Footer with package version and last-updated date
- Concise prose โ one sentence per concept, no filler
- Match existing doc style in the project when updating