# ubiquity-os-marketplace/text-conversation-rewards architecture

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

- Interactive diagram: https://gitdiagram.com/ubiquity-os-marketplace/text-conversation-rewards
- Repository: https://github.com/ubiquity-os-marketplace/text-conversation-rewards

## Overview

##### Main Components
- Content Evaluation Engine – This accepts raw conversation data (from issues and pull requests), preprocesses it (removing user commands, quotes, HTML comments, etc.), and calculates relevance scores using language models. It resides in the “src/parser” and “src/configuration” directories.
- Review Incentivization System – Takes review metadata (e.g., additions, deletions, issue labels, review state) and computes rewards using defined structures (as seen in the ReviewScore interface). This is also modularized in “src/parser/review-incentivizer-module.ts”.
- Permit Generation and Reward Distribution – Handles the secure generation of ERC20 permit tokens and fee processing. This module validates permissions against GitHub organization/repository IDs, calculates fees, and outputs claimable URLs. The permit-specific configurations are in “src/configuration/permit-generation-configuration.ts” and related modules.
- Token Management and Calculation – Uses libraries such as decimal.js for precise arithmetic operations during reward calculations.
- Data Collection and GitHub Integration – In “src/data-collection” you have scripts and fixtures for collecting comments and events using the GitHub GraphQL API. These modules handle fetching, deduplicating, and pre-processing data.
- Web UI Component – Separated within “src/web” which includes a web front-end (with main.tsx, index.html, API endpoints) to display or aid in permit distribution (also linking to the Permit2 allowance UI).
- Configuration and Plugin Setup – All configuration files (in “src/configuration/”) define how each module behaves, controlling multipliers, API limits, encryption parameters, etc.
- External Integrations – External services include GitHub GraphQL endpoints, a Supabase database for storing permits, and Ethereum-related services for tokens.

##### Relationships and Data Flow
- The Content Evaluation Engine takes this data, processes the context, and produces relevance scores (0 to 1) based on parsed markdown and content context.
- Simultaneously, the Review Incentivization System evaluates the review comments and computes review scores (reward, effect, and priority) based on file changes and review state.
- These evaluation outputs feed into a reward calculation process that incorporates the provided formula. This aggregated result then passes to the Permit Generation module.
- The Permit Generation module runs security checks, fee processing, and finally, outputs ERC20 permits alongside claimable URLs.
- The web UI component provides an interface for viewing, managing, or even triggering parts of this workflow and may also interact with permit verification.
- Lastly, all configurations are loaded at start-up and reused by each module to ensure consistency across token limits, fee structures, and evaluation rules.

##### Architectural Patterns and Design Principles
- Modular Design: Each core functionality (evaluation, incentivization, permit generation) is encapsulated as its own module.
- Data Flow Pipelines: There is a clear sequential processing—from data collection to content evaluation, reward calculations, and finally distribution.
- External API Integration: The system integrates with GitHub, potentially Supabase, and Ethereum-based token services.
- Extensibility: A plugin architecture allows configuration to modify behaviors (via YAML configurations in “src/configuration”).
- Testing and Mocks: There is a comprehensive “tests” directory indicating that unit tests and integration tests cover most modules, reinforcing the modular design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integrations
    API["GitHub API (External)"]:::integration
    SUPABASE["Supabase Database"]:::integration
    ETH["Ethereum Token Service"]:::integration

    %% Data Collection Layer
    DC["Data Collection & GitHub Integration\n(Collects GitHub issues & PR comments)"]:::processing

    %% Core Processing Layers
    CE["Content Evaluation Engine\n(Processes conversation data)"]:::processing
    CEC["Content Evaluator Config"]:::config

    RI["Review Incentivization System\n(Computes review scores)"]:::processing
    RIC["Review Incentivizer Config"]:::config

    RC["Reward Calculation Engine\n(Aggregates evaluation outputs)"]:::processing

    PG["Permit Generation & Reward Distribution\n(Issues ERC20 permits)"]:::processing
    PGC["Permit Generation Config"]:::config

    %% Web UI Component
    UI["Web UI Component\n(Interface for permits)"]:::ui

    %% Global Configuration
    GC["Configuration & Plugin Setup"]:::config

    %% Data Flow Definitions
    API -->|"fetches data"| DC
    DC -->|"sends raw data"| CE
    DC -->|"sends raw data"| RI
    CE -->|"outputs scores"| RC
    RI -->|"outputs review scores"| RC
    RC -->|"aggregated result"| PG

    PG -- "stores permits" --> SUPABASE
    PG -- "triggers token issuance" --> ETH

    UI <-->|"API calls"| PG

    %% Configuration flows to various modules
    GC --> CE
    GC --> RI
    GC --> RC
    GC --> PG

    %% Click Events
    click CE "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/parser/content-evaluator-module.ts"
    click CEC "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/configuration/content-evaluator-config.ts"
    click RI "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/parser/review-incentivizer-module.ts"
    click RIC "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/configuration/review-incentivizer-config.ts"
    click PG "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/parser/permit-generation-module.ts"
    click PGC "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/blob/development/src/configuration/permit-generation-configuration.ts"
    click DC "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/tree/development/src/data-collection"
    click UI "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/tree/development/src/web"
    click GC "https://github.com/ubiquity-os-marketplace/text-conversation-rewards/tree/development/src/configuration"

    %% Styles
    classDef processing fill:#CFE2F3,stroke:#2E75B6,stroke-width:2px;
    classDef config fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
    classDef ui fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef integration fill:#FCE5CD,stroke:#E69138,stroke-width:2px;
```
