90 lines
3.3 KiB
Rust
90 lines
3.3 KiB
Rust
//! # Real-World: Automated Documentation Generation
|
|
//!
|
|
//! Generate comprehensive API documentation using specialized agents.
|
|
//!
|
|
//! ## Business Problem
|
|
//! Keep API documentation in sync with code changes (currently 2 weeks behind).
|
|
//!
|
|
//! ## Solution
|
|
//! Multi-agent pipeline: Code Analyzer → Doc Writer → Quality Checker
|
|
//!
|
|
//! ## Run
|
|
//! ```bash
|
|
//! cargo run --example 02-documentation-generation
|
|
//! ```
|
|
|
|
fn main() {
|
|
println!("=== Real-World: Documentation Generation ===\n");
|
|
|
|
println!("Problem: Documentation is always out of sync");
|
|
println!("Current: Manual updates, 2-3 weeks behind code\n");
|
|
|
|
println!("Solution: Automated documentation pipeline\n");
|
|
|
|
// Phase 1: Code Analysis
|
|
println!("Phase 1: Code Analysis (Ollama)");
|
|
println!(" 1. Parse all source files");
|
|
println!(" 2. Extract API endpoints, types, functions");
|
|
println!(" 3. Identify breaking changes");
|
|
println!(" 4. Generate change summary");
|
|
println!("Cost: FREE (local)");
|
|
println!("Time: 2 minutes for 10k LOC\n");
|
|
|
|
// Phase 2: Doc Generation
|
|
println!("Phase 2: Documentation Writing (Claude)");
|
|
println!(" 1. Generate endpoint descriptions");
|
|
println!(" 2. Create request/response examples");
|
|
println!(" 3. Document parameters and types");
|
|
println!(" 4. Add error documentation");
|
|
println!("Cost: ~$0.40 per endpoint");
|
|
println!("Time: 30 seconds per endpoint\n");
|
|
|
|
// Phase 3: Quality Check
|
|
println!("Phase 3: Quality Assurance (GPT-4)");
|
|
println!(" 1. Verify accuracy against code");
|
|
println!(" 2. Check completeness");
|
|
println!(" 3. Ensure clarity for developers");
|
|
println!(" 4. Validate examples");
|
|
println!("Cost: ~$0.15 per doc");
|
|
println!("Time: 15 seconds\n");
|
|
|
|
// Execution example
|
|
println!("=== Example: New Feature Documentation ===");
|
|
println!("Commit: Add user search API endpoint\n");
|
|
|
|
println!("Step 1: Code analysis");
|
|
println!(" Detected: New endpoint POST /api/v1/users/search");
|
|
println!(" Parameters: query, limit, offset");
|
|
println!(" Returns: { users: [...], total: number }");
|
|
println!(" Status: Ready for documentation\n");
|
|
|
|
println!("Step 2: Documentation");
|
|
println!(" [Claude generates markdown]");
|
|
println!(" ## Search Users");
|
|
println!(" Search the user database with full-text capabilities.");
|
|
println!(" ### Request");
|
|
println!(" POST /api/v1/users/search");
|
|
println!(" {{ \"query\": \"john\", \"limit\": 10 }}");
|
|
println!(" ...[complete documentation]...\n");
|
|
|
|
println!("Step 3: Quality check");
|
|
println!(" ✓ Accuracy: 100% (matches code)");
|
|
println!(" ✓ Completeness: All fields documented");
|
|
println!(" ✓ Clarity: Developer-friendly");
|
|
println!(" ✓ Examples: Valid and correct");
|
|
println!(" Status: APPROVED\n");
|
|
|
|
println!("=== Workflow Results ===");
|
|
println!("Docs generated: 5 minutes after code commit");
|
|
println!("Accuracy: 99%+ (verified by tests)");
|
|
println!("Cost: $0.55 per endpoint");
|
|
println!("Time saved: 2+ hours per feature\n");
|
|
|
|
println!("=== Monthly Impact ===");
|
|
println!("Endpoints added/month: ~20");
|
|
println!("Manual doc time: 40+ hours");
|
|
println!("Automated time: 2 hours");
|
|
println!("Cost savings: $1000+ month");
|
|
println!("Quality improvement: Docs in sync, always current");
|
|
}
|