# erdemozgen/blackdagger architecture

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

- Interactive diagram: https://gitdiagram.com/erdemozgen/blackdagger
- Repository: https://github.com/erdemozgen/blackdagger

## Overview

##### Project Type and Purpose
- Blackdagger is a full-stack, self-contained workflow-automation framework written in Go with a React/TypeScript web UI.
- It provides both a CLI (“blackdagger” commands) and a Web UI for defining, scheduling, executing, and monitoring DAG-based automation pipelines via YAML.
- Key use cases: DevOps/DevSecOps/MLOps pipelines, continuous automated red-teaming, batch jobs, reporting, external-service orchestration.

##### High-Level Architecture Overview
A. User Interfaces
- CLI Component (“blackdagger” binary) – interacts with the backend over HTTP REST.
- Web UI (React/TypeScript, served as static assets) – issues API calls to the server and shows real-time updates.
B. Backend Services (Go processes)
- REST API Server
– Serves HTTP endpoints (generated via Swagger in internal/frontend/gen) for listing DAGs, starting/stopping/retrying, fetching logs/status.
– Hosts the Web UI assets.
– Handles authentication (basic and token) via middleware.
– Writes/reads run metadata to/from persistence.
- Scheduler
– Watches the DAG directory (via fsnotify/file polling), parses YAML definitions, evaluates Cron schedules.
– Enqueues scheduled DAG runs into the persistence layer or directly invokes the executor.
- Agent/Executor
– Reads execution requests (from scheduler or server), iterates DAG steps, and dispatches them to pluggable executors (Docker, HTTP, SSH, jq, mail, custom code).
– Reports step-level status, logs, and outputs back to persistence.
C. Persistence Layer
- Abstract store interface with multiple implementations: JSONDB, filecache, local file storage, grep-based lookup.
- Persists DAG definitions, run history, step logs, status details, request IDs.
D. External Systems
- Docker Engine (for container tasks)
- SSH endpoints, HTTP services, SMTP servers, external APIs
- Cron scheduler (embedded in the Scheduler component)

##### Component Relationships and Data Flow
- Users → CLI or Web UI → HTTP REST API → Server
- Server ↔ Persistence (read/write DAG definitions, run metadata)
- Scheduler ↔ Persistence (polls scheduled run requests or writes new runs)
- Scheduler → Agent/Executor (invokes run jobs, passing step definitions)
- Agent → Persistence (writes step status, logs, outputs)
- Web UI polls or subscribes (via sock package/websocket) to Server for live updates

##### Architectural Patterns and Design Principles
- Modular monolith with clear separation of concerns: CLI, API surface, scheduler, executor, persistence.
- Plug-in executor pattern: each task type implements an Executor interface.
- Declarative configuration (YAML) driving a DAG builder/parser → scheduler → executor pipeline.
- Code generation for API (Swagger) ensures consistency between handlers and models.
- Clean layering: internal packages (agent, client, dag, persistence, scheduler, frontend) communicate via well-defined interfaces.

##### Technologies and Frameworks to Call Out
- Go modules for core (cmd/, internal/, main.go)
- go-swagger / Swagger UI (api.v1.yaml, internal/frontend/gen)
- React + TypeScript + Webpack + Babel for the UI (ui/src/)
- fsnotify / file polling for directory watching
- Cron parser for schedule expressions
- net/http, Gorilla mux for REST
- net/smtp for email executor
- golang.org/x/crypto/ssh for SSH executor
- Docker client API for Docker executor

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "User Interfaces"
    CLI["CLI (blackdagger)"]:::ui
    WebUI["Web UI (React/TS)"]:::ui
  end

  subgraph "Backend Services"
    subgraph "REST API Server"
      Api["API Server"]:::backend
      Swagger["Swagger API (api.v1.yaml)"]:::backend
      ApiGenModels["Gen Models"]:::backend
      ApiGenServer["Gen REST API"]:::backend
      ServerEntry["Server Entry"]:::backend
      ServerRoutes["Routes"]:::backend
      BasicAuth["Basic Auth"]:::backend
      TokenAuth["Token Auth"]:::backend
      LoggingMW["Logging"]:::backend
    end
    subgraph "Scheduler Components"
      Scheduler["Scheduler"]:::backend
      SchEntry["Scheduler Entry"]:::backend
      SchLogic["Core Scheduler"]:::backend
      FileNotify["File Watcher"]:::backend
      EntryReader["Entry Reader"]:::backend
      JobDef["Job Definition"]:::backend
    end
    subgraph "Agent Components"
      Agent["Agent/Executor"]:::backend
      AgentProc["Agent Process"]:::backend
      Reporter["Reporter"]:::backend
      ExecutorDir["Executors"]:::backend
    end
  end

  subgraph "Persistence Layer"
    JSONDB["JSONDB"]:::storage
    FileCache["FileCache"]:::storage
    GrepStore["Grep Store"]:::storage
    LocalStore["Local Storage"]:::storage
  end

  subgraph "External Systems"
    Docker["Docker Engine"]:::ext
    SSH["SSH Endpoints"]:::ext
    HTTPServ["HTTP Services"]:::ext
    SMTP["SMTP Servers"]:::ext
  end

  CLI -->|HTTP/REST| Api
  WebUI -->|HTTP/REST| Api
  Api -->|uses spec| Swagger
  Swagger --> ApiGenModels
  Swagger --> ApiGenServer
  ApiGenModels --> Api
  ApiGenServer --> Api
  Api --> ServerEntry
  Api --> ServerRoutes
  Api --> BasicAuth
  Api --> TokenAuth
  Api --> LoggingMW

  Api -->|read/write| JSONDB
  Scheduler -->|Persistence read/write| JSONDB
  Scheduler -->|invoke| Agent
  Agent -->|write status/logs| JSONDB
  WebUI -->|Websocket| Api

  Agent -->|exec containers| Docker
  Agent -->|exec SSH| SSH
  Agent -->|exec HTTP| HTTPServ
  Agent -->|exec email| SMTP

  classDef ui fill:#D0E6FF,stroke:#3B82F6;
  classDef backend fill:#D1FAE5,stroke:#10B981;
  classDef storage fill:#FEF3C7,stroke:#F59E0B;
  classDef ext fill:#E5E7EB,stroke:#6B7280;

  click CLI "https://github.com/erdemozgen/blackdagger/blob/main/cmd/root.go"
  click WebUI "https://github.com/erdemozgen/blackdagger/tree/main/ui/src/"
  click WebUI "https://github.com/erdemozgen/blackdagger/blob/main/ui/public/index.html"
  click Api "https://github.com/erdemozgen/blackdagger/blob/main/cmd/server.go"
  click ServerEntry "https://github.com/erdemozgen/blackdagger/blob/main/cmd/server.go"
  click ServerRoutes "https://github.com/erdemozgen/blackdagger/blob/main/internal/frontend/server/routes.go"
  click BasicAuth "https://github.com/erdemozgen/blackdagger/blob/main/internal/frontend/middleware/basic_auth.go"
  click TokenAuth "https://github.com/erdemozgen/blackdagger/blob/main/internal/frontend/middleware/token_auth.go"
  click LoggingMW "https://github.com/erdemozgen/blackdagger/blob/main/internal/frontend/middleware/logging.go"
  click Swagger "https://github.com/erdemozgen/blackdagger/blob/main/api.v1.yaml"
  click ApiGenModels "https://github.com/erdemozgen/blackdagger/tree/main/internal/frontend/gen/models/"
  click ApiGenServer "https://github.com/erdemozgen/blackdagger/tree/main/internal/frontend/gen/restapi/"
  click Scheduler "https://github.com/erdemozgen/blackdagger/blob/main/cmd/scheduler.go"
  click SchEntry "https://github.com/erdemozgen/blackdagger/blob/main/cmd/scheduler.go"
  click SchLogic "https://github.com/erdemozgen/blackdagger/blob/main/internal/scheduler/scheduler.go"
  click FileNotify "https://github.com/erdemozgen/blackdagger/tree/main/internal/scheduler/filenotify/"
  click EntryReader "https://github.com/erdemozgen/blackdagger/blob/main/internal/scheduler/entryreader.go"
  click JobDef "https://github.com/erdemozgen/blackdagger/blob/main/internal/scheduler/job.go"
  click AgentProc "https://github.com/erdemozgen/blackdagger/blob/main/internal/agent/agent.go"
  click Reporter "https://github.com/erdemozgen/blackdagger/blob/main/internal/agent/reporter.go"
  click ExecutorDir "https://github.com/erdemozgen/blackdagger/tree/main/internal/dag/executor/"
  click JSONDB "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/jsondb/jsondb.go"
  click FileCache "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/filecache/filecache.go"
  click GrepStore "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/grep/grep.go"
  click LocalStore "https://github.com/erdemozgen/blackdagger/tree/main/internal/persistence/local/"
  click FileCache "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/filecache/filecache.go"
  click Reporter "https://github.com/erdemozgen/blackdagger/blob/main/internal/agent/reporter.go"
  click Parser "https://github.com/erdemozgen/blackdagger/blob/main/internal/dag/parser.go"
  click Loader "https://github.com/erdemozgen/blackdagger/blob/main/internal/dag/loader.go"
  click Builder "https://github.com/erdemozgen/blackdagger/blob/main/internal/dag/builder.go"
  click DAGStruct "https://github.com/erdemozgen/blackdagger/blob/main/internal/dag/dag.go"
  click DAGSched "https://github.com/erdemozgen/blackdagger/tree/main/internal/dag/scheduler/"
  click StoreInterface "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/interface.go"
  click StoreFactory "https://github.com/erdemozgen/blackdagger/blob/main/internal/persistence/client/store_factory.go"
  click Logger "https://github.com/erdemozgen/blackdagger/blob/main/internal/logger/logger.go"
  click FileLogger "https://github.com/erdemozgen/blackdagger/blob/main/internal/logger/file.go"
  click SockServer "https://github.com/erdemozgen/blackdagger/blob/main/internal/sock/server.go"
  click SockClient "https://github.com/erdemozgen/blackdagger/blob/main/internal/sock/client.go"
  click ConfigResolver "https://github.com/erdemozgen/blackdagger/blob/main/internal/config/config.go"
  click ConfigResolver2 "https://github.com/erdemozgen/blackdagger/blob/main/internal/config/resolver.go"
  click ProviderConfig "https://github.com/erdemozgen/blackdagger/blob/main/provider-config.yaml"
  click Main "https://github.com/erdemozgen/blackdagger/blob/main/main.go"
```
