Crate codebank

Source
Expand description

§CodeBank

codebank is a powerful documentation generator that creates structured markdown documentation from your codebase. It supports multiple programming languages and provides flexible strategies for documentation generation.

§Features

  • Multi-language Support: Parse and document Rust, Python, TypeScript, and C code
  • Flexible Strategies: Choose between different documentation strategies:
    • Default: Complete code representation with full implementations
    • NoTests: Exclude test-related code for cleaner documentation
    • Summary: Generate public interface documentation only
  • Intelligent Parsing: Uses tree-sitter for accurate code parsing and analysis
  • Customizable Output: Control what gets included in your documentation

§Quick Start

use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;

fn main() -> Result<()> {
    // Create a new code bank generator
    let code_bank = CodeBank::try_new()?;

    // Generate documentation for your source directory
    let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
    let content = code_bank.generate(&config)?;

    println!("Generated documentation:\n{}", content);
    Ok(())
}

§Documentation Strategies

§Default Strategy

The default strategy includes all code elements with their complete implementations:

use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;

let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
let content = code_bank.generate(&config)?;

§NoTests Strategy

Exclude test-related code for cleaner documentation:

use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;

let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::NoTests, vec![]);
let content = code_bank.generate(&config)?;

§Summary Strategy

Generate documentation for public interfaces only:

use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;

let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::Summary, vec![]);
let content = code_bank.generate(&config)?;

§Custom Implementation

You can implement the Bank trait for your own code bank generator:

use codebank::{Bank, BankConfig, BankStrategy, Result};
use std::path::Path;

struct MyCodeBank;

impl Bank for MyCodeBank {
    fn generate(&self, config: &BankConfig) -> Result<String> {
        // Your implementation here
        Ok("# Code Bank\n\nCustom implementation".to_string())
    }
}

§Error Handling

The crate uses a custom Result type that wraps common error cases:

use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result, Error};

let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(std::path::Path::new("nonexistent"), BankStrategy::Default, vec![]);
let result = code_bank.generate(&config);

if let Err(err) = result {
    eprintln!("Failed to generate documentation: {}", err);
}

Modules§

formatter

Structs§

BankConfig
Configuration for generating code bank documentation.
CodeBank
The code bank generator implementation
CodeBankMcp
CodeBank MCP server implementation
CppParser
DeclareStatements
Represents declarations in source code.
FieldUnit
Represents a field in a struct
FileUnit
Represents a file in the code.
FunctionUnit
Represents a function or method in the code
GoParser
ImplUnit
Represents an implementation block in the code, not all languages need this
ModuleUnit
Represents a module in the code
PythonParser
RustParser
StructUnit
Represents a struct or class in the code
TraitUnit
Represents a trait or interface in the code
TypeScriptParser

Enums§

BankStrategy
Strategy for generating code bank documentation.
DeclareKind
The kind of declaration statement.
Error
Error types for the CodeBank library.
LanguageType
The language type supported by the parser.
Visibility
Represents visibility levels for code elements.

Traits§

Bank
Trait to generate a code bank for a given directory.
Formatter
LanguageParser
Trait for language-specific parsers.

Type Aliases§

Result
Result type alias for CodeBank operations.