# koderover/zadig architecture

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

- Interactive diagram: https://gitdiagram.com/koderover/zadig
- Repository: https://github.com/koderover/zadig

## Overview

##### High-Level Components
First, represent the main microservices identified in the /pkg/microservice directory:

a) Core Services (Primary Layer):
- Aslan Service (Main application service)
- User Service (Authentication/Authorization)
- Cron Service (Scheduled tasks)
- Hub Server/Agent (Cluster management)

b) Supporting Services (Secondary Layer):
- Job Executor
- Reaper (Build/Test execution)
- Predator (Testing)
- Jenkins Plugin
- Packager Plugin

##### Key Architectural Patterns

Following architectural patterns:
- Microservices Architecture
- Event-driven Architecture (using message queues)
- API Gateway pattern
- Multi-cluster Management

##### Infrastructure Layer

Include:
- Kubernetes Clusters
- MongoDB (primary database)
- Redis (caching)
- Object Storage (S3)
- Message Queue (NSQ)

##### Integration Points

External integrations:
- Source Code Management (GitHub, GitLab, Gerrit)
- Container Registries
- CI Tools (Jenkins)
- Monitoring Systems (Grafana)
- Notification Systems (DingTalk, Lark)

##### Data Flow Patterns

Workflows:
- CI/CD Pipeline Flow
- Environment Management Flow
- Multi-cluster Deployment Flow
- User Authentication Flow

##### Key Relationships

Highlight:
- Service Dependencies
- API Communications
- Event Publishing/Subscription
- Database Access Patterns

##### Security Boundaries

Indicate:
- Authentication Boundaries
- Authorization Zones
- Network Segmentation
- API Gateway Security

##### Scalability Points

Mark:
- Horizontally Scalable Components
- Caching Layers
- Load Balancing Points
- State Management

##### Monitoring & Observability

Show:
- Logging Points
- Metrics Collection
- Tracing Implementation
- Health Check Endpoints

##### External Integration Layer

Remember to:
- Critical technical details while maintaining clarity
- Both runtime and deployment perspectives
- Scalability and reliability patterns
- Document key design decisions and trade-offs

This system design should reflect Zadig's cloud-native nature and its focus on developer self-service while maintaining enterprise-grade scalability and reliability.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#B2D7DA
    classDef gateway fill:#95A5A6
    classDef core fill:#3498DB
    classDef support fill:#2ECC71
    classDef infra fill:#F1C40F
    classDef external fill:#BDC3C7
    
    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        UI[Web UI]:::client
        CLI[CLI Tool]:::client
        API[API Clients]:::client
    end

    %% API Gateway
    Gateway["API Gateway"]:::gateway

    %% Core Services Layer
    subgraph CoreServices["Core Services"]
        Aslan["Aslan Service"]:::core
        UserSvc["User Service"]:::core
        CronSvc["Cron Service"]:::core
        HubServer["Hub Server"]:::core
        HubAgent["Hub Agent"]:::core
    end

    %% Supporting Services Layer
    subgraph SupportServices["Supporting Services"]
        JobExec["Job Executor"]:::support
        Reaper["Reaper"]:::support
        Predator["Predator"]:::support
        JenkinsPlugin["Jenkins Plugin"]:::support
        PackagerPlugin["Packager Plugin"]:::support
    end

    %% Infrastructure Layer
    subgraph Infrastructure["Infrastructure Layer"]
        MongoDB[(MongoDB)]:::infra
        Redis[(Redis Cache)]:::infra
        NSQ[("Message Queue\n(NSQ)")]:::infra
        K8s["Kubernetes\nClusters"]:::infra
        S3["Object Storage\n(S3)"]:::infra
    end

    %% External Systems
    subgraph ExternalSystems["External Systems"]
        Git["Source Code\nManagement"]:::external
        Registry["Container\nRegistries"]:::external
        Jenkins["Jenkins CI"]:::external
        Grafana["Monitoring\n(Grafana)"]:::external
        Chat["Notification\nSystems"]:::external
    end

    %% Relationships
    UI --> Gateway
    CLI --> Gateway
    API --> Gateway
    Gateway --> Aslan
    Gateway --> UserSvc
    Aslan --> MongoDB
    Aslan --> Redis
    Aslan --> NSQ
    Aslan --> JobExec
    JobExec --> K8s
    Reaper --> K8s
    HubServer --> HubAgent
    HubAgent --> K8s
    Aslan --> Git
    Aslan --> Registry
    JenkinsPlugin --> Jenkins
    Predator --> K8s
    CronSvc --> NSQ
    UserSvc --> MongoDB

    %% Click Events
    click Aslan "https://github.com/koderover/zadig/tree/main//pkg/microservice/aslan/"
    click UserSvc "https://github.com/koderover/zadig/tree/main//pkg/microservice/user/"
    click CronSvc "https://github.com/koderover/zadig/tree/main//pkg/microservice/cron/"
    click HubServer "https://github.com/koderover/zadig/tree/main//pkg/microservice/hubserver/"
    click HubAgent "https://github.com/koderover/zadig/tree/main//pkg/microservice/hubagent/"
    click JobExec "https://github.com/koderover/zadig/tree/main//pkg/microservice/jobexecutor/"
    click Reaper "https://github.com/koderover/zadig/tree/main//pkg/microservice/reaper/"
    click Predator "https://github.com/koderover/zadig/tree/main//pkg/microservice/predator/"
    click JenkinsPlugin "https://github.com/koderover/zadig/tree/main//pkg/microservice/jenkinsplugin/"
    click PackagerPlugin "https://github.com/koderover/zadig/tree/main//pkg/microservice/packager/"
    click MongoDB "https://github.com/koderover/zadig/tree/main//pkg/microservice/aslan/core/common/repository/mongodb/"
    click Redis "https://github.com/koderover/zadig/blob/main//pkg/handler/cache/redis_cache.go"
    click NSQ "https://github.com/koderover/zadig/tree/main//pkg/microservice/aslan/core/common/service/nsq/"
    click Git "https://github.com/koderover/zadig/tree/main//pkg/tool/git/"
    click Jenkins "https://github.com/koderover/zadig/tree/main//pkg/tool/jenkins/"
    click K8s "https://github.com/koderover/zadig/tree/main//pkg/tool/kube/"

    %% Legend
    subgraph Legend["Legend"]
        L_Client["Client Component"]:::client
        L_Gateway["Gateway"]:::gateway
        L_Core["Core Service"]:::core
        L_Support["Support Service"]:::support
        L_Infra["Infrastructure"]:::infra
        L_External["External System"]:::external
    end
```
