# adityaprakash-work/contextcraft architecture

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

- Interactive diagram: https://gitdiagram.com/adityaprakash-work/contextcraft
- Repository: https://github.com/adityaprakash-work/contextcraft

## Overview

##### Project type and purpose
- This is a Python library (distributed via PyPI / Poetry) called “contextcraft” whose goal is “Advanced context comprehension and manipulation for LLMs.” It provides abstractions for building up context, calling one or more LLM back-ends, post-processing, and persisting results.

##### File structure
- Top‐level files:
- .env.example – environment variable template for API keys, etc.
- pyproject.toml – declares Python dependencies (e.g. OpenAI).
- media/files – a placeholder for user-provided assets (text snippets, documents).
- output – where the tool writes generated results.
- scripts – any helper scripts (e.g. demo or bootstrap).
- src/contextcraft:
- config.py – loads and centralizes configuration (API keys, timeouts).
- lms/openai.py – adapter for interacting with the OpenAI API.
- programs/ – entry points or higher-level routines that glue config, context builders, and LLM calls.

##### Be detailed but not exhaustive
- Every module folder (config, lms, programs).
- Distinguish between what runs locally and what is an external dependency.
- How environment configuration (.env) flows into the system at startup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points Layer
    subgraph "User Entry Points"
        direction TB
        CLI["CLI Programs"]:::entry
        Scripts["Helper Scripts"]:::entry
    end

    %% Configuration and Build
    Env[".env.example"]:::storage
    BuildConfig["pyproject.toml"]:::storage

    %% Core Library
    subgraph "contextcraft Library"
        direction TB
        Config["Configuration Module\n(config.py)"]:::module
        Core["Core Library\n(__init__.py & Context Builders)"]:::module
        subgraph "LLM Adapters"
            OpenAI["OpenAI API Adapter\n(openai.py)"]:::adapter
        end
    end

    %% Local Storage
    Media["Local Input Store\n(media/files)"]:::storage
    Output["Local Output Store\n(output/)"]:::storage

    %% External Service
    OpenAIExt["OpenAI Service"]:::external

    %% Flows
    CLI -->|loads| Env
    CLI -->|loads| BuildConfig
    CLI -->|invokes| Config
    Scripts -->|invokes| Config

    Env -->|provides vars| Config
    BuildConfig -->|defines deps| Core

    Config -->|initializes| Core
    Core -->|reads| Media
    Core -->|builds prompts| Core

    Core -->|calls| OpenAI
    OpenAI -->|HTTP request/response| OpenAIExt

    OpenAIExt -->|response| OpenAI
    OpenAI -->|returns output| Core

    Core -->|post-processes| Core
    Core -->|writes results| Output
    Core -->|prints to console| CLI
    Core -->|prints to console| Scripts

    %% Click Events
    click CLI "https://github.com/adityaprakash-work/contextcraft/tree/main/src/contextcraft/programs"
    click Scripts "https://github.com/adityaprakash-work/contextcraft/tree/main/scripts"
    click Env "https://github.com/adityaprakash-work/contextcraft/blob/main/.env.example"
    click BuildConfig "https://github.com/adityaprakash-work/contextcraft/blob/main/pyproject.toml"
    click Config "https://github.com/adityaprakash-work/contextcraft/blob/main/src/contextcraft/config.py"
    click Core "https://github.com/adityaprakash-work/contextcraft/blob/main/src/contextcraft/__init__.py"
    click OpenAI "https://github.com/adityaprakash-work/contextcraft/blob/main/src/contextcraft/lms/openai.py"
    click Media "https://github.com/adityaprakash-work/contextcraft/tree/main/media/files"
    click Output "https://github.com/adityaprakash-work/contextcraft/tree/main/output"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:1px;
    classDef module fill:#bbf,stroke:#333,stroke-width:1px;
    classDef adapter fill:#bfc,stroke:#333,stroke-width:1px;
    classDef storage fill:#cfc,stroke:#333,stroke-width:1px;
    classDef external fill:#fcf,stroke:#333,stroke-width:1px;
    class CLI,Scripts entry
    class Config,Core module
    class OpenAI adapter
    class Env,BuildConfig,Media,Output storage
    class OpenAIExt external
```
