# ouqiang/gocron architecture

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

- Interactive diagram: https://gitdiagram.com/ouqiang/gocron
- Repository: https://github.com/ouqiang/gocron

## Overview

##### Main Components

a) Frontend Layer:
- Vue.js based web interface (located in /web/vue)
- Element UI components integration
- API communication layer

b) Backend Components:
- Main Server (gocron)
- Node Agents (gocron-node)
- Database (MySQL)
- RPC Communication Layer

c) Integration Services:
- Notification Systems (Email, Slack, Webhook)
- HTTP Client for external task execution

##### Architecture Representation

**[User Interface Layer]**

**[API/Router Layer]**

**[Service Layer]**

**[Data Layer]**

**[Node Communication]**

##### Component Details

a) UI Layer (Blue):
- Vue.js Frontend
- Element UI Components
- Web Router
- API Client

b) API/Router Layer (Green):
- HTTP Endpoints (/internal/routers)
- Authentication
- Task Management
- Host Management
- User Management

c) Service Layer (Yellow):
- Task Scheduler
- Task Executor
- Notification Service
- RPC Service

d) Data Layer (Purple):
- MySQL Database
- Models (Task, User, Host, etc.)

e) Node Communication (Orange):
- gRPC Protocol
- Node Pool Management
- Authentication/Certification

##### Connection Flows

- HTTP/API calls between frontend and backend
- gRPC communication between main server and nodes
- Database interactions
- External service calls (notifications)

##### Technical Details

Technologies:
- Macaron Web Framework
- XORM
- gRPC
- Cron Scheduler
- Vue.js + Element UI

##### Integration points

Keep the abstraction level high enough to be understandable but detailed enough to show the system's complexity and distributed nature. Focus on showing how the scheduler coordinates with nodes and how tasks are managed and executed across the system.

Remember to include the notification system's integration points and the security layer between components, as these are crucial aspects of the system's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI
        FE["Vue.js Frontend"]:::frontend
        COMP["UI Components"]:::frontend
        ROUTER["Web Router"]:::frontend
        APICLIENT["API Client"]:::frontend
    end

    subgraph API
        TASK_API["Task API"]:::api
        USER_API["User API"]:::api
        HOST_API["Host API"]:::api
        AUTH["Authentication"]:::security
    end

    subgraph Services
        TASK_SVC["Task Service"]:::service
        SCHEDULER["Task Scheduler"]:::service
        EXECUTOR["Task Executor"]:::service
        HTTP_CLIENT["HTTP Client"]:::service
    end

    subgraph Notification
        EMAIL["Email Service"]:::notify
        SLACK["Slack Service"]:::notify
        WEBHOOK["Webhook Service"]:::notify
    end

    subgraph RPC
        RPC_SERVER["RPC Server"]:::rpc
        RPC_CLIENT["RPC Client"]:::rpc
        RPC_PROTO["RPC Protocol"]:::rpc
        RPC_AUTH["RPC Authentication"]:::security
    end

    subgraph Data
        DB[(MySQL Database)]:::database
        TASK_MODEL["Task Model"]:::model
        USER_MODEL["User Model"]:::model
        HOST_MODEL["Host Model"]:::model
        LOG_MODEL["Task Log Model"]:::model
    end

    subgraph Node
        NODE_AGENT["Node Agent"]:::node
    end

    %% Connections
    FE --> COMP
    FE --> ROUTER
    FE --> APICLIENT
    APICLIENT --> TASK_API
    APICLIENT --> USER_API
    APICLIENT --> HOST_API

    TASK_API --> AUTH
    USER_API --> AUTH
    HOST_API --> AUTH

    TASK_API --> TASK_SVC
    TASK_SVC --> SCHEDULER
    SCHEDULER --> EXECUTOR
    EXECUTOR --> HTTP_CLIENT

    TASK_SVC --> EMAIL
    TASK_SVC --> SLACK
    TASK_SVC --> WEBHOOK

    TASK_SVC --> RPC_SERVER
    RPC_SERVER --> RPC_AUTH
    RPC_SERVER --> RPC_PROTO
    RPC_CLIENT --> RPC_PROTO
    RPC_AUTH --> NODE_AGENT
    RPC_CLIENT --> NODE_AGENT

    TASK_SVC --> TASK_MODEL
    TASK_MODEL --> DB
    USER_MODEL --> DB
    HOST_MODEL --> DB
    LOG_MODEL --> DB

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef api fill:#4CAF50,color:white
    classDef service fill:#FFC107,color:black
    classDef notify fill:#9C27B0,color:white
    classDef rpc fill:#FF5722,color:white
    classDef database fill:#607D8B,color:white
    classDef model fill:#795548,color:white
    classDef security fill:#F44336,color:white
    classDef node fill:#009688,color:white

    %% Click events
    click FE "https://github.com/ouqiang/gocron/tree/master/web/vue"
    click APICLIENT "https://github.com/ouqiang/gocron/tree/master/web/vue/src/api"
    click COMP "https://github.com/ouqiang/gocron/tree/master/web/vue/src/components"
    click ROUTER "https://github.com/ouqiang/gocron/blob/master/web/vue/src/router/index.js"
    click NODE_AGENT "https://github.com/ouqiang/gocron/blob/master/cmd/node/node.go"
    click RPC_SERVER "https://github.com/ouqiang/gocron/blob/master/internal/modules/rpc/server/server.go"
    click RPC_CLIENT "https://github.com/ouqiang/gocron/blob/master/internal/modules/rpc/client/client.go"
    click RPC_PROTO "https://github.com/ouqiang/gocron/blob/master/internal/modules/rpc/proto/task.proto"
    click EMAIL "https://github.com/ouqiang/gocron/blob/master/internal/modules/notify/mail.go"
    click SLACK "https://github.com/ouqiang/gocron/blob/master/internal/modules/notify/slack.go"
    click WEBHOOK "https://github.com/ouqiang/gocron/blob/master/internal/modules/notify/webhook.go"
    click TASK_MODEL "https://github.com/ouqiang/gocron/blob/master/internal/models/task.go"
    click USER_MODEL "https://github.com/ouqiang/gocron/blob/master/internal/models/user.go"
    click HOST_MODEL "https://github.com/ouqiang/gocron/blob/master/internal/models/host.go"
    click LOG_MODEL "https://github.com/ouqiang/gocron/blob/master/internal/models/task_log.go"
    click TASK_API "https://github.com/ouqiang/gocron/blob/master/internal/routers/task/task.go"
    click USER_API "https://github.com/ouqiang/gocron/blob/master/internal/routers/user/user.go"
    click HOST_API "https://github.com/ouqiang/gocron/blob/master/internal/routers/host/host.go"
    click TASK_SVC "https://github.com/ouqiang/gocron/blob/master/internal/service/task.go"
    click RPC_AUTH "https://github.com/ouqiang/gocron/blob/master/internal/modules/rpc/auth/Certification.go"
    click HTTP_CLIENT "https://github.com/ouqiang/gocron/blob/master/internal/modules/httpclient/http_client.go"
```
