# sutt/lime architecture

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

- Interactive diagram: https://gitdiagram.com/sutt/lime
- Repository: https://github.com/sutt/lime

## Overview

##### High-Level Components

a. CLI Interface Layer:
- Main entry points: eval, agg, grade, initialize, check, render
- To the core processing layers below

b. Core Processing Layer (organize in three main vertical streams):
##### Evaluation Stream
- Markdown Parser
- Model Interface
- Grading System

##### Aggregation Stream
- Results Collector
- Analysis Engine
- Report Generator

##### Configuration Stream
- Config Parser
- State Management
- Error Handling

c. Model Integration Layer:
- Three parallel paths for different model types:
- OpenAI API
- Local LlamaCpp
- Custom Pipeline (CPL)

##### Component Relationships

**Input Files (MD) → Parser → Model Interface → Grading → Output Files (JSON)**
- ↓
- Aggregation Engine
- ↓
- Reports (MD/Terminal)

##### Specific Implementation Details

- MVC pattern in the common/ directory:
- Models: config.py, internal.py, state.py
- Views: agg/, msg/ directories
- Controllers: config_parse.py, parse.py

**MD Files → Parser → Model → Grading → JSON → Aggregation → Reports**

**config.yaml → ConfigParser → State Management → Command Execution**

**Interface (base.py)**
- ↓
- OpenAI (api_openai.py)
- LlamaCpp (local_llama_cpp.py)
- CPL (cpl_client.py, cpl_server.py)

##### Important Notes

- Clear separation between synchronous and asynchronous operations
- Version/configuration management flow
- Error handling paths
- Where extensibility points exist

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["CLI Interface Layer"]
        direction TB
        EVAL[["Eval"]]:::cmd
        AGG[["Agg"]]:::cmd
        GRADE[["Grade"]]:::cmd
        INIT[["Initialize"]]:::cmd
        CHECK[["Check"]]:::cmd
        RENDER[["Render"]]:::cmd
    end

    subgraph CORE["Core Processing Layer"]
        direction TB
        subgraph EVAL_STREAM["Evaluation Stream"]
            direction TB
            MD_PARSER["Markdown Parser"]:::process
            MODEL_IF["Model Interface"]:::process
            GRADING["Grading System"]:::process
        end

        subgraph AGG_STREAM["Aggregation Stream"]
            direction TB
            COLLECTOR["Results Collector"]:::process
            ANALYSIS["Analysis Engine"]:::process
            REPORT_GEN["Report Generator"]:::process
        end

        subgraph CONFIG_STREAM["Configuration Stream"]
            direction TB
            CONF_PARSE["Config Parser"]:::process
            STATE_MGT["State Management"]:::process
            ERR_HANDLE["Error Handling"]:::process
        end
    end

    subgraph MODEL["Model Integration Layer"]
        direction TB
        BASE_IF["Base Interface"]:::model
        OPENAI["OpenAI API"]:::model
        LLAMA["Local LlamaCpp"]:::model
        CPL["Custom Pipeline"]:::model
    end

    %% Data Flow Connections
    MD_IN[("MD Files")]:::data --> MD_PARSER
    MD_PARSER --> MODEL_IF
    MODEL_IF --> GRADING
    GRADING --> JSON_OUT[("JSON Output")]:::data
    JSON_OUT --> COLLECTOR
    COLLECTOR --> ANALYSIS
    ANALYSIS --> REPORT_GEN
    REPORT_GEN --> REPORTS[("Reports")]:::data

    %% CLI to Core Connections
    EVAL --> MD_PARSER
    AGG --> COLLECTOR
    GRADE --> GRADING
    INIT --> CONF_PARSE
    CHECK --> ERR_HANDLE
    RENDER --> REPORT_GEN

    %% Model Interface Connections
    MODEL_IF --> BASE_IF
    BASE_IF --> OPENAI
    BASE_IF --> LLAMA
    BASE_IF --> CPL

    %% Config Flow
    CONFIG[("config.yaml")]:::data --> CONF_PARSE
    CONF_PARSE --> STATE_MGT
    STATE_MGT -.-> ERR_HANDLE

    %% Styling
    classDef cmd fill:#f9f,stroke:#333,stroke-width:2px
    classDef process fill:#90EE90,stroke:#333
    classDef model fill:#FFD700,stroke:#333
    classDef data fill:#87CEEB,stroke:#333

    %% Click Events
    click EVAL "https://github.com/sutt/lime/blob/master/lime/commands/eval.py"
    click AGG "https://github.com/sutt/lime/blob/master/lime/commands/agg.py"
    click GRADE "https://github.com/sutt/lime/blob/master/lime/commands/grade.py"
    click INIT "https://github.com/sutt/lime/blob/master/lime/commands/initialize.py"
    click CHECK "https://github.com/sutt/lime/blob/master/lime/commands/check.py"
    click RENDER "https://github.com/sutt/lime/blob/master/lime/commands/render.py"
    click MD_PARSER "https://github.com/sutt/lime/blob/master/lime/common/controllers/parse.py"
    click MODEL_IF "https://github.com/sutt/lime/blob/master/lime/common/inference/interface.py"
    click GRADING "https://github.com/sutt/lime/blob/master/lime/common/grading/base.py"
    click COLLECTOR "https://github.com/sutt/lime/blob/master/lime/common/views/agg/collect.py"
    click ANALYSIS "https://github.com/sutt/lime/blob/master/lime/common/views/agg/query.py"
    click REPORT_GEN "https://github.com/sutt/lime/blob/master/lime/common/views/msg/eval.py"
    click CONF_PARSE "https://github.com/sutt/lime/blob/master/lime/common/controllers/config_parse.py"
    click STATE_MGT "https://github.com/sutt/lime/blob/master/lime/common/models/state.py"
    click ERR_HANDLE "https://github.com/sutt/lime/blob/master/lime/common/models/errs.py"
    click BASE_IF "https://github.com/sutt/lime/blob/master/lime/common/inference/base.py"
    click OPENAI "https://github.com/sutt/lime/blob/master/lime/common/inference/api_openai.py"
    click LLAMA "https://github.com/sutt/lime/blob/master/lime/common/inference/local_llama_cpp.py"
    click CPL "https://github.com/sutt/lime/blob/master/lime/common/inference/cpl_client.py"
```
