ai generated docs and related tools for publishing new versions * ai generated docs and tooling * tools * add mermaid links * add task docs:ai:generate * Merged main into feature/ai-generated-docs Approved-by: Michael McGuinness
8.1 KiB
Documentation Generation & Testing
This directory contains scripts and prompts for automatically generating comprehensive system documentation using Claude AI.
Directory Structure
prompts/
├── README.md # This file - overview of the system
├── prompt.for.system.documentation.generation.md # Main documentation generation prompt
├── regenerate_docs.sh # Production documentation generation script
├── test.prompt.md # Test prompt for validating the pipeline
└── test_script.sh # Test runner for prompt pipeline validation
Overview
This documentation generation system uses Claude AI to automatically analyze the codebase and produce comprehensive technical documentation. It follows a two-phase approach:
- Testing Phase: Validates the pipeline with a simple test
- Generation Phase: Produces full system documentation
How It Works
Documentation Generation Process
The system uses a comprehensive prompt (prompt.for.system.documentation.generation.md) that instructs Claude to:
-
Analyze the codebase systematically:
- Survey documentation files and entry points
- Map directory structure and major modules
- Trace application startup flows
- Identify architecture patterns
-
Generate structured documentation:
- System overview and architecture
- Service architecture and data flows
- API documentation and schemas
- Developer guides and operational procedures
-
Output to temporary location: All generated docs are placed in
./docs_temp/for review before replacing existing documentation.
Testing Pipeline
Before running full documentation generation, you can validate the pipeline works correctly:
# Run the test to ensure Claude integration works
./test_script.sh
This test:
- Creates a temporary docs directory
- Pipes a simple test prompt to Claude
- Verifies output file generation
- Confirms the pipeline is working
Usage
1. Test the Pipeline (Recommended First Step)
cd docs/ai.generated/prompts
./test_script.sh
Expected Output: Creates ../../docs_temp/test_output.md with test content.
2. Generate Full Documentation
cd docs/ai.generated/prompts
./regenerate_docs.sh <path_to_prompt_file>
Examples:
# Generate full system documentation
./regenerate_docs.sh ./prompt.for.system.documentation.generation.md
# Use relative path from current directory
./regenerate_docs.sh prompt.for.system.documentation.generation.md
# Test with dummy prompt
./regenerate_docs.sh test.prompt.md
Process Flow:
- User provides prompt file path as parameter
- Script validates prompt file exists
- WARNING: User must type 'YES' to confirm expensive operation
- Script validates prerequisites (Claude CLI)
- Creates temporary documentation directory (
docs_temp/) - Pipes the specified prompt to Claude AI
- Claude analyzes the codebase and generates documentation
- Script prompts user to review and optionally replace existing docs
3. Review and Deploy
After generation:
- Review generated documentation in
docs_temp/ - When prompted, choose whether to replace existing docs
- If approved, existing docs are backed up and new ones deployed
Prerequisites
Required Tools
- Claude CLI: Install from https://claude.ai/code
- Bash: For running the generation scripts
- Project Access: Must be run from within the project repository
Environment Setup
The scripts automatically:
- Detect project root directory
- Create necessary temporary directories
- Handle backup of existing documentation
- Provide colored terminal output for clarity
Script Details
regenerate_docs.sh
Purpose: Main production script for documentation generation
Usage: ./regenerate_docs.sh <path_to_prompt_file>
Features:
- Takes prompt file path as parameter for flexibility
- Input validation with helpful usage examples
- WARNING prompt requiring 'YES' confirmation for expensive operations
- Automatic prerequisite checking (Claude CLI, file existence)
- Temporary directory management
- User confirmation before replacing docs
- Automatic backup of existing documentation
- Colored output for better UX
Safety Features:
- Prompt file existence validation before starting
- Warning confirmation (must type exactly 'YES' to proceed)
- Backs up existing docs with timestamp
- User confirmation before destructive operations
- Comprehensive error checking and reporting
test_script.sh
Purpose: Lightweight test to validate the Claude integration pipeline
Features:
- Quick validation of Claude CLI availability
- Simple test prompt execution
- File generation verification
- Pass/fail reporting
Generated Documentation Structure
When successful, the generation process creates:
docs_temp/
├── 01-system-overview.md # High-level architecture and purpose
├── 02-service-architecture.md # Component breakdown and relationships
├── 03-api-documentation.md # REST endpoints and schemas
├── 04-data-architecture.md # Database schemas and data models
├── 05-getting-started.md # Development setup and workflows
├── 06-code-organization.md # Package structure and patterns
├── 07-configuration-management.md # Config options and environment setup
├── 08-operations-guide.md # Deployment and monitoring
└── README.md # Documentation index and navigation
Troubleshooting
Common Issues
-
Claude CLI Not Found
Error: Claude CLI not found. Please install it first.Solution: Install Claude CLI from https://claude.ai/code
-
No Documentation Generated
Error: No documentation was generated in docs_temp/Solutions:
- Check Claude CLI authentication
- Verify project structure is accessible
- Review Claude's output for error messages
-
Permission Issues
Permission denied: ./regenerate_docs.shSolution: Make scripts executable:
chmod +x *.sh
Debugging
- Run test script first to isolate pipeline issues
- Check Claude output for specific error messages
- Verify working directory is project root
- Ensure network connectivity for Claude API access
Maintenance
Updating the Generation Prompt
The main prompt (prompt.for.system.documentation.generation.md) can be modified to:
- Add new documentation sections
- Change analysis methodology
- Adjust output formatting requirements
- Update verification checklist
Script Modifications
Scripts are designed to be maintainable:
- Clear variable definitions at the top
- Comprehensive error checking
- Modular functions for key operations
- Extensive comments explaining logic
Integration with Development Workflow
Recommended Usage Patterns
- After Major Architecture Changes:
./regenerate_docs.sh prompt.for.system.documentation.generation.md - Before Releases: Ensure documentation matches current implementation
- Onboarding New Developers: Fresh, accurate documentation for team members
- API Changes: Keep endpoint documentation synchronized with code
- Testing Pipeline: Always test with dummy prompt first:
./regenerate_docs.sh test.prompt.md
CI/CD Integration Potential
The scripts could be integrated into automated workflows:
- PR Checks: Verify docs stay current with code changes
- Release Automation: Auto-update docs as part of release process
- Scheduled Updates: Regular documentation refreshes
Quality Assurance
The generation process includes verification steps:
- ✅ All major packages documented
- ✅ API endpoints match route definitions
- ✅ Configuration options are complete
- ✅ Database schemas reflect models
- ✅ Deployment instructions match infrastructure
- ✅ Dependencies and versions are current
This ensures generated documentation accurately reflects the actual codebase rather than outdated or aspirational descriptions.