# semaphoreui/semaphore architecture

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

- Interactive diagram: https://gitdiagram.com/semaphoreui/semaphore
- Repository: https://github.com/semaphoreui/semaphore

## Overview

##### Main Components
- Frontend: Located in the “web” directory, this is a Vue.js–based web application with its source files (App.vue, components, views, assets, etc.), configurations, and tests.
- Backend/API: Found in the “api” directory, this is the core server-side functionality (routing, authentication, tasks, projects, integrations, etc.) written in Go.
- CLI: The “cli” directory shows command-line functionalities for management tasks (migrations, runner setup, server start, user management, etc.).
- Database Layer: The “db” and “db_lib” directories illustrate two approaches (Bolt and SQL) for database/storage integration including migrations and data access for tokens, tasks, projects, users, etc.
- Services: The “services” directory contains subdirectories for projects, runners, schedules, and tasks, indicating additional business logic and orchestration layers (e.g., job pools, scheduler, task runners).
- Supporting Utilities and Libraries: Under “pkg”, “util”, and hook stubs (as seen in .dredd and hook_helpers) there are reusable libraries for SSH, randomness, error logging, and mailing.
- Deployment & Containerization: The “deployment” directory (with Docker compose, Dockerfiles, systemd service files, etc.) sets up how the application is packaged and deployed in different environments.
- Testing and CI/CD: Multiple files and directories (like tests in “web/tests”, .github/workflows configurations, Codacy, and goreleaser files) reveal support for automated testing/delivery.

##### Relationships & Interactions
- The Frontend interacts with the Backend via HTTP/REST APIs (and potentially websockets as indicated in “api/sockets” and “web/src/socket.js”).
- The Backend communicates with the Database layer abstracted by “db” (both Bolt and SQL implementations) for data persistence.
- The CLI provides alternative access to the same core functionalities as the API, likely interacting with the database or invoking API endpoints.
- The “services” layer encapsulates logic for project management, runner jobs, scheduling, and task execution – interactions that the API relies upon.
- Deployment orchestration is achieved via Docker, Docker Compose, and potentially systemd, setting up independent containers or processes for the backend server, runner components, and storage.
- External integrations or hooks (see “.dredd/hooks” and “hook_helpers”) enable custom capabilities and event handling within the system.

##### Architectural Patterns & Design Principles
- The project appears to follow a separation-of-concerns model by splitting the UI from backend logic.
- Microservice or modular patterns are used, with directories for “cli”, “services”, and “api” suggesting loosely coupled components.
- There is a clear domain-driven design around key concepts (Projects, Tasks, Schedules, Inventory, etc.) representing user workflows.
- The use of multiple deployment configurations (Docker Compose, systemd, etc.) indicates an emphasis on adaptability to different environments.

##### Relevant Technologies
- Programming Language: Go (back end) and Vue.js (front end).
- Database: Options for Bolt and SQL.
- Containerization & Deployment: Docker, Docker Compose, systemd.
- Additional Tools: Dredd for API testing, various CI/CD configurations from GitHub Actions, and code quality settings (Codacy).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend"
        FE["Web Frontend (Vue.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend API (Go)"]:::backend
        SVC["Services (Task,Runner,Schedule,Projects)"]:::services
        UTIL["Supporting Utilities & Libraries"]:::utilities
    end

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Tool"]:::cli
    end

    %% Database Layer (Bolt & SQL)
    subgraph "Database Layer (Bolt & SQL)"
        BOLT["Bolt DB"]:::database
        SQL["SQL DB"]:::database
        MIG["Migrations"]:::database
    end

    %% Deployment & Testing Layer
    subgraph "Deployment & CI/CD"
        DEPLOY["Deployment Artifacts"]:::deployment
        TEST["Testing & CI/CD"]:::testing
    end

    %% Relationships
    FE -->|"HTTP/REST&WebSockets"| BE
    BE -->|"PersistentStorageAccess"| BOLT
    BE -->|"PersistentStorageAccess"| SQL
    BE -->|"CallsServices"| SVC
    CLI -->|"ManagementCommands"| BE
    CLI -->|"DirectDBAccess"| BOLT
    CLI -->|"DirectDBAccess"| SQL
    BE -->|"Utilizes"| UTIL
    DEPLOY --> FE
    DEPLOY --> BE
    DEPLOY --> CLI
    TEST --> FE
    TEST --> BE
    TEST --> CLI

    %% Click Events
    click FE "https://github.com/semaphoreui/semaphore/tree/develop/web"
    click BE "https://github.com/semaphoreui/semaphore/tree/develop/api"
    click CLI "https://github.com/semaphoreui/semaphore/tree/develop/cli"
    click BOLT "https://github.com/semaphoreui/semaphore/tree/develop/db"
    click SQL "https://github.com/semaphoreui/semaphore/tree/develop/db_lib"
    click MIG "https://github.com/semaphoreui/semaphore/tree/develop/db/sql/migrations"
    click SVC "https://github.com/semaphoreui/semaphore/tree/develop/services"
    click UTIL "https://github.com/semaphoreui/semaphore/tree/develop/pkg"
    click UTIL "https://github.com/semaphoreui/semaphore/tree/develop/util"
    click UTIL "https://github.com/semaphoreui/semaphore/tree/develop/.dredd/hooks"
    click UTIL "https://github.com/semaphoreui/semaphore/tree/develop/hook_helpers"
    click DEPLOY "https://github.com/semaphoreui/semaphore/tree/develop/deployment"
    click TEST "https://github.com/semaphoreui/semaphore/tree/develop/web/tests"
    click TEST "https://github.com/semaphoreui/semaphore/tree/develop/.github/workflows"

    %% Styles
    classDef frontend fill:#FEE,stroke:#333,stroke-width:2px;
    classDef backend fill:#EEF,stroke:#333,stroke-width:2px;
    classDef cli fill:#EFE,stroke:#333,stroke-width:2px;
    classDef database fill:#FFE,stroke:#333,stroke-width:2px;
    classDef services fill:#EFF,stroke:#333,stroke-width:2px;
    classDef utilities fill:#EFD,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FED,stroke:#333,stroke-width:2px;
    classDef testing fill:#DFE,stroke:#333,stroke-width:2px;
```
