# destructivevoice/destructivefarm architecture

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

- Interactive diagram: https://gitdiagram.com/destructivevoice/destructivefarm
- Repository: https://github.com/destructivevoice/destructivefarm

## Overview

##### Main Components
a. Exploit Scripts: Represented by sample scripts such as client/spl_example.py. They are written by participants and are “plugged into” the client.
b. Farm Client: The client (client/start_sploit.py) acts as the local runner. It periodically executes exploits, collects their results (flags), and forwards these to the farm server.
c. Farm Server: Located in the server directory, this is the central hub. It contains:
- API endpoints (server/api.py) – the interface that accepts flags from farm clients.
- Authentication and configuration (server/auth.py and server/config.py).
- Database integration (server/database.py, schema.sql, and models.py) to store flags and track statistics.
- Protocol adapters (inside server/protocols, e.g., forcad_tcp.py, ructf_http.py, etc.) that likely handle communication with external systems (like the checksystem).
- A web interface using Flask (templates and static assets) which shows the flags stats (with assets in server/static/css, server/static/js, and server/templates).

##### Relationships and Data Flow
- Internally within the Farm Server, show the interaction between:
- The API and authentication modules (ensuring secure flag submissions).
- The database (via models/database files) where the flag persistence and statistics are stored.
- The protocol modules which process and format data before sending out to the Checksystem.
- How static assets and templates form the web interface for administrative viewing.
- A label showing that exploits (written separately by participants) are used as plug-ins that get executed by the client.

##### Architectural Patterns and Key Design Principles
- The design follows a clear separation of concerns:
- The client and server roles are distinct. The client is responsible for running user-created exploits, while the server handles aggregation, processing, and interfacing with other systems.
- Inside the server, the separation is visible between API logic, authentication, data modeling, and protocol handling.
- Recognize it as a full-stack-like design (for the server) but with distributed external interactions (client to server to checksystem).

##### Technologies and Frameworks
- Python is the main language.
- Flask is used for the web service.
- Likely a relational database (given the presence of schema.sql and database modules).
- The protocol modules indicate custom implementations for interacting with various CTF protocols or checksystems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Exploit Scripts"]:::exploit
    B["Farm Client"]:::client
    FS["Farm Server"]:::server
    D["External Checksystem"]:::external

    A -->|"runs"| B
    B -->|"sendsFlagsTo"| FS

    subgraph "Server Internals"
        API["API Endpoints & Auth"]:::apiAuth
        DB["Database Integration"]:::database
        PM["Protocol Modules"]:::protocol
        WI["Web Interface"]:::web
    end

    FS -->|"processes"| API
    API -->|"storesFlagsIn"| DB
    API -->|"formatsFlagsFor"| PM
    API -->|"displaysStatsOn"| WI
    PM -->|"forwardsFlagsTo"| D

    %% Click Events
    click A "https://github.com/destructivevoice/destructivefarm/blob/master/client/spl_example.py"
    click B "https://github.com/destructivevoice/destructivefarm/blob/master/client/start_sploit.py"
    click FS "https://github.com/destructivevoice/destructivefarm/tree/master/server/"
    click API "https://github.com/destructivevoice/destructivefarm/blob/master/server/api.py"
    click API "https://github.com/destructivevoice/destructivefarm/blob/master/server/auth.py"
    click API "https://github.com/destructivevoice/destructivefarm/blob/master/server/config.py"
    click DB "https://github.com/destructivevoice/destructivefarm/blob/master/server/database.py"
    click DB "https://github.com/destructivevoice/destructivefarm/blob/master/server/models.py"
    click DB "https://github.com/destructivevoice/destructivefarm/blob/master/server/schema.sql"
    click PM "https://github.com/destructivevoice/destructivefarm/tree/master/server/protocols/"
    click WI "https://github.com/destructivevoice/destructivefarm/tree/master/server/static/"
    click WI "https://github.com/destructivevoice/destructivefarm/blob/master/server/templates/index.html"

    %% Styles
    classDef exploit fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef client fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef server fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef apiAuth fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef protocol fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef web fill:#A3E4D7,stroke:#333,stroke-width:2px;
    classDef external fill:#E5E7E9,stroke:#333,stroke-width:2px;
```
