deepwiki-rs (Litho)

repository·main·Indexed 23 days ago

https://github.com/sopaco/deepwiki-rs

A high-performance, AI-driven engine built with Rust for the automatic generation of professional C4-model architecture documentation (Context, Container, Component, and Code diagrams) from source code. It supports multiple languages including Rust, Python, Java, Go, C#, and JavaScript. Key features include automatic synchronization with codebase changes, SQL database analysis for ERD generation, external knowledge integration (PDF, Markdown, SQL), and a four-stage processing pipeline to ensure documentation remains current.

Tokens
79.7K
Snippets
130
Records
344
Agent score
79%

What's inside deepwiki-rs

  1. What is deepwiki-rs?

    main

    deepwiki-rs is a Rust-based Command-Line Interface (CLI) tool that automates the generation of C4 architecture documentation. It uses a multi-agent AI pipeline to analyze source code across 12+ programming languages (including Rust, Java, Python, TypeScript, Go, and more) and produces professional-grade documentation such as system context diagrams, domain module analyses, and workflow documentation.

    It is designed as a read-only analysis engine, meaning it ingests your source code and metadata to emit markdown artifacts without ever modifying your code or interacting with your application's runtime.

  2. Overview of the Knowledge Integration Domain

    main

    The Knowledge Integration Domain is a Tool Support Domain in deepwiki-rs that implements a Retrieval-Augmented Generation (RAG) pipeline. It ingests external documentation (PDF, Markdown, SQL, YAML, JSON, and plain text) and transforms it into LLM-optimized knowledge segments.

    Key capabilities include:

    • Multi-Format Ingestion: Processes various file types without requiring manual conversion.
    • Intelligent Chunking: Uses semantic, paragraph, or fixed-size strategies to manage LLM context windows.
    • Incremental Synchronization: Uses file modification times (mtime) and HashSet-based change detection to minimize reprocessing costs.
    • Agent-Based Access Control: Restricts specific documents to certain AI agents via target_agents configuration.
    • Categorized Organization: Uses a taxonomy (e.g., architecture, database, api) for context-aware retrieval.
  3. What is Litho (deepwiki-rs)

    main

    Litho (also known as deepwiki-rs) is an AI-powered documentation generation engine built with Rust. It automatically analyzes source code to generate comprehensive, professional architecture documentation following the C4 model (Context, Container, Component, and Code diagrams).

    Key benefits include:

    • Automatic Synchronization: Keeps documentation in sync with codebase changes to prevent outdated docs.
    • C4 Model Support: Generates structured diagrams (Context, Container, Component, and Code).
    • Multi-language Support: Works with Rust, Python, Java, Go, C#, JavaScript, and more.
    • CI/CD Integration: Can be integrated into pipelines to automate documentation generation on every commit.
  4. Key features and capabilities of Litho

    main

    Litho provides several core and advanced capabilities for automated documentation:

    Core Capabilities

    • AI-Driven Architecture Generation: Creates documentation based on codebase analysis.
    • C4 Model Diagrams: Automatically generates Context, Container, Component, and Code diagrams.
    • Intelligent Extraction: Pulls code comments, structures, and dependency relationships.
    • Multi-language Support: Extensible language processors.
    • Customizable Templates: Supports custom output styles via a template system.

    Advanced Features

    • External Knowledge Mounting: Supports attaching PDF, Markdown, and SQL files as additional knowledge sources.
    • Database Documentation: Analyzes SQL projects to generate ER diagrams and database architecture docs.
    • Git History Analysis: Tracks architectural evolution over time.
    • Cross-referencing: Links code elements directly to documentation.
    • CI/CD Integration: Can be integrated into pipelines to automate documentation updates on every commit.
  5. Key architectural features and constraints of deepwiki-rs

    main

    When integrating or deploying deepwiki-rs, keep the following architectural decisions in mind:

    • Multi-Agent AI Pipeline: Uses 8 specialized research agents operating at different C4 abstraction levels to reduce hallucinations and improve coherence.
    • Read-Only Analysis: The system strictly enforces read-only file system access to target projects to ensure safety and prevent source code corruption.
    • Dual LLM Provider Support: Supports both Cloud APIs (via HTTPS/JSON) and local Ollama inference (via HTTP) to accommodate enterprise security and air-gapped environments.
    • Language-Agnostic Preprocessing: Uses a trait-based architecture supporting 12+ languages through pluggable modules.
    • File-Based Caching: Implements persistent MD5-based caching for LLM responses to reduce costs and enable offline replay.
    • Privacy & Security: Local Ollama support allows for zero-egress environments. The system requires no network ingress and operates without privilege escalation.
  6. Understand the Core Generation Domain architecture

    main

    The Core Generation Domain (located in src/generator/) is the orchestration layer of the deepwiki-rs engine. It manages the end-to-end AI-powered documentation pipeline, bridging infrastructure (LLM providers, caching, configuration) with domain-specific processing stages: Preprocessing, Research, Composition, and Output.

    Key Architectural Characteristics

    • Thread-Safe Resource Management: Uses Arc<RwLock<T>> for concurrent access to shared resources across async boundaries.
    • Dual Execution Models: Supports Imperative patterns (direct AgentExecutor usage for fine-grained control) and Declarative patterns (using the StepForwardAgent trait for research and synthesis).
    • Type-Safe Agent Framework: Provides compile-time guarantees for agent outputs via associated types and JSON Schema validation.
    • Intelligent Caching: Implements a cache-aside pattern with token usage tracking.
    • Multilingual Support: Supports integrated internationalization with 8-language prompt generation.
  7. Overview of deepwiki-rs core execution paths

    main

    The system processes data through three primary layers:

    • Input Layer: Consumes CLI arguments, configuration files, the target project, and existing knowledge bases.
    • Processing Layer: Executes the core logic through the sequence of Preprocessing $\rightarrow$ Research $\rightarrow$ Composition.
    • Output Layer: Handles Document Persistence and the generation of Summary Reports.
    flowchart LR
        subgraph Input["Input Layer"]
            A[CLI Arguments] --> B[Configuration]
            C[Target Project] --> D[Knowledge Base]
        end
        
        subgraph Processing["Processing Layer"]
            E[Preprocessing] --> F[Research]
            F --> G[Composition]
        end
        
        subgraph Output["Output Layer"]
            G --> H[Document Persistence]
            H --> I[Summary Reports]
        end
        
        Input --> Processing
        Processing --> Output
        
        style Processing fill:#e3f2fd,stroke:#1976d2
        style Input fill:#e8f5e9,stroke:#388e3c
        style Output fill:#fff3e0,stroke:#f57c00
  8. How Litho's four-stage pipeline works

    main

    Litho processes source code through a four-stage pipeline to produce high-quality technical documentation:

    1. Preprocessing (预处理): Scans the codebase, extracts files and metadata, identifies modules, and identifies dependencies.
    2. Research (研究): Employs multiple AI agents to perform deep analysis of system context, architectural patterns, workflows, and module responsibilities using a ReAct reasoning loop.
    3. Composition (编排): Integrates research findings into structured documents (Overview, Architecture, and Module deep-dives).
    4. Output & Validation (输出与验证): Formats the output, validates Mermaid diagram syntax, generates coverage reports, and persists the files to disk.
  9. Choose the right Litho workflow mode

    main

    Depending on your goal, select one of the following operational modes:

    • Full Litho Workflow: Use for Comprehensive Documentation. Generates complete C4 model documentation including architecture diagrams and technical specs.
    • Basic Analysis Mode: Use for Quick Code Analysis. Provides fast code insights without running the full documentation pipeline.
    • Advanced C4 Generation: Use for Architecture Understanding. Performs deep architectural analysis with detailed component relationships.
    • Automated Pipeline: Use for CI/CD Integration. Designed for continuous documentation generation within development workflows.
  10. Understand the Preprocessing Module (generator/preprocess)

    main

    The Preprocessing Module is the first stage of the Litho four-stage pipeline. Its purpose is to transform raw source code files into structured information (project structure, code insights, directory dossiers, and dependency relationships) that subsequent AI Agents can use for analysis. It does not produce final documentation itself, but provides the essential "raw materials" for the research and orchestration stages.

    Core Functions

    • Project Structure Scanning: Uses StructureExtractor to traverse the directory tree and calculate importance scores for files and directories.
    • Multi-language Analysis: Uses LanguageProcessor implementations to parse language-specific structures (classes, functions, traits, etc.) for 14 supported languages.
    • Directory Importance Scoring: Uses DirectoryScorer (via LLM) to distinguish core directories (e.g., src/) from auxiliary ones (e.g., assets/).
    • Directory Summarization: Uses DirectorySummarizer to perform deep analysis of core files, generating DirectoryDossier and FileInsight objects.
    • Dependency Analysis: Uses RelationshipsAnalyzer to identify import/use statements and map module dependencies.
  11. Understand the deepwiki-rs Hybrid Storage Architecture

    main

    The system uses a hybrid storage strategy combining in-memory state and file-system-based persistence. It does not require an external database.

    Memory Scopes (Runtime)

    Data is managed in three distinct lifecycles aligned with pipeline stages. Scopes are cleared after consumption to manage memory footprint:

    • PREPROCESSING Scope: Contains CodeInsight and ProjectStructure.
    • STUDIES_RESEARCH Scope: Contains SystemContextReport, DomainModulesReport, and ArchitectureReport.
    • DOCUMENTATION Scope: Contains DocTree and DocumentMetadata.

    File System Cache

    • LLM Response Cache: Uses MD5 keys (hash of prompt content + model configuration) to map to JSON responses with TTL-based expiration. This follows a Cache-Aside pattern.
    • Knowledge Base Cache: Stores chunked documents and sync metadata.

    Output Artifacts

    Final results are persisted as:

    • Markdown Files: With localized naming.
    • Mermaid Diagrams: With fixed syntax.
    • Summary Reports: Including performance metrics.
  12. Litho system boundaries and limitations

    main

    Understanding what Litho does and does not do is essential for integration:

    In Scope:

    • Automated code analysis and C4 documentation generation.
    • Multi-language static analysis.
    • Mermaid diagram validation and fixing.
    • External knowledge augmentation.
    • Database (SQL) architecture generation.
    • LLM provider abstraction.

    Out of Scope:

    • No Web UI: Litho is a CLI tool. For viewing documentation, use the Litho Book ecosystem tool.
    • No Code Modification: It does not change your source code or affect compilation.
    • No Execution: It does not run or test your code.
    • No Version Management: It does not manage documentation history (use Git for this).
    • No Real-time Updates: Documentation is updated via manual triggers or CI/CD integration.