# abcsys/libem architecture

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

- Interactive diagram: https://gitdiagram.com/abcsys/libem
- Repository: https://github.com/abcsys/libem

## Overview

##### Main Components
- Core Libem Library:
- This is where the heart of the entity matching logic resides. In the “libem” directory you have modules like match, browse, compose, resolve, optimize, tune, prepare, etc.
- These modules implement the matching algorithms, tool integration (browsing, data preparation), and bridge interfaces to various LLM models (GPT-3.5, GPT-4, Llama3, etc.).
- CLI & API Interface:
- The “cli” directory provides a command-line interface that serves as an alternative front end to the library.
- The library functions are exposed via API calls so that users can calibrate parameters and run matches, as seen in the sample code from the README.
- Web-based Evaluation (Libem Arena):
- Under the “arena” directory, you have a web application (with a “src”, “public”, and “app” folder structure). This React-based frontend, along with Dockerfiles, webpack configuration, and nginx settings, indicates a containerized full-stack “arena” for online evaluation and leaderboard functionality.
- The arena likely interacts with backend services for user requests and persists data (e.g., using MySQL configurations provided in the “arena/mysql” folder and corresponding YAML files).
- Benchmarking Suite:
- The “benchmark” directory includes scripts, analysis tools, benchmarking suites, and plot generators that allow evaluation and comparison over multiple entity matching datasets.
- Serve/Deployment Components:
- In the “serve” and “arena” sub-directories, you have server-related code and deployment configuration (Dockerfiles, Kubernetes/YAML deployment files) that highlight how the system is containerized and deployed.

##### Relationships and Data Flows
- The CLI and library components are tightly coupled: the CLI is essentially a front end to the library’s functionality, and both leverage the core entity matching functions.
- The web-based Arena communicates with backend services (possibly provided by the “serve” directory) and the core Libem library to perform matching requests and update the leaderboard, while using external data storage (MySQL).
- The benchmarking tools invoke the core library functions to test against different datasets, while gathering metrics and visualizing performance.
- External LLM integrations (e.g., OpenAI’s GPT models, Llama3) and tool components like “libem.browse” are integrated into the matching pipeline. Indicate the API calls/requests to these external services.

##### Important Architectural Patterns
- API & CLI Interface: The separation between CLI tools, library API, and web application indicates a multi-layered architecture.
- Full-Stack Separation (for Arena): A clear division between the frontend (React app) and the backend service (served via Docker containers, nginx proxy, and MySQL).

##### Relevant Technologies and Frameworks
- Programming/Frameworks: Python for the core logic; JavaScript/React for the Arena frontend.
- Containerization: Docker files and YAML configurations are used for packaging and possibly Kubernetes deployment.
- LLM APIs: External integration with OpenAI and other LLM models.
- Database: MySQL configurations in the arena deployment show persistent data storage.
- Build Tools: Makefile, webpack, and configuration files (.babelrc, package.json) reflect the build and development infrastructure.
- Testing: Unit tests and integration tests in the “test” directory ensure functionality.

##### Final Detailed Steps for the Principal Software Engineer
- Inside the Libem Core Library block, detail the internal modules like match, browse, resolve, and tune. You do not need a very granular view but enough to show modularity.
- User → CLI or User → Arena UI.
- CLI/Frontend → Libem Core (API call) → External LLM/Tool integrations.
- Libem Core output → CLI/UI, and Benchmarks → Libem Core → Metrics & Plotting modules.
- Use annotations to mention key technologies (e.g., “React, Node.js, Nginx” for Arena; “Python, Docker, Kubernetes” for backend deployment; “OpenAI API, GPT models” for external services).

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction Layer
    subgraph "User Interactions"
        U["User"]:::external
    end

    %% CLI & API Interface
    subgraph "CLI & API Interface"
        CLI["CLI Interface"]:::python
    end

    %% Web-based Evaluation (Libem Arena)
    subgraph "Web-based Evaluation (Arena)"
        AFE["Arena Frontend (React UI)"]:::react
        ABS["Arena Backend Service (API)"]:::python
    end

    %% Core Libem Library and Modules
    subgraph "Core Components"
        LIB["Libem Core Library"]:::python
        subgraph "Core Modules"
            MATCH["match module"]:::python
            BROWSE["browse module"]:::python
            COMPOSE["compose module"]:::python
            RESOLVE["resolve module"]:::python
            OPTIMIZE["optimize module"]:::python
            TUNE["tune module"]:::python
            PREPARE["prepare module"]:::python
        end
    end

    %% Benchmarking Suite
    subgraph "Benchmark Suite"
        BENCH["Benchmarking Suite"]:::python
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        DEPLOY["Deployment Config (Docker, Kubernetes)"]:::deployment
    end

    %% External Dependencies and Services
    subgraph "External Services"
        LLM["External LLM APIs (OpenAI, Llama3)"]:::external
        DB["MySQL Database"]:::database
    end

    %% Data Flows and Relationships
    U -->|"uses"| CLI
    U -->|"uses"| AFE

    CLI -->|"calls"| LIB
    AFE -->|"sends HTTP requests"| ABS
    ABS -->|"invokes"| LIB

    LIB -->|"integrates with"| LLM
    LIB -->|"returns results to"| CLI
    LIB -->|"returns results to"| ABS

    BENCH -->|"tests"| LIB

    ABS -->|"stores/retrieves data"| DB

    DEPLOY -->|"containerizes"| AFE
    DEPLOY -->|"containerizes"| ABS
    DEPLOY -->|"containerizes"| BENCH

    %% Internal module grouping within Core Library
    LIB ---|"includes"| MATCH
    LIB ---|"includes"| BROWSE
    LIB ---|"includes"| COMPOSE
    LIB ---|"includes"| RESOLVE
    LIB ---|"includes"| OPTIMIZE
    LIB ---|"includes"| TUNE
    LIB ---|"includes"| PREPARE

    %% Click Events for Component Mapping
    click LIB "https://github.com/abcsys/libem/tree/main/libem/"
    click CLI "https://github.com/abcsys/libem/tree/main/cli/"
    click AFE "https://github.com/abcsys/libem/tree/main/arena/app/"
    click ABS "https://github.com/abcsys/libem/tree/main/arena/serve/"
    click BENCH "https://github.com/abcsys/libem/tree/main/benchmark/"
    click DEPLOY "https://github.com/abcsys/libem/tree/main/serve/deploy/"

    %% Styles
    classDef python fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef react fill:#61dafb,stroke:#2E86C1,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef database fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef deployment fill:#D6EAF8,stroke:#2980B9,stroke-width:2px;
```
