# ubiquity-os-marketplace/daemon-pricing architecture

> Architecture diagram of the GitHub repository ubiquity-os-marketplace/daemon-pricing, 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/daemon-pricing
- Repository: https://github.com/ubiquity-os-marketplace/daemon-pricing

## Overview

##### Main Components
- Cloudflare Worker: Since the runtime is Cloudflare Workers, include this as the central execution environment.
- Plugin System: Represent the core plugin system (built on @ubiquity-os/plugin-sdk) which handles webhook events and dynamic configuration.
- Permission System: Illustrate the module that manages fine-grained access controls for label management and repository-specific rules.
- GitHub Integration: Include a dedicated component to manage GitHub OAuth, webhook event processing, and issue/label modifications.
- External Services & Development Tools: Optionally note testing (Jest), linting (ESLint/Prettier), and configuration management (Wrangler, Supabase for local development).

##### And Map Relationships
- The Plugin System receives events (via @octokit/webhooks) and validates/normalizes them.
- The Label Management Module consumes processed data from the Plugin System, applying business rules to create or update labels.
- The Permission System validates whether a particular operation on labels is authorized, based on collaborators, repository rules, etc.
- Configuration stores (using environment-specific configuration files and envSchema) and error handling paths (e.g., automatic issue commenting on error).

##### Architectural Patterns and Design Principles
- Service-Oriented and Plugin Architecture: Emphasize the separation between core event-handling logic and specialized modules (label and permission management).
- Microservice/Serverless Architecture: Since the service runs on Cloudflare Workers, highlight the event-driven, serverless nature of the design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Systems"
        GH["GitHub (External)"]:::external
    end

    subgraph "Cloudflare Worker Environment"
        Worker["Cloudflare Worker Runtime"]:::worker
        Plugin["Plugin System (@ubiquity-os/plugin-sdk & @octokit/webhooks)"]:::plugin

        subgraph "Business Logic"
            subgraph "Label Management Module"
                PL["Pricing Label Handler"]:::handler
                GL["Get Label Changes Handler"]:::handler
                LC["Label Checks Handler"]:::handler
                SL["Label Shared Logic"]:::shared
                SP["Pricing Shared Logic"]:::shared
            end
            subgraph "Permission System"
                PShared["Permissions Shared"]:::handler
                CT["Context & Plugin Input Types"]:::handler
            end
        end

        GitIntegration["GitHub Integration"]:::integration
        Error["Error Handling & Issue Commenting"]:::error
    end

    subgraph "GitHub Integration Details"
        GTypes["GitHub Types & API Integration"]:::handler
        GCC["Get Commit Changes Handler"]:::handler
        GConfig["Global Config Update Handler"]:::handler
    end

    subgraph "Configuration & Development"
        Config["Configuration Manager"]:::config
        DevTools["Testing & Linting Tools"]:::dev
    end

    %% Connections
    GH -->|"webhook"| Worker
    Worker -->|"processesEvent"| Plugin
    Worker -->|"loadsConfig"| Config
    Plugin -->|"sendsDataTo"| PL
    Plugin -->|"sendsDataTo"| GL
    Plugin -->|"sendsDataTo"| LC
    Plugin -->|"checksPerms"| CT
    Plugin -->|"handlesError"| Error
    PL --- SL
    PL --- SP
    GL --- SL
    LC --- SP

    %% Permission System linkage
    CT --- PShared

    %% Business Logic to GitHub Integration
    PL --> GitIntegration
    GL --> GitIntegration
    LC --> GitIntegration
    CT --> GitIntegration
    PShared --> GitIntegration

    GitIntegration -->|"updatesIssuesLabels"| GH

    %% Link GitHub Integration internal components
    GitIntegration --> GTypes
    GitIntegration --> GCC
    GitIntegration --> GConfig

    %% Development tools dependency
    DevTools -->|"usedInDevelopment"| Plugin

    %% Click Events
    click Worker "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/worker.ts"
    click Plugin "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/index.ts"
    click Plugin "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/run.ts"
    click PL "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/handlers/pricing-label.ts"
    click GL "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/handlers/get-label-changes.ts"
    click LC "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/handlers/label-checks.ts"
    click SL "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/shared/label.ts"
    click SP "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/shared/pricing.ts"
    click PShared "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/shared/permissions.ts"
    click CT "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/types/context.ts"
    click CT "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/types/plugin-input.ts"
    click GTypes "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/types/github.ts"
    click GCC "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/handlers/get-commit-changes.ts"
    click GConfig "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/src/handlers/global-config-update.ts"
    click Config "https://github.com/ubiquity-os-marketplace/daemon-pricing/tree/development/.github/workflows/"
    click Config "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/wrangler.toml"
    click DevTools "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/jest.config.ts"
    click DevTools "https://github.com/ubiquity-os-marketplace/daemon-pricing/blob/development/eslint.config.mjs"
    click DevTools "https://github.com/ubiquity-os-marketplace/daemon-pricing/tree/development/tests/"

    %% Style Classes
    classDef external fill:#aqua,stroke:#000,stroke-width:2px;
    classDef worker fill:#f3a683,stroke:#000,stroke-width:2px;
    classDef plugin fill:#badc58,stroke:#000,stroke-width:2px;
    classDef module fill:#f9ca24,stroke:#000,stroke-width:2px;
    classDef handler fill:#ff7979,stroke:#000,stroke-width:2px;
    classDef shared fill:#f6e58d,stroke:#000,stroke-width:2px;
    classDef integration fill:#7ed6df,stroke:#000,stroke-width:2px;
    classDef error fill:#e056fd,stroke:#000,stroke-width:2px;
    classDef config fill:#dff9fb,stroke:#000,stroke-width:2px;
    classDef dev fill:#c7ecee,stroke:#000,stroke-width:2px;
```
