# milankomaj/dev-badge architecture

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

- Interactive diagram: https://gitdiagram.com/milankomaj/dev-badge
- Repository: https://github.com/milankomaj/dev-badge

## Overview

##### Main Components

a) Client Layer:
- Web Browsers/API Consumers
- Badge Request Endpoints

b) Cloudflare Workers Runtime:
- Main Worker Handler (index.js)
- Module System
- Configuration Layer

c) External Services Integration:
- Multiple API Integrations (shown in /mods directory)
- Authentication/Secrets Management

##### Key Architectural Elements

a) Request Flow:
- How requests flow through the worker handler
- Module routing and processing

b) Modular Architecture:
- Pluggable nature of the badge modules
- How different services (GitHub, NPM, Docker, etc.) connect

c) Helper Functions:
- Utility layer (helpers directory)
- How these support the main badge generation

- [Client Layer]
- ↓
- [Cloudflare Workers Runtime]
- ↓
- [External Services]

##### For the Workers Runtime section, create a detailed breakdown
- [Main Handler]
- ↓
- [Module Router] → [Configuration]
- ↓
- [Badge Modules] ← [Helpers]

##### For the External Services section, group the APIs by type
- Version Control (GitHub, etc.)
- Package Managers (NPM, etc.)
- Metrics Services (Travis, AppVeyor)
- Media Services (Spotify, YouTube)

##### Specific Elements
- Badge generation flow
- Configuration management
- Secret handling
- Cache layer (if applicable)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Browser["Web Browsers"]
        APIConsumer["API Consumers"]
    end

    %% Cloudflare Workers Runtime
    subgraph WorkerRuntime["Cloudflare Workers Runtime"]
        MainHandler["Main Worker Handler"]:::core
        ModuleRouter["Module Router"]:::core
        Config["Configuration Layer"]:::config
        
        subgraph Modules["Badge Modules"]
            GitHub["GitHub Module"]:::module
            NPM["NPM Module"]:::module
            Docker["Docker Module"]:::module
            Spotify["Spotify Module"]:::module
            Travis["Travis Module"]:::module
            AppVeyor["AppVeyor Module"]:::module
        end
        
        subgraph Helpers["Helper Utilities"]
            BadgeGen["Badge Generation"]:::helper
            IPGeo["IP Geolocation"]:::helper
            SpotifyHelper["Spotify Helper"]:::helper
            StarsHelper["Stars Helper"]:::helper
            VersionHelper["Version Helper"]:::helper
        end
        
        subgraph ConfigMgmt["Configuration Management"]
            Secrets["Secrets Management"]:::config
            WorkerConfig["Worker Configuration"]:::config
            DevVars["Development Variables"]:::config
            CICD["CI/CD Pipeline"]:::config
        end
    end

    %% External Services
    subgraph ExternalServices["External Services"]
        GitHubAPI["GitHub API"]:::external
        NPMAPI["NPM API"]:::external
        DockerAPI["Docker API"]:::external
        SpotifyAPI["Spotify API"]:::external
        TravisAPI["Travis API"]:::external
        AppVeyorAPI["AppVeyor API"]:::external
    end

    %% Relationships
    Browser --> MainHandler
    APIConsumer --> MainHandler
    MainHandler --> ModuleRouter
    ModuleRouter --> Config
    ModuleRouter --> Modules
    Modules --> Helpers
    Config --> ConfigMgmt
    
    GitHub --> GitHubAPI
    NPM --> NPMAPI
    Docker --> DockerAPI
    Spotify --> SpotifyAPI
    Travis --> TravisAPI
    AppVeyor --> AppVeyorAPI

    %% Click Events
    click MainHandler "https://github.com/milankomaj/dev-badge/blob/master/index.js"
    click ModuleRouter "https://github.com/milankomaj/dev-badge/blob/master/mods/index.js"
    click Config "https://github.com/milankomaj/dev-badge/blob/master/config/index.js"
    click BadgeGen "https://github.com/milankomaj/dev-badge/blob/master/helpers/badge.js"
    click GitHub "https://github.com/milankomaj/dev-badge/blob/master/mods/github.js"
    click NPM "https://github.com/milankomaj/dev-badge/blob/master/mods/npm.js"
    click Docker "https://github.com/milankomaj/dev-badge/blob/master/mods/docker.js"
    click Spotify "https://github.com/milankomaj/dev-badge/blob/master/mods/spotify.js"
    click Travis "https://github.com/milankomaj/dev-badge/blob/master/mods/travis.js"
    click AppVeyor "https://github.com/milankomaj/dev-badge/blob/master/mods/appveyor.js"
    click IPGeo "https://github.com/milankomaj/dev-badge/blob/master/helpers/ipgeo.js"
    click SpotifyHelper "https://github.com/milankomaj/dev-badge/blob/master/helpers/spotify.js"
    click StarsHelper "https://github.com/milankomaj/dev-badge/blob/master/helpers/stars.js"
    click VersionHelper "https://github.com/milankomaj/dev-badge/blob/master/helpers/version.js"
    click Secrets "https://github.com/milankomaj/dev-badge/blob/master/example.secrets.json"
    click WorkerConfig "https://github.com/milankomaj/dev-badge/blob/master/wrangler.toml"
    click CICD "https://github.com/milankomaj/dev-badge/blob/master/.github/workflows/deploy.yml"
    click DevVars "https://github.com/milankomaj/dev-badge/blob/master/.dev.vars"

    %% Styles
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef module fill:#ADD8E6,stroke:#333
    classDef helper fill:#D3D3D3,stroke:#333
    classDef config fill:#FFE4B5,stroke:#333
    classDef external fill:#FFA07A,stroke:#333

    %% Legend
    subgraph Legend
        CoreComponent["Core Component"]:::core
        ModuleComponent["Module Component"]:::module
        HelperComponent["Helper Component"]:::helper
        ConfigComponent["Config Component"]:::config
        ExternalComponent["External Service"]:::external
    end
```
