# giteabot/gitea-backporter architecture

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

- Interactive diagram: https://gitdiagram.com/giteabot/gitea-backporter
- Repository: https://github.com/giteabot/gitea-backporter

## Overview

##### Main Components

a) External Systems:
- GitHub API (for interacting with go-gitea/gitea repository)
- GitHub Webhooks (trigger point for the bot)
- Gitea Fork Repository

b) Core Service Components:
- Webhook Handler (entry point)
- Authentication & Authorization Layer
- Task Orchestrator
- Git Operations Handler
- State Management

c) Feature Modules:
- Backport Manager
- Merge Queue Manager
- Milestone Manager
- LGTM Handler
- Comment Handler
- Lock Manager
- Feedback Manager
- Command Handler
- Last Call Manager

**[GitHub Webhook] → [Webhook Handler] → [Task Orchestrator] → [Feature Modules]**
- ↑
- [Authentication Layer]

##### Key Relationships to Highlight

- Webhook Handler receiving events from GitHub
- Authentication layer validating webhook secrets
- Task Orchestrator distributing work to appropriate modules
- Git Operations Handler interacting with repositories
- State Management maintaining PR status
- Feature modules' interactions with GitHub API

##### Technical Details

- Deno runtime environment
- GitHub API integration points
- Webhook endpoint (/trigger)
- Environment variables configuration
- File system interactions for git operations

##### Implementation Notes

- How webhook.ts acts as the entry point
- How different modules (backport.ts, labels.ts, etc.) interact
- Demonstrate the flow of GitHub events through the system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        GH[GitHub API]
        GW[GitHub Webhooks]
        GF[Gitea Fork Repository]
    end

    subgraph Core
        WH[Webhook Handler]:::core
        Auth[Authentication Layer]:::core
        TO[Task Orchestrator]:::core
        GOH[Git Operations Handler]:::core
        SM[State Management]:::core
        GHI[GitHub API Integration]:::core
        PRA[PR Actions Handler]:::core
    end

    subgraph Modules
        BM[Backport Manager]:::module
        LM[Label Manager]:::module
        MQM[Merge Queue Manager]:::module
        MM[Milestone Manager]:::module
        LGTM[LGTM Handler]:::module
        CH[Comment Handler]:::module
        LockM[Lock Manager]:::module
        FM[Feedback Manager]:::module
        CMD[Command Handler]:::module
        LCM[Last Call Manager]:::module
        GVH[Gitea Version Handler]:::module
    end

    subgraph Infrastructure
        Docker[Docker Container]:::infra
        CICD[CI/CD Pipeline]:::infra
        Deploy[Deployment Config]:::infra
        Types[Type Definitions]:::infra
    end

    %% External to Core Connections
    GW --> WH
    GH <--> GHI

    %% Core Component Connections
    WH --> Auth
    Auth --> TO
    TO --> GOH
    TO --> SM
    TO --> GHI
    TO --> PRA

    %% Core to Modules Connections
    TO --> BM
    TO --> LM
    TO --> MQM
    TO --> MM
    TO --> LGTM
    TO --> CH
    TO --> LockM
    TO --> FM
    TO --> CMD
    TO --> LCM
    TO --> GVH

    %% Module Interactions with Core
    BM & LM & MQM & MM & LGTM & CH & LockM & FM & CMD & LCM & GVH --> GHI
    BM & LM & MQM & MM & LGTM & CH & LockM & FM & CMD & LCM & GVH --> SM
    BM --> GOH

    %% Infrastructure Connections
    Docker -.-> WH
    CICD -.-> Docker
    Deploy -.-> Docker
    Types -.-> TO

    %% Click Events
    click WH "https://github.com/GiteaBot/gitea-backporter/blob/main/src/webhook.ts"
    click GOH "https://github.com/GiteaBot/gitea-backporter/blob/main/src/git.ts"
    click SM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/state.ts"
    click GHI "https://github.com/GiteaBot/gitea-backporter/blob/main/src/github.ts"
    click PRA "https://github.com/GiteaBot/gitea-backporter/blob/main/src/prActions.ts"
    click BM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/backport.ts"
    click LM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/labels.ts"
    click MQM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/mergeQueue.ts"
    click MM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/milestones.ts"
    click LGTM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/lgtm.ts"
    click CH "https://github.com/GiteaBot/gitea-backporter/blob/main/src/comments.ts"
    click LockM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/lock.ts"
    click FM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/feedback.ts"
    click CMD "https://github.com/GiteaBot/gitea-backporter/blob/main/src/cmd.ts"
    click LCM "https://github.com/GiteaBot/gitea-backporter/blob/main/src/lastCall.ts"
    click Types "https://github.com/GiteaBot/gitea-backporter/blob/main/src/types.ts"
    click GVH "https://github.com/GiteaBot/gitea-backporter/blob/main/src/giteaVersion.ts"
    click CICD "https://github.com/GiteaBot/gitea-backporter/blob/main/.github/workflows/ci.yml"
    click Docker "https://github.com/GiteaBot/gitea-backporter/tree/main/Dockerfile"
    click Deploy "https://github.com/GiteaBot/gitea-backporter/blob/main/fly.toml"

    %% Styling
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef module fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Feature Modules]:::module
        L3[External Systems]:::external
        L4[Infrastructure]:::infra
    end
```
