# alirezasalemi7/expert architecture

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

- Interactive diagram: https://gitdiagram.com/alirezasalemi7/expert
- Repository: https://github.com/alirezasalemi7/expert

## Overview

##### Project Type and Purpose
- ExPerT is a Python library (an open-source evaluation tool) for explainable, reference-based scoring of personalized long-form text generated by large language models (LLMs). It provides a pipeline that:
a. Extracts atomic aspects from generated and reference texts
b. Matches and aligns those aspects
c. Produces alignment scores and human-readable explanations via an LLM backbone

##### High-Level Architecture
- This is a library/API-driven system, not a web application. The core runtime is a single Python process that orchestrates calls to an external LLM service.
- Main components:
- Client code (user script or notebook)
- ExPerT orchestrator (`expert_score.expert`)
- Submodules:
– Aspect Extraction (`aspects/extraction.py`)
– Aspect Matching (`matching/match.py`, `matching/utils.py`)
– Utilities (`utils/api_llm.py`, `utils/json_parsing.py`)
- External LLM Service (OpenAI, Google, or Hugging Face model)
- Local Cache Directory

##### Data Flow and Component Interaction
1. Client invokes `expert(inputs, outputs, references, …)`.
2. The orchestrator prepares prompts and calls `utils/api_llm` to dispatch to the chosen LLM.
3. LLM responses are parsed by `utils/json_parsing`.
4. Parsed output feeds into:
a. Aspect Extraction module → yields atomic aspects + evidences
b. Aspect Matching module → aligns aspects between generated vs. reference
5. Scoring logic in `expert.py` aggregates content/style alignment scores.
6. Explanations are assembled (detailed step-by-step).
7. Final score + explanations return to client.
8. Cache module (in `api_llm`) handles prompt/result caching and retry logic.

##### Architectural Patterns and Design Principles
- Pipeline pattern: sequential stages (extract → match → score → explain).
- Separation of concerns:
- `aspects/` handles extraction logic
- `matching/` handles alignment logic
- `utils/` abstracts LLM API and parsing
- Extensibility points:
- Swap or configure LLM backend (OpenAI, Google, Hugging Face)
- Tweak extraction or matching strategies by subclassing modules

##### Elements
- Clear component labels: “Client Script,” “ExPerT Orchestrator,” “Aspect Extraction,” etc.
- Arrowheads showing flow order: client → orchestrator → LLM → parsing → extraction → matching → scoring → client.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client Script"]:::internal

    %% Package Initialization
    subgraph "Package Initialization"
        I1["expert_score/__init__.py"]:::internal
        I2["expert_score/aspects/__init__.py"]:::internal
        I3["expert_score/matching/__init__.py"]:::internal
        I4["expert_score/utils/__init__.py"]:::internal
    end

    %% Core Pipeline
    subgraph "ExPerT Pipeline"
        E1["ExPerT Orchestrator"]:::internal
        E2["Scoring & Explanation"]:::internal
    end

    %% Aspect Extraction
    subgraph "Aspect Extraction"
        AE["Aspect Extraction"]:::internal
    end

    %% Aspect Matching
    subgraph "Aspect Matching"
        AM1["Matching Logic"]:::internal
        AM2["Matching Utilities"]:::internal
    end

    %% Utilities
    subgraph "Utilities"
        U1["LLM API Adapter / Cache"]:::cache
        U2["LLM Response Parser"]:::internal
    end

    %% External Service
    LLM["External LLM Service"]:::external

    %% Data Flow
    Client -->|"invoke expert()"| E1
    E1 -->|"prepare prompt"| U1
    U1 -->|"LLM API call"| LLM
    LLM -->|"response"| U1
    U1 -->|"JSON response"| U2
    U2 -->|"parsed data"| AE
    AE -->|"atomic aspects"| AM1
    AM2 --> AM1
    AM1 -->|"aligned aspects"| E2
    E2 -->|"results + explanations"| Client

    %% Click Events
    click E1 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/expert.py"
    click AE "https://github.com/alirezasalemi7/expert/blob/main/expert_score/aspects/extraction.py"
    click AM1 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/matching/match.py"
    click AM2 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/matching/utils.py"
    click U1 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/utils/api_llm.py"
    click U2 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/utils/json_parsing.py"
    click I1 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/__init__.py"
    click I2 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/aspects/__init__.py"
    click I3 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/matching/__init__.py"
    click I4 "https://github.com/alirezasalemi7/expert/blob/main/expert_score/utils/__init__.py"

    %% Styles
    classDef internal fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef external fill:#ccf,stroke:#333,stroke-width:1px
    classDef cache fill:#fea,stroke:#333,stroke-width:1px
```
