# lean-dojo/leandojo architecture

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

- Interactive diagram: https://gitdiagram.com/lean-dojo/leandojo
- Repository: https://github.com/lean-dojo/leandojo

## Overview

##### And Highlight Core Components
- Library Entry-Point: Represent the core package (lean_dojo) as the primary container.
- Data Extraction Module: Create a component for data_extraction that includes submodules such as ExtractData.lean, ast.py, cache.py, lean.py, trace.py, and traced_data.py. Show that this module is responsible for parsing Lean proof states, tactics, and premises.
- Interaction Module: Create a component for interaction that covers Lean4Repl.lean, dojo.py, and parse_goals.py. This module handles programmatic interactions with Lean (for example, sending commands and processing responses).

##### Relationships and Interactions
- That the Data Extraction module provides structured data about proofs and tactics, which then may be consumed by the Interaction module. For instance, results from ast and trace processing are used by functions in interactions.

##### Architectural Patterns
- Separation of Concerns: Note that the library cleanly separates functionalities—data extraction is isolated from interaction. This modular design helps in testing and maintenance.
- Integration Points: Identify points where the library might interface with external Lean installations (external dependency on Lean 4) or other tooling (like GitHub APIs via tokens).
- Reusability: Mention that submodules are designed to be plug-and-play components, hinting at extensibility.

##### Technologies
- Lean: Illustrate that the data and interaction methods are geared towards interfacing with Lean (noted by the Lean4Repl and Lean (.lean) files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    CoreLib["Core Library (LeanDojo)"]:::core

    subgraph "Data Extraction"
        ED["ExtractData.lean"]:::file
        AST["ast.py"]:::file
        CACHE["cache.py"]:::file
        DATA_LEAN["lean.py"]:::file
        TRACE["trace.py"]:::file
        TRACED["traced_data.py"]:::file
    end

    subgraph "Interaction"
        LEAN4["Lean4Repl.lean"]:::file
        DOJO["dojo.py"]:::file
        PARSE["parse_goals.py"]:::file
    end

    subgraph "Utilities & Config"
        UTILS["utils.py"]:::file
        CONST["constants.py"]:::file
    end

    EXTERNAL["External Dependencies: Lean4,GitHubAPI,wget,elan"]:::external

    %% Connections from Core Library to Modules
    CoreLib --> ED
    CoreLib --> LEAN4
    CoreLib --> UTILS

    %% Data flow from Data Extraction to Interaction
    ED -->|"data_flow"| LEAN4

    %% External dependency connection from Interaction module
    LEAN4 ---|"external"| EXTERNAL

    %% Click Events
    click CoreLib "https://github.com/lean-dojo/leandojo/tree/main/src/lean_dojo"
    click ED "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/ExtractData.lean"
    click AST "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/ast.py"
    click CACHE "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/cache.py"
    click DATA_LEAN "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/lean.py"
    click TRACE "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/trace.py"
    click TRACED "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/data_extraction/traced_data.py"
    click LEAN4 "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/interaction/Lean4Repl.lean"
    click DOJO "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/interaction/dojo.py"
    click PARSE "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/interaction/parse_goals.py"
    click UTILS "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/utils.py"
    click CONST "https://github.com/lean-dojo/leandojo/blob/main/src/lean_dojo/constants.py"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef file fill:#ABEBC6,stroke:#1D8348,stroke-width:1px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:1px;
```
