# egraphs-good/egg architecture

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

- Interactive diagram: https://gitdiagram.com/egraphs-good/egg
- Repository: https://github.com/egraphs-good/egg

## Overview

##### Main Components

a) Core E-Graph Engine Components:
- EGraph Module (src/egraph.rs)
- EClass Module (src/eclass.rs)
- Pattern Matching System (src/pattern.rs)
- Rewrite System (src/rewrite.rs)
- Extraction System (src/extract.rs, src/lp_extract.rs)

b) Supporting Components:
- Union-Find Data Structure (src/unionfind.rs)
- Language Framework (src/language.rs)
- Explanation System (src/explain.rs)

**┌─ Core Layer ─────────────────────┐**
- ┌─────────┐  ┌─────────────────┐ │
- EGraph  │←→│ Union-Find      │ │
- ┘  └─────────────────┘ │
- ↕            ↕              │
- ┌─────────┐  ┌─────────────────┐ │
- EClass  │←→│ Pattern Matching│ │
- ┘  └─────────────────┘ │
- ┘
- ↑               ↑
**┌─ Extension Layer ───────────────┐**
- ┌─────────┐  ┌───────────────┐ │
- Rewrite │  │ Extraction    │ │
- System  │  │ (Normal/LP)   │ │
- ┘  └───────────────┘ │
- ┘
- ↑               ↑
**┌─ Interface Layer ──────────────┐**
- ┌─────────┐  ┌──────────────┐ │
- Language │  │ Explanation  │ │
- Framework│  │ System       │ │
- ┘  └──────────────┘ │
- ┘

##### Additional Details

A side panel showing:
- Supported Features:
- Equality Saturation
- Pattern Matching
- Custom Language Definition
- Extraction Strategies

- External Dependencies:
- CBC Solver (for LP extraction)
- Rust Standard Library

##### Implementation Notes

- Clear boundaries between the different modules
- Public APIs with bold borders
- Version information
- Notes about performance-critical paths

##### Testing Components

A separate section showing:
- Test Framework (tests/)
- Example Implementations:
- Propositional Logic
- Math Operations
- Lambda Calculus

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef extension fill:#e8f5e9,stroke:#1b5e20
    classDef interface fill:#fff3e0,stroke:#e65100
    classDef test fill:#f3e5f5,stroke:#4a148c
    classDef feature fill:#fce4ec,stroke:#880e4f

    subgraph Core["Core Layer"]
        EGraph["EGraph Module"]:::core
        EClass["EClass Module"]:::core
        UnionFind["Union-Find Data Structure"]:::core
        Pattern["Pattern Matching System"]:::core
        MultiPattern["Multi-Pattern Matching"]:::core
        Subst["Substitution System"]:::core

        EGraph <--> UnionFind
        EGraph <--> EClass
        EClass <--> Pattern
        Pattern <--> MultiPattern
        Pattern <--> Subst
    end

    subgraph Extension["Extension Layer"]
        Rewrite["Rewrite System"]:::extension
        Extract["Extraction System"]:::extension
        LPExtract["LP Extraction"]:::extension
        Machine["Machine Interface"]:::extension

        Extract <--> LPExtract
        Rewrite <--> Machine
    end

    subgraph Interface["Interface Layer"]
        Lang["Language Framework"]:::interface
        Explain["Explanation System"]:::interface
        Tutorial["Tutorial System"]:::interface
        Viz["Visualization Component"]:::interface
    end

    subgraph Testing["Testing Components"]
        PropLogic["Propositional Logic Tests"]:::test
        MathOps["Math Operations Tests"]:::test
        Lambda["Lambda Calculus Tests"]:::test
    end

    %% Inter-layer connections
    Core --> Extension
    Extension --> Interface
    Interface --> Testing

    %% Features panel
    subgraph Features["Supported Features"]
        EqSat["Equality Saturation"]:::feature
        PatMatch["Pattern Matching"]:::feature
        CustLang["Custom Language Definition"]:::feature
        ExtStrat["Extraction Strategies"]:::feature
    end

    %% Click events for component mapping
    click EGraph "https://github.com/egraphs-good/egg/blob/main/src/egraph.rs"
    click EClass "https://github.com/egraphs-good/egg/blob/main/src/eclass.rs"
    click Pattern "https://github.com/egraphs-good/egg/blob/main/src/pattern.rs"
    click Rewrite "https://github.com/egraphs-good/egg/blob/main/src/rewrite.rs"
    click Extract "https://github.com/egraphs-good/egg/blob/main/src/extract.rs"
    click LPExtract "https://github.com/egraphs-good/egg/blob/main/src/lp_extract.rs"
    click UnionFind "https://github.com/egraphs-good/egg/blob/main/src/unionfind.rs"
    click Lang "https://github.com/egraphs-good/egg/blob/main/src/language.rs"
    click Explain "https://github.com/egraphs-good/egg/blob/main/src/explain.rs"
    click PropLogic "https://github.com/egraphs-good/egg/blob/main/tests/prop.rs"
    click MathOps "https://github.com/egraphs-good/egg/blob/main/tests/math.rs"
    click Lambda "https://github.com/egraphs-good/egg/blob/main/tests/lambda.rs"
    click Tutorial "https://github.com/egraphs-good/egg/blob/main/src/tutorials/mod.rs"
    click MultiPattern "https://github.com/egraphs-good/egg/blob/main/src/multipattern.rs"
    click Subst "https://github.com/egraphs-good/egg/blob/main/src/subst.rs"
    click Machine "https://github.com/egraphs-good/egg/blob/main/src/machine.rs"
    click Viz "https://github.com/egraphs-good/egg/blob/main/src/dot.rs"
```
