Skip to content

manan45/autodoc

Repository files navigation

๐Ÿš€ Auto Documentation Generation System

An intelligent system that automatically analyzes your codebase and generates comprehensive documentation, with specialized support for AI/ML pipelines.

Python License Status

๐ŸŒŸ Features

  • ๐Ÿ” Intelligent Code Analysis: AST-based Python code analysis with complexity metrics
  • ๐Ÿค– AI/ML Pipeline Detection: Specialized analysis for machine learning components
  • ๐Ÿ“š Comprehensive Documentation: Generates multiple documentation sections automatically
  • ๐Ÿ“Š Visual Diagrams: Architecture diagrams and data flow visualizations
  • ๐Ÿ—„๏ธ Supabase Integration: Complete data logging, monitoring, and debug interface
  • ๐Ÿ”„ CI/CD Integration: GitHub Actions workflow for automated documentation updates
  • ๐ŸŽจ Beautiful Output: MkDocs Material theme with modern UI
  • โšก Fast & Efficient: Optimized for large codebases

๐Ÿ“‹ Generated Documentation

The system automatically generates:

  • ๐Ÿ“– Project Overview: High-level project statistics and summary
  • ๐Ÿ—๏ธ Architecture Documentation: System design and component relationships
  • ๐Ÿ“‹ API Reference: Detailed function and class documentation
  • ๐Ÿ‘ฅ Onboarding Guide: New developer getting-started guide
  • ๐Ÿค– AI/ML Documentation: Machine learning models and pipelines (if detected)
  • ๐Ÿ“Š Code Quality Reports: Complexity analysis and metrics

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone <your-repo-url>
cd auto_doc_generator

# Install dependencies
pip install -r requirements.txt

# Or install as a package
pip install -e .

Basic Usage

# Analyze current directory and generate documentation
python src/main.py --analyze --generate

# Analyze, generate, and build MkDocs site
python src/main.py --analyze --generate --build

# Serve documentation locally
python src/main.py --serve

# Analyze specific repository
python src/main.py --repo /path/to/your/project --analyze --generate

Docker Usage

# Build Docker image
docker build -t auto-doc-generator .

# Run analysis on your project
docker run -v /path/to/your/project:/app/source -v /path/to/output:/app/docs auto-doc-generator --repo /app/source

๐Ÿ“ Project Structure

auto_doc_generator/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ analyzers/
โ”‚   โ”‚   โ”œโ”€โ”€ code_analyzer.py      # Core code analysis
โ”‚   โ”‚   โ””โ”€โ”€ ai_pipeline_analyzer.py # AI/ML detection
โ”‚   โ”œโ”€โ”€ generators/
โ”‚   โ”‚   โ”œโ”€โ”€ markdown_generator.py # Documentation generation
โ”‚   โ”‚   โ””โ”€โ”€ diagram_generator.py  # Visual diagram creation
โ”‚   โ”œโ”€โ”€ supabase_integration.py  # Supabase logging & storage
โ”‚   โ”œโ”€โ”€ debug_interface.py       # Web debug interface
โ”‚   โ””โ”€โ”€ main.py                   # Main entry point
โ”œโ”€โ”€ config/
โ”‚   โ”œโ”€โ”€ doc_config.yaml          # Main configuration
โ”‚   โ””โ”€โ”€ analysis_rules.yaml      # Analysis rules
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ base_template.md         # Base documentation template
โ”‚   โ”œโ”€โ”€ architecture_template.md # Architecture documentation
โ”‚   โ”œโ”€โ”€ api_template.md          # API reference template
โ”‚   โ””โ”€โ”€ onboarding_template.md   # Onboarding guide template
โ”œโ”€โ”€ .github/workflows/
โ”‚   โ””โ”€โ”€ auto-doc.yml             # GitHub Actions workflow
โ”œโ”€โ”€ docs/                        # Generated documentation output
โ”œโ”€โ”€ setup_supabase.py            # Supabase setup script
โ”œโ”€โ”€ supabase_setup.sql           # Complete database setup (handles all scenarios)
โ”œโ”€โ”€ start_debug_server.py        # Debug interface launcher
โ”œโ”€โ”€ Dockerfile                   # Container definition
โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ””โ”€โ”€ README.md                    # This file

โš™๏ธ Configuration

Basic Configuration (config/doc_config.yaml)

analysis:
  include_patterns:
    - "*.py"
    - "*.js"
    - "*.ts"
  exclude_patterns:
    - "*/tests/*"
    - "*/__pycache__/*"
  
  ai_analysis:
    detect_frameworks: true
    analyze_pipelines: true
    generate_flow_diagrams: true

generation:
  output_format: "mkdocs"
  theme: "material"
  include_diagrams: true
  include_api_docs: true

deployment:
  target: "github_pages"
  auto_deploy: true

Analysis Rules (config/analysis_rules.yaml)

complexity_thresholds:
  cyclomatic:
    low: 5
    medium: 10
    high: 15

code_patterns:
  ai_pipeline:
    - "class.*Pipeline"
    - "def.*train"
    - "def.*predict"

๐Ÿ—„๏ธ Supabase Integration

The system includes comprehensive Supabase integration for logging, data storage, and monitoring of the documentation generation process.

Features

  • ๐Ÿ“Š Analysis Tracking: Complete analysis results storage
  • ๐Ÿค– LLM Logging: All AI/LLM interactions with metrics
  • ๐ŸŽฏ Vector Embeddings: Code embeddings with pgvector for fast semantic search
  • ๐Ÿ”ฌ Quality Assessments: Module quality metrics and insights
  • ๐Ÿ“š Documentation Tracking: Generation metadata and results
  • ๐Ÿ” Debug Interface: Web-based monitoring dashboard

Quick Setup

  1. Create Supabase Project:

    • Go to supabase.com and create a new project
    • Note your project URL and anon key
  2. Set Environment Variables:

    export SUPABASE_URL='https://your-project-ref.supabase.co'
    export SUPABASE_ANON_KEY='your-supabase-anon-key'
  3. Run Setup Script:

    python setup_supabase.py
  4. Execute Database Schema:

    • Copy contents of supabase_setup.sql and execute in Supabase SQL Editor
    • This single file handles both new setups and existing installations automatically

Database Tables

The system creates 6 tables for comprehensive data storage:

Table Purpose
analysis_steps Track each step of the analysis process
llm_interactions Log all AI/LLM requests and responses
vector_embeddings Store code embeddings using pgvector for fast semantic search
quality_assessments Module quality metrics and LLM insights
complete_analysis_results Full analysis data (code, AI, quality)
documentation_generations Documentation generation tracking

Debug Interface

Monitor your data with the web-based debug interface:

# Start debug server
python start_debug_server.py

# Visit dashboard
open http://localhost:5001

Available Endpoints:

  • /api/database-stats - Database statistics
  • /api/llm-interactions - Recent AI interactions
  • /api/analysis-steps - Analysis step history
  • /api/complete-analysis-results - Full analysis data
  • /api/documentation-generations - Documentation tracking
  • /api/vector-embeddings/search - Semantic code search

Configuration

Add Supabase configuration to your documentor.yaml:

supabase:
  enabled: true
  url: ${SUPABASE_URL}
  key: ${SUPABASE_ANON_KEY}

# Optional: Customize logging behavior
logging:
  supabase:
    log_analysis_steps: true
    log_llm_interactions: true
    log_quality_assessments: true
    log_complete_results: true
    log_documentation: true

Usage with Analysis

The system automatically logs data when Supabase is configured:

# Run analysis with Supabase logging
python -m auto_doc_generator.main --analyze --generate

# Start debug interface to monitor
python start_debug_server.py

Data Retention

  • Development: Data stored indefinitely
  • Production: Consider implementing data retention policies
  • Privacy: All data stored in your Supabase instance

For detailed setup instructions, see SUPABASE_INTEGRATION.md.

๐Ÿ”„ CI/CD Integration

GitHub Actions

The system includes a pre-configured GitHub Actions workflow:

  1. Automatic Triggers: Runs on push to main branch and merged PRs
  2. Documentation Generation: Analyzes code and generates docs
  3. GitHub Pages Deployment: Automatically deploys to GitHub Pages
  4. Quality Checks: Lints documentation and runs completeness checks

Setup Steps

  1. Copy .github/workflows/auto-doc.yml to your repository
  2. Enable GitHub Pages in repository settings
  3. Push changes to trigger the workflow
  4. Documentation will be available at https://username.github.io/repository-name/

๐Ÿ› ๏ธ Advanced Usage

Custom Analysis

from src.analyzers.code_analyzer import CodeAnalyzer
from src.analyzers.ai_pipeline_analyzer import AIPipelineAnalyzer

# Initialize analyzers
code_analyzer = CodeAnalyzer("/path/to/project")
ai_analyzer = AIPipelineAnalyzer()

# Perform analysis
code_results = code_analyzer.analyze_codebase()
ai_results = ai_analyzer.analyze_ai_components("/path/to/project")

Custom Documentation Generation

from src.generators.markdown_generator import MarkdownGenerator

# Initialize generator
generator = MarkdownGenerator("templates", "output")

# Generate specific documentation
docs = generator.generate_all_documentation(code_results, ai_results)
generator.save_documentation(docs)

๐ŸŽฏ AI/ML Support

The system provides specialized analysis for:

  • ๐Ÿค– Model Detection: Identifies ML models, classifiers, and regressors
  • โšก Pipeline Analysis: Detects data processing pipelines
  • ๐Ÿ“ˆ Training Scripts: Finds model training functions
  • ๐Ÿ”ฎ Inference Endpoints: Locates prediction/inference code
  • ๐Ÿ“Š Experiment Tracking: Detects MLflow, WandB, TensorBoard usage
  • ๐Ÿ—„๏ธ Data Sources: Identifies data loading and processing patterns

Supported Frameworks

  • TensorFlow/Keras
  • PyTorch
  • Scikit-learn
  • Pandas/NumPy
  • MLflow
  • Weights & Biases (WandB)
  • XGBoost/LightGBM
  • Hugging Face Transformers

๐Ÿ“Š Code Quality Metrics

The system analyzes:

  • Cyclomatic Complexity: Function complexity scoring
  • Maintainability Index: Code maintainability metrics
  • Halstead Metrics: Software complexity measures
  • Dependency Analysis: Module interdependencies
  • Architecture Patterns: Design pattern detection

๐Ÿ”ง Troubleshooting

Common Issues

Issue: Import errors when running analysis

# Solution: Set PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"
python src/main.py --analyze --generate

Issue: MkDocs not found

# Solution: Install MkDocs
pip install mkdocs mkdocs-material

Issue: Diagrams library errors

# Solution: Install system dependencies
sudo apt-get install graphviz graphviz-dev
pip install diagrams

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests if applicable
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Setup

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/

# Lint code
flake8 src/

๐Ÿ“ˆ Performance

  • Analysis Speed: ~1000 lines of code per second
  • Memory Usage: <100MB for typical projects
  • Output Size: ~1-5MB documentation for medium projects
  • Build Time: 30-60 seconds for full documentation generation

๐Ÿ”’ Security

  • No external API calls during analysis
  • Local processing only
  • Configurable file inclusion/exclusion
  • Safe AST parsing without code execution

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with MkDocs and Material theme
  • Code analysis powered by Python AST and Radon
  • Diagrams created with Diagrams library
  • Inspired by the need for always up-to-date documentation

๐Ÿ“ž Support

  • ๐Ÿ“ง Create an issue for bug reports or feature requests
  • ๐Ÿ’ฌ Check existing issues for solutions
  • ๐Ÿ“– Read the generated documentation for usage examples

Auto-generated documentation for the win! ๐ŸŽ‰

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors