# betterde/ects architecture

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

- Interactive diagram: https://gitdiagram.com/betterde/ects
- Repository: https://github.com/betterde/ects

## Overview

##### Main Components

a. Core System Components:
- Master Node (Controller)
- Worker Nodes
- ETCD Cluster (as the distributed coordination system)
- Web UI Interface
- API Layer

b. Key Services:
- Authentication Service (controllers/auth)
- Pipeline Service (internal/pipeline)
- Task Service (services/task)
- Node Service (services/node)
- Scheduler Service (internal/scheduler)
- Notification System (internal/notify)

##### Architecture Layers

**┌─────────────────────────────────────────────┐**
- Web UI                    │
- (Vue.js + Element UI + Vuex + Vue Router)   │
- ┤
- API Gateway                 │
- (Go HTTP Controllers)             │
- ┤
- Core Services                 │
- ┬──────────────┬──────────────┤
- Master Node │ Worker Nodes │    ETCD      │
- ┴──────────────┴──────────────┘

##### Component Interactions

- Communication between Master and Worker nodes via ETCD
- API requests from Web UI to backend services
- Task execution flow from scheduler to workers
- Event notifications and hooks
- Service discovery and health checks

##### Specific Implementation Details

Technical elements:
- Actuators (internal/actuator):
- HTTP
- Shell
- Hook
- Mail
- Message System (internal/message)
- Service Discovery (internal/discover)
- Pipeline Management
- Task Scheduling

##### Additional Elements

Supporting components:
- Authentication flow
- Permission management
- Task execution pipeline
- Monitoring and logging system
- Configuration management

##### Security and monitoring aspects

Remember to maintain a balance between detail and clarity, focusing on the distributed architecture while showing how ETCD enables coordination between components.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        WebUI["Web UI"]:::frontend
        APILayer["API Layer"]:::frontend
        StateManagement["State Management"]:::frontend
        Router["Router"]:::frontend
        Views["Views"]:::frontend
    end

    subgraph APIGateway
        TaskRoutes["Task Routes"]:::api
        NodeRoutes["Node Routes"]:::api
        PipelineRoutes["Pipeline Routes"]:::api
        AuthRoutes["Auth Routes"]:::api
    end

    subgraph CoreServices
        AuthService["Authentication Service"]:::service
        PipelineService["Pipeline Service"]:::service
        TaskService["Task Service"]:::service
        NodeService["Node Service"]:::service
        SchedulerService["Scheduler Service"]:::service
        NotificationSystem["Notification System"]:::service
    end

    subgraph Actuators
        HTTPActuator["HTTP Actuator"]:::actuator
        ShellActuator["Shell Actuator"]:::actuator
        MailActuator["Mail Actuator"]:::actuator
        HookActuator["Hook Actuator"]:::actuator
    end

    subgraph Infrastructure
        Master["Master Node"]:::core
        Worker["Worker Node"]:::core
        ETCD[("ETCD Cluster")]:::db
        MessageSystem["Message System"]:::service
        ServiceDiscovery["Service Discovery"]:::service
    end

    subgraph Models
        TaskModel["Task Model"]:::model
        NodeModel["Node Model"]:::model
        PipelineModel["Pipeline Model"]:::model
        UserModel["User Model"]:::model
    end

    %% Frontend Connections
    WebUI --> APILayer
    APILayer --> StateManagement
    APILayer --> Router
    Router --> Views

    %% API Gateway Connections
    APILayer --> TaskRoutes
    APILayer --> NodeRoutes
    APILayer --> PipelineRoutes
    APILayer --> AuthRoutes

    %% Core Service Connections
    TaskRoutes --> TaskService
    NodeRoutes --> NodeService
    PipelineRoutes --> PipelineService
    AuthRoutes --> AuthService

    %% Service to Infrastructure Connections
    TaskService --> Master
    NodeService --> ServiceDiscovery
    PipelineService --> SchedulerService
    SchedulerService --> Worker
    NotificationSystem --> MessageSystem

    %% Infrastructure Connections
    Master --> ETCD
    Worker --> ETCD
    ServiceDiscovery --> ETCD

    %% Actuator Connections
    Worker --> HTTPActuator
    Worker --> ShellActuator
    Worker --> MailActuator
    Worker --> HookActuator

    %% Model Connections
    TaskService --> TaskModel
    NodeService --> NodeModel
    PipelineService --> PipelineModel
    AuthService --> UserModel

    %% Click Events
    click Master "https://github.com/betterde/ects/blob/master/cmd/master.go"
    click Worker "https://github.com/betterde/ects/blob/master/cmd/worker.go"
    click AuthService "https://github.com/betterde/ects/blob/master/controllers/auth/authentication.go"
    click PipelineService "https://github.com/betterde/ects/blob/master/controllers/pipeline/main.go"
    click TaskService "https://github.com/betterde/ects/blob/master/controllers/task/main.go"
    click NodeService "https://github.com/betterde/ects/blob/master/controllers/node/main.go"
    click SchedulerService "https://github.com/betterde/ects/blob/master/internal/scheduler/main.go"
    click NotificationSystem "https://github.com/betterde/ects/blob/master/internal/notify/main.go"
    click HTTPActuator "https://github.com/betterde/ects/blob/master/internal/actuator/http.go"
    click ShellActuator "https://github.com/betterde/ects/blob/master/internal/actuator/shell.go"
    click MailActuator "https://github.com/betterde/ects/blob/master/internal/actuator/mail.go"
    click HookActuator "https://github.com/betterde/ects/blob/master/internal/actuator/hook.go"
    click MessageSystem "https://github.com/betterde/ects/blob/master/internal/message/main.go"
    click ServiceDiscovery "https://github.com/betterde/ects/blob/master/internal/discover/main.go"
    click WebUI "https://github.com/betterde/ects/blob/master/web/src/App.vue"
    click APILayer "https://github.com/betterde/ects/tree/master/web/src/apis/modules/"
    click StateManagement "https://github.com/betterde/ects/tree/master/web/src/store/"
    click Router "https://github.com/betterde/ects/blob/master/web/src/router/index.js"
    click Views "https://github.com/betterde/ects/tree/master/web/src/views/"
    click TaskModel "https://github.com/betterde/ects/blob/master/models/task.go"
    click NodeModel "https://github.com/betterde/ects/blob/master/models/node.go"
    click PipelineModel "https://github.com/betterde/ects/blob/master/models/pipeline.go"
    click UserModel "https://github.com/betterde/ects/blob/master/models/user.go"
    click TaskRoutes "https://github.com/betterde/ects/blob/master/routes/task.go"
    click NodeRoutes "https://github.com/betterde/ects/blob/master/routes/node.go"
    click PipelineRoutes "https://github.com/betterde/ects/blob/master/routes/pipeline.go"
    click AuthRoutes "https://github.com/betterde/ects/blob/master/routes/auth.go"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef core fill:#f1c40f,stroke:#f39c12,color:black
    classDef db fill:#9b59b6,stroke:#8e44ad,color:white
    classDef actuator fill:#1abc9c,stroke:#16a085,color:white
    classDef model fill:#34495e,stroke:#2c3e50,color:white
```
