How erdemozgen/blackdagger works
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