# mufeedvh/code2prompt architecture

> Architecture diagram of the GitHub repository mufeedvh/code2prompt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mufeedvh/code2prompt
- Repository: https://github.com/mufeedvh/code2prompt

## Overview

##### Main Components

a) Core Components:
- CLI Interface (Entry Point)
- Template Engine
- File System Handler
- Token Counter
- Git Integration
- Output Formatter

b) Supporting Components:
- Filter System
- Template Repository
- Tokenizer Engines

**User Interface Layer**

**Business Logic Layer**

**Integration Layer**

##### Detailed Component Breakdown

A. User Interface Layer:
- Path to codebase
- Template selection
- Filter patterns
- Output preferences

B. Business Logic Layer (Core):
- Template Engine (template.rs)
- Connection to template repository
- Handlebars integration
- File System Handler (path.rs)
- Directory traversal
- File reading
- Token Counter (token.rs)
- Multiple tokenizer support
- Token calculation logic
- Filter System (filter.rs)
- Glob pattern matching
- Exclusion logic

C. Integration Layer:
- Git Integration (git.rs)
- Diff generation
- Branch comparison
- Output Formatter
- JSON output
- Markdown formatting
- Clipboard integration

##### Component Interactions

How:
- CLI parses arguments and initializes components
- Template Engine loads and processes templates
- File System Handler traverses and reads files
- Filter System applies patterns
- Token Counter processes content
- Git Integration fetches diffs when requested
- Output Formatter generates final output

##### External Dependencies

Connections to:
- Handlebars templating engine
- tiktoken-rs for tokenization
- Git system
- Clipboard system

##### Notes

Annotations for:
- Supported tokenizer types
- Template customization points
- Filter pattern syntax
- Git integration capabilities

Remember to include the key features like:
- Template customization
- Glob pattern filtering
- Token counting
- Git integration
- Multiple output formats

This will create a comprehensive system design that accurately represents code2prompt's architecture while being useful for both development and documentation purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI
        CLI["CLI Interface"]:::cli
    end

    subgraph Core
        TE["Template Engine"]:::core
        FSH["File System Handler"]:::core
        TC["Token Counter"]:::core
        FS["Filter System"]:::core
        OF["Output Formatter"]:::core
    end

    subgraph Integration
        GI["Git Integration"]:::integration
        TR["Template Repository"]:::integration
        TOK["Tokenizer Engines"]:::integration
    end

    subgraph External
        HB["Handlebars"]:::external
        TT["tiktoken-rs"]:::external
        GS["Git System"]:::external
        CB["Clipboard"]:::external
    end

    %% Core Flow
    CLI --> TE
    CLI --> FSH
    CLI --> FS
    
    TE --> TR
    TE --> HB
    FSH --> FS
    FSH --> TC
    TC --> TOK
    TOK --> TT
    
    FS --> OF
    TC --> OF
    GI --> OF
    GI --> GS

    OF --> CB

    %% Click Events
    click CLI "https://github.com/mufeedvh/code2prompt/blob/main/src/main.rs"
    click TE "https://github.com/mufeedvh/code2prompt/blob/main/src/template.rs"
    click FSH "https://github.com/mufeedvh/code2prompt/blob/main/src/path.rs"
    click TC "https://github.com/mufeedvh/code2prompt/blob/main/src/token.rs"
    click GI "https://github.com/mufeedvh/code2prompt/blob/main/src/git.rs"
    click FS "https://github.com/mufeedvh/code2prompt/blob/main/src/filter.rs"
    click TR "https://github.com/mufeedvh/code2prompt/tree/main/templates/"

    %% Styling
    classDef cli fill:#FF9900,stroke:#333,stroke-width:2px
    classDef core fill:#3498DB,stroke:#333,stroke-width:2px
    classDef integration fill:#2ECC71,stroke:#333,stroke-width:2px
    classDef external fill:#95A5A6,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["User Interface"]:::cli
        L2["Core Components"]:::core
        L3["Integration Layer"]:::integration
        L4["External Dependencies"]:::external
    end
```
