# tanq16/ai-context architecture

> Architecture diagram of the GitHub repository tanq16/ai-context, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanq16/ai-context
- Repository: https://github.com/tanq16/ai-context

## Overview

##### Main Components

a. Input Sources (External Systems):
- Local Directory System
- GitHub Repositories
- YouTube Videos
- Web Pages

b. Core Processing Components:
- Main CLI Interface
- Context Handlers (separate for each input type)
- Concurrent Processing Engine
- File System Interface

##### Architecture Pattern

a. Command Layer:
- Entry point (main.go)
- CLI command handling (cmd/ai-context.go)

b. Core Processing Layer (aicontext/):
- Source context processing (source-context.go)
- Web context processing (web-context.go)
- Video context processing (video-context.go)
- Common handler interface (handler.go)

**[Input Sources]**
- ↓
**[CLI Interface Layer]**
- ↓
**[Processing Layer]**
- ↓
**[Output Layer]**

##### Key Elements to Highlight

a. Data Flow:
- Input processing flow from various sources
- Concurrent processing for multiple inputs
- Output generation to markdown files

b. External Dependencies:
- GitHub API (for repository access)
- YouTube API (for transcripts)
- Web scraping capabilities
- File system interactions

##### Important Interactions

- CLI receiving input (URL or file list)
- Concurrent worker pool for processing
- Handler selection based on input type
- Markdown file generation
- Image downloading for web pages
- File system operations

##### Technical Details

- Environment variables (GH_TOKEN)
- Default ignore patterns
- Concurrent processing limits
- Output directory structure
- File naming conventions

##### Output Layer (bottom)

- External system interfaces

Keep the abstraction level focused on the main architectural components while showing the key processing flows that make this tool unique, particularly its ability to handle multiple input types and convert them into a consistent markdown output format.

Remember to emphasize the concurrent processing capability and the modular nature of the handlers for different input types, as these are key architectural features of the system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        GH[GitHub Repos]:::input
        YT[YouTube Videos]:::input
        WEB[Web Pages]:::input
        FS[Local Files]:::input
    end

    subgraph CLI
        MAIN[Main Entry]:::cli
        CLIIF[CLI Interface]:::cli
    end

    subgraph Processors
        HAND[Common Handler Interface]:::processor
        SRC[Source Context Handler]:::processor
        WEBC[Web Context Handler]:::processor
        VIDC[Video Context Handler]:::processor
        IGN[Ignore Patterns Manager]:::processor
    end

    subgraph External
        GHAPI[GitHub API]:::external
        YTAPI[YouTube API]:::external
        WAPI[Web Scraper]:::external
    end

    subgraph Output
        MD[Markdown Files]:::output
        IMG[Downloaded Images]:::output
    end

    %% Input to CLI
    GH --> MAIN
    YT --> MAIN
    WEB --> MAIN
    FS --> MAIN

    %% CLI Flow
    MAIN --> CLIIF
    CLIIF --> HAND

    %% Handler to Processors
    HAND --> SRC
    HAND --> WEBC
    HAND --> VIDC
    IGN --> SRC
    IGN --> WEBC
    IGN --> VIDC

    %% External Services
    SRC --> GHAPI
    VIDC --> YTAPI
    WEBC --> WAPI

    %% Output Generation
    SRC --> MD
    WEBC --> MD
    VIDC --> MD
    WEBC --> IMG

    %% Click Events
    click MAIN "https://github.com/Tanq16/ai-context/blob/main/main.go"
    click CLIIF "https://github.com/Tanq16/ai-context/blob/main/cmd/ai-context.go"
    click HAND "https://github.com/Tanq16/ai-context/blob/main/aicontext/handler.go"
    click SRC "https://github.com/Tanq16/ai-context/blob/main/aicontext/source-context.go"
    click WEBC "https://github.com/Tanq16/ai-context/blob/main/aicontext/web-context.go"
    click VIDC "https://github.com/Tanq16/ai-context/blob/main/aicontext/video-context.go"
    click IGN "https://github.com/Tanq16/ai-context/blob/main/aicontext/ignores.go"

    %% Styling
    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef cli fill:#2ecc71,stroke:#27ae60,color:white
    classDef processor fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef output fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1[Input Sources]:::input
        L2[CLI Components]:::cli
        L3[Processors]:::processor
        L4[External Services]:::external
        L5[Output Files]:::output
    end
```
