Skip to content

AI-powered code & API documentation generator. Automatically analyzes source code and generates comprehensive, human-readable documentation with examples, diagrams, and explanations using LLMs (OpenAI GPT-4, Anthropic Claude).

License

Notifications You must be signed in to change notification settings

srdarkseer/AutoDoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AutoDoc - Intelligent Code & API Documentation Generator

πŸ“– What is AutoDoc?

AutoDoc is an intelligent, AI-powered platform that automatically analyzes source code and APIs to generate comprehensive, human-readable documentation. It combines static code analysis with Large Language Models (LLMs) to create detailed documentation, examples, diagrams, and explanations that help developers understand codebases quickly.

Key Capabilities

  • πŸ” Automatic Code Analysis: Parses and analyzes multiple programming languages
  • πŸ€– AI-Powered Explanations: Uses OpenAI GPT-4 or Anthropic Claude to generate intelligent documentation
  • πŸ“š Multi-Format Output: Generates Markdown documentation with code examples and diagrams
  • πŸ–₯️ CLI & API: Command-line tool for local use and REST API for integration
  • πŸ“Š Project Insights: Analyzes project structure, dependencies, and code patterns
  • πŸ’Ύ History Tracking: Stores documentation versions and analysis history in SQLite
  • 🐳 Docker Ready: Fully containerized for easy deployment

πŸ—οΈ Architecture

AutoDoc follows a microservices architecture with two main components:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Client Layer                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚   CLI Tool   β”‚  β”‚  REST API    β”‚  β”‚  Web UI      β”‚       β”‚
β”‚  β”‚  (Commander) β”‚  β”‚  (Express)   β”‚  β”‚  (Future)    β”‚       β”‚ 
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚  
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                  β”‚                    β”‚
        β–Ό                  β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Node.js    β”‚   β”‚   Python     β”‚   β”‚   SQLite     β”‚
β”‚   Backend    │◄───   AI Service β”‚   β”‚   Database   β”‚
β”‚              β”‚   β”‚              β”‚   β”‚              β”‚
β”‚  - Analyzers β”‚   β”‚  - LLM APIs  β”‚   β”‚  - Analyses  β”‚
β”‚  - Parsers   β”‚   β”‚  - Diagram   β”‚   β”‚  - Docs      β”‚
β”‚  - Generatorsβ”‚   β”‚  - Generationβ”‚   β”‚  - History   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                  β”‚
        β”‚                  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚  Source Code β”‚
           β”‚  Repository  β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Details

1. Node.js Backend (TypeScript + Express)

  • Purpose: Core analysis engine and API server
  • Responsibilities:
    • File ingestion and parsing
    • Project structure analysis
    • Dependency detection
    • Code element extraction (functions, classes, imports, etc.)
    • Documentation generation orchestration
    • Database operations
    • REST API endpoints

2. Python AI Service (Flask)

  • Purpose: Intelligent documentation enhancement
  • Responsibilities:
    • LLM integration (OpenAI/Anthropic)
    • Natural language documentation generation
    • Code explanations and summaries
    • Mermaid diagram generation
    • Enhanced documentation quality

3. SQLite Database

  • Purpose: Data persistence
  • Stores:
    • Project analysis results
    • Generated documentation
    • Analysis history and metadata
    • Version tracking

Data Flow

1. User Input (CLI/API)
   ↓
2. Node.js Backend receives project path
   ↓
3. Project Analyzer scans directory structure
   ↓
4. Code Parser extracts code elements per file
   ↓
5. Dependency Analyzer detects dependencies
   ↓
6. Analysis stored in SQLite database
   ↓
7. Documentation Generator creates base markdown
   ↓
8. Python AI Service enhances with LLM (optional)
   ↓
9. Final documentation stored and returned

πŸ“ Project Structure

AutoDoc/
β”œβ”€β”€ src/                          # TypeScript source code
β”‚   β”œβ”€β”€ index.ts                 # Main Express server entry point
β”‚   β”œβ”€β”€ analyzers/               # Code analysis modules
β”‚   β”‚   β”œβ”€β”€ projectAnalyzer.ts   # Main project analysis orchestrator
β”‚   β”‚   β”œβ”€β”€ dependencyAnalyzer.ts # Dependency detection (npm, pip, go, etc.)
β”‚   β”‚   └── structureAnalyzer.ts # Directory structure and file analysis
β”‚   β”œβ”€β”€ parsers/                 # File parsing utilities
β”‚   β”‚   └── codeParser.ts        # Multi-language code parser
β”‚   β”œβ”€β”€ generators/              # Documentation generators
β”‚   β”‚   └── docGenerator.ts      # Markdown documentation generator
β”‚   β”œβ”€β”€ database/                # Database operations
β”‚   β”‚   └── databaseManager.ts   # SQLite operations and schema
β”‚   └── types/                   # TypeScript type definitions
β”‚       └── index.ts             # Comprehensive type system
β”‚
β”œβ”€β”€ python-service/              # Python AI service
β”‚   β”œβ”€β”€ app.py                   # Flask application and LLM service
β”‚   β”œβ”€β”€ requirements.txt         # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile               # Python service containerization
β”‚   └── README.md                # Python service documentation
β”‚
β”œβ”€β”€ bin/                         # CLI executable
β”‚   └── autodoc.ts               # Command-line interface entry point
β”‚
β”œβ”€β”€ tests/                       # Test files
β”‚   └── core.test.ts             # Core functionality tests
β”‚
β”œβ”€β”€ templates/                   # Documentation templates (future)
β”œβ”€β”€ output/                      # Generated documentation output
β”œβ”€β”€ database/                    # SQLite database files
β”‚   └── autodoc.db              # Main database file
β”‚
β”œβ”€β”€ Dockerfile                   # Node.js backend containerization
β”œβ”€β”€ docker-compose.yml           # Multi-service orchestration
β”œβ”€β”€ docker.sh                    # Docker helper scripts
β”œβ”€β”€ .dockerignore               # Docker build exclusions
β”‚
β”œβ”€β”€ package.json                 # Node.js dependencies and scripts
β”œβ”€β”€ tsconfig.json               # TypeScript configuration
β”œβ”€β”€ .eslintrc.json              # ESLint configuration
β”œβ”€β”€ .babelrc                    # Babel configuration
β”œβ”€β”€ env.example                 # Environment variables template
β”‚
└── README.md                   # This file

πŸ”§ Technical Stack

Backend (Node.js/TypeScript)

  • Runtime: Node.js 18+
  • Language: TypeScript 5.3+
  • Framework: Express.js 4.18+
  • Database: SQLite3
  • Key Libraries:
    • commander - CLI interface
    • chalk - Terminal colors
    • ora - Spinners and progress
    • fs-extra - Enhanced file operations
    • glob - File pattern matching
    • multer - File uploads
    • axios - HTTP requests

AI Service (Python)

  • Runtime: Python 3.11+
  • Framework: Flask 2.3+
  • Key Libraries:
    • openai - OpenAI GPT integration
    • anthropic - Claude API integration
    • requests - HTTP client
    • flask-cors - CORS support

Infrastructure

  • Containerization: Docker & Docker Compose
  • Database: SQLite (file-based, no server required)
  • Deployment: Multi-container architecture

πŸš€ Quick Start

Installing AutoDoc

# Clone the repository
git clone https://github.com/srdarkser/autodoc.git
cd autodoc

# Install dependencies
npm install

# Build the project
npm run build

# (Optional) Install globally for CLI access
npm install -g .

Using Docker (Recommended)

# Build and start all services
docker-compose up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Generate Documentation for Any Project

Simple CLI Usage:

# Analyze any project on your system
autodoc analyze /path/to/your/project

# Example: Document a React app
autodoc analyze ~/projects/my-react-app --output ./documentation

# Example: Document current directory
cd ~/my-project
autodoc analyze . --output ./docs

Using REST API:

# Start the server
autodoc serve  # or: docker-compose up -d

# Analyze via API
curl -X POST http://localhost:3000/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"projectPath": "/path/to/your/project"}'

πŸ“– For detailed usage instructions, see USAGE.md

Manual Installation

# Install Node.js dependencies
npm install

# Install Python dependencies
cd python-service
pip install -r requirements.txt
cd ..

# Build TypeScript
npm run build

# Start backend server
npm start

# In another terminal, start Python AI service
cd python-service
python app.py

Using CLI

# Initialize AutoDoc configuration
autodoc init

# Analyze a project
autodoc analyze ./my-project

# Analyze with options
autodoc analyze ./my-project --output ./docs --include-tests

# Start the server
autodoc serve --port 3000

🌐 API Endpoints

Backend API (Port 3000)

Method Endpoint Description
GET /health Health check
POST /api/analyze Analyze a project
POST /api/generate-docs Generate documentation
GET /api/analyses Get all analyses
GET /api/docs/:id Get documentation by ID

Python AI Service API (Port 5001)

Method Endpoint Description
GET /health Health check
POST /api/generate-docs Generate AI-enhanced documentation
POST /api/analyze-code Analyze code snippets
POST /api/generate-diagram Generate Mermaid diagrams

Example API Usage

# Analyze a project
curl -X POST http://localhost:3000/api/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "projectPath": "/path/to/project",
    "options": {
      "includeTests": false,
      "maxFileSize": 1048576
    }
  }'

# Generate documentation
curl -X POST http://localhost:3000/api/generate-docs \
  -H "Content-Type: application/json" \
  -d '{
    "analysisId": "analysis-id-here",
    "template": "default",
    "options": {
      "includeDiagrams": true,
      "includeExamples": true
    }
  }'

πŸ“Š Supported Languages

AutoDoc supports analysis of the following languages:

Fully Supported

  • βœ… JavaScript (ES6+)
  • βœ… TypeScript
  • βœ… Python 3
  • βœ… Java
  • βœ… Go
  • βœ… Rust

Partially Supported

  • πŸ”Ά C/C++
  • πŸ”Ά C#
  • πŸ”Ά PHP
  • πŸ”Ά Ruby
  • πŸ”Ά Swift
  • πŸ”Ά Kotlin

Dependency Detection

  • βœ… Node.js (package.json, package-lock.json, yarn.lock)
  • βœ… Python (requirements.txt, pyproject.toml, setup.py)
  • βœ… Java (pom.xml, build.gradle)
  • βœ… Go (go.mod, go.sum)
  • βœ… Rust (Cargo.toml, Cargo.lock)

πŸ€– AI Integration

AutoDoc supports multiple LLM providers for enhanced documentation:

OpenAI GPT-4

export OPENAI_API_KEY="sk-..."
export LLM_PROVIDER="openai"

Anthropic Claude

export ANTHROPIC_API_KEY="sk-ant-..."
export LLM_PROVIDER="anthropic"

Mock Mode (No API Keys)

AutoDoc automatically falls back to mock documentation generation if no API keys are provided.

πŸ“ Features

Code Analysis

  • Multi-file Analysis: Scans entire projects recursively
  • Pattern Detection: Identifies functions, classes, interfaces, types, etc.
  • Import Tracking: Maps dependencies between files
  • Comment Extraction: Captures and preserves documentation comments
  • Structure Mapping: Generates project hierarchy diagrams

Documentation Generation

  • Markdown Format: Clean, developer-friendly markdown output
  • Code Examples: Extracts and formats code snippets
  • Mermaid Diagrams: Generates flowcharts and class diagrams
  • API Documentation: Auto-generates API reference from code
  • Usage Examples: Creates example usage patterns

Advanced Features

  • History Tracking: Stores all analysis runs for comparison
  • Version Control: Tracks documentation versions
  • Custom Templates: Support for custom documentation templates
  • Batch Processing: Analyze multiple projects simultaneously
  • Export Formats: Markdown, HTML (future), PDF (future)

πŸ”§ Configuration

Environment Variables

Create a .env file based on env.example:

# LLM Configuration
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
LLM_PROVIDER=openai

# Service Configuration
PORT=3000
PYTHON_SERVICE_PORT=5000
NODE_ENV=development

# Database
DATABASE_PATH=database/autodoc.db

# Output
OUTPUT_DIRECTORY=./docs
TEMPLATE=default
FORMAT=markdown

CLI Configuration

After running autodoc init, you can customize .autodoc.json:

{
  "version": "1.0.0",
  "analysis": {
    "includePatterns": ["**/*.js", "**/*.ts", "**/*.py"],
    "excludePatterns": ["node_modules/**", ".git/**"],
    "maxFileSize": 1048576,
    "includeTests": false,
    "includeComments": true
  },
  "output": {
    "directory": "./docs",
    "format": "markdown",
    "template": "default",
    "includeDiagrams": true
  }
}

πŸ§ͺ Development

Prerequisites

  • Node.js 18+ and npm
  • Python 3.11+ and pip
  • Docker and Docker Compose (optional)

Development Workflow

# Install all dependencies
npm install
cd python-service && pip install -r requirements.txt && cd ..

# Run TypeScript in watch mode
npm run dev:watch

# Run Python service
npm run python:start

# Run linting
npm run lint
npm run lint:fix

# Run tests
npm test

# Build for production
npm run build

Code Structure

  • TypeScript: Strict mode enabled with comprehensive type checking
  • Error Handling: Try-catch blocks with proper error responses
  • Logging: Console logging with structured output
  • Validation: Input validation on all API endpoints
  • Type Safety: Complete TypeScript coverage with no any types

πŸ“¦ Deployment

Docker Deployment

# Build images
docker-compose build

# Start services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Production Considerations

  1. Environment Variables: Set secure API keys
  2. Database Backup: Regularly backup SQLite database
  3. Resource Limits: Configure Docker resource limits
  4. Reverse Proxy: Use nginx for production
  5. SSL/TLS: Enable HTTPS for API endpoints
  6. Monitoring: Set up logging and monitoring

🎯 Use Cases

  • Open Source Projects: Generate comprehensive docs for GitHub repositories
  • Enterprise Codebases: Document large, complex projects automatically
  • API Documentation: Generate API docs from code analysis
  • Code Reviews: Understand project structure before reviews
  • Developer Onboarding: Help new developers understand codebases quickly
  • Compliance: Generate documentation for regulatory requirements
  • Knowledge Transfer: Preserve institutional knowledge
  • Technical Writing: Base content for technical writers

🀝 Contributing

We welcome contributions! Please follow these steps:

  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 'feat: add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“„ License

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

πŸ™ Acknowledgments

  • OpenAI and Anthropic for LLM APIs
  • Express.js and Flask communities
  • All contributors and users of AutoDoc

Author: Sushant R. Dangal

About

AI-powered code & API documentation generator. Automatically analyzes source code and generates comprehensive, human-readable documentation with examples, diagrams, and explanations using LLMs (OpenAI GPT-4, Anthropic Claude).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published