# katorlys/github-mirror-gitea architecture

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

- Interactive diagram: https://gitdiagram.com/katorlys/github-mirror-gitea
- Repository: https://github.com/katorlys/github-mirror-gitea

## Overview

##### Main Components

a) External Services Layer:
- GitHub API (with authentication)
- Gitea API (with authentication)

b) Core Application Components:
- Configuration Manager (handling credentials.toml and options.toml)
- Cache System (represented by cache.py)
- Repository Handlers:
- GitHub Repository Manager (githubRepo.py)
- Gitea Repository Manager (giteaRepo.py)
- Gitea Organization Manager (giteaOrg.py)
- Mirror Controller (mirror.py)
- Repository Rules Engine (repoRules.py)

##### Component Relationships and Data Flow

**[Configuration Manager] → [Mirror Controller]**
- ↓
**[GitHub API] ←→ [GitHub Repo Manager] → [Mirror Controller] ← [Repository Rules Engine]**
- ↓
**[Gitea API] ←→ [Gitea Repo Manager] ← [Mirror Controller] → [Gitea Org Manager]**
- ↓
- [Cache System]

##### Important Details

a) Configuration Flows:
- How credentials.toml and options.toml feed into the system
- Environment variable support for Docker deployment

b) Process Flows:
- Repository discovery flow from GitHub
- Rule application process
- Mirror creation/update flow to Gitea
- Organization creation when needed

##### Deployment Options

A small section showing the three deployment methods:
- Direct Python execution
- Docker container
- GitHub Actions

This system design should help developers understand both the overall architecture and the specific components that enable the mirroring functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Services"]
        direction TB
        GH[GitHub API]:::external
        GT[Gitea API]:::external
    end

    subgraph Config["Configuration Layer"]
        direction TB
        CM["Configuration Manager"]:::config
        CRED["credentials.toml"]:::config
        OPT["options.toml"]:::config
        CRED --> CM
        OPT --> CM
    end

    subgraph Core["Core Processing Layer"]
        direction TB
        MC["Mirror Controller"]:::core
        GRM["GitHub Repository Manager"]:::core
        GTRM["Gitea Repository Manager"]:::core
        GTOM["Gitea Organization Manager"]:::core
        RRE["Repository Rules Engine"]:::core
        CS["Cache System"]:::cache
    end

    subgraph Deploy["Deployment Options"]
        direction TB
        PY["Python Execution"]:::deploy
        DK["Docker Container"]:::deploy
        GHA["GitHub Actions"]:::deploy
    end

    %% Relationships
    CM --> MC
    GH <-.-> GRM
    GT <-.-> GTRM
    GT <-.-> GTOM
    
    GRM --> MC
    MC --> GTRM
    MC --> GTOM
    RRE --> MC
    MC --> CS

    %% Click Events
    click CM "https://github.com/katorlys/github-mirror-gitea/blob/main/config.py"
    click CRED "https://github.com/katorlys/github-mirror-gitea/blob/main/config/credentials.toml"
    click OPT "https://github.com/katorlys/github-mirror-gitea/blob/main/config/options.toml"
    click CS "https://github.com/katorlys/github-mirror-gitea/blob/main/cache.py"
    click GRM "https://github.com/katorlys/github-mirror-gitea/blob/main/utils/githubRepo.py"
    click GTRM "https://github.com/katorlys/github-mirror-gitea/blob/main/utils/giteaRepo.py"
    click GTOM "https://github.com/katorlys/github-mirror-gitea/blob/main/utils/giteaOrg.py"
    click MC "https://github.com/katorlys/github-mirror-gitea/blob/main/utils/mirror.py"
    click RRE "https://github.com/katorlys/github-mirror-gitea/blob/main/utils/repoRules.py"
    click DK "https://github.com/katorlys/github-mirror-gitea/tree/main/Dockerfile"
    click GHA "https://github.com/katorlys/github-mirror-gitea/blob/main/.github/workflows/docker-build.yml"

    %% Styling
    classDef external fill:#68a3ff,stroke:#333,stroke-width:2px
    classDef config fill:#ffd700,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef cache fill:#d3d3d3,stroke:#333,stroke-width:2px
    classDef deploy fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        direction TB
        L1[External Services]:::external
        L2[Configuration Components]:::config
        L3[Core Components]:::core
        L4[Cache System]:::cache
        L5[Deployment Options]:::deploy
    end

    %% Notes
    note["Note: Gitea performs automatic<br/>fetch every 8 hours"]
    style note fill:#fff,stroke:#333,stroke-width:1px
```
