# rmdc-crafty/crafty architecture

> Architecture diagram of the GitHub repository rmdc-crafty/crafty, 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/rmdc-crafty/crafty
- Repository: https://github.com/rmdc-crafty/crafty

## Overview

##### Project Type and Purpose
- Crafty Controller is essentially a full-stack application with a Python back-end (powered by Tornado) that both launches and controls a Minecraft server and serves a dynamic web interface.
- Its purpose is to offer a secure web portal for administrating, monitoring, and operating a Minecraft server, including features such as backups, remote commands, FTP operations, and other server management utilities.

##### File Structure
- The “app” directory is the heart of the application. It is organized into several key subdirectories:
– “app/classes” contains modules for different functionalities (e.g., api.py, backupmgr.py, minecraft_server.py, remote_coms.py) and handlers (under app/classes/handlers) that process web requests.
– “app/web” holds the front-end components such as static files (CSS, JavaScript, images), templates (HTML for admin, public, setup, etc.), and translations.
– “app/config” stores JSON files for logging and version information.
- Additional directories like “configs” and Docker-related directories indicate that deployment and configuration management are important aspects.
- There’s also a “docker-compose.yml” along with Dockerfiles and related Docker directories, suggesting containerized deployment support.

##### Key Architectural Components
a. Frontend (Web Interface):
– Includes static assets in “app/web/static” (CSS, JS, vendors) and templates in “app/web/templates” (admin, ajax, public, setup).
– Provides a graphical UI for server administration.
b. Backend (Server and API Layer):
– Utilizes Tornado (as specified in the README) to run a web server handling both RESTful API endpoints (defined in modules like api.py and routed via handler classes) and serving the web interface.
– Contains specialized classes for tasks such as backups (backupmgr.py), FTP operations (ftp.py), running the Minecraft server (minecraft_server.py), and remote communications (remote_coms.py).
c. Database/Configuration:
– Uses an SQLite database (as mentioned in the README) to store settings and user information, with configuration files under “app/config”.
d. External Components & Deployment:
– Docker-related files indicate the use of containerization for deployment.
– The README also mentions external libraries like Argon2 for password hashing and AdminLTE and Font Awesome for UI styling.

##### Relationships and Interactions
- The user interacts with the system via a browser that loads static assets and templates from the “web” directory.
- The front-end makes HTTP requests to the Tornado server running in the back-end.
- The Tornado back-end routes these requests to the appropriate handler classes in “app/classes/handlers”, which then call various business logic services (e.g., server control, backup management).
- The backend communicates with the SQLite database for storage/retrieval of configuration and state.
- Docker and docker-compose configuration encapsulate these components for deployment.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear segmentation between presentation (web/templates) and business logic (modules in app/classes).
- Modular Design: Each significant functionality (e.g., FTP management, backup, remote communication) is handled by separate modules.
- Containerized Deployment: The Docker files and docker-compose configuration indicate a modern approach to environment isolation and streamlined deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["User Browser"]:::frontend
        WebInterface["Web Interface (app/web)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Tornado["Tornado Web Server"]:::backend
        BackendEntry["Backend Entry (crafty.py)"]:::backend
        BackendModules["Backend Modules (app/classes)"]:::backend
        Tornado --> BackendEntry
        Tornado --> BackendModules
    end

    %% Backend Services
    subgraph "Service Modules"
        direction TB
        MinecraftLauncher["Minecraft Server Launcher (app/classes/minecraft_server.py)"]:::backend
        MinecraftResources["Minecraft Server Resources (app/minecraft)"]:::backend
        BackupManager["Backup Manager (app/classes/backupmgr.py)"]:::backend
        FTPModule["FTP Module (app/classes/ftp.py)"]:::backend
        RemoteComm["Remote Communications (app/classes/remote_coms.py)"]:::backend
        
        %% Relationship between Minecraft launcher and its resources
        MinecraftLauncher --> MinecraftResources
    end

    %% Configuration/Database
    subgraph "Configuration & Database"
        direction TB
        ConfigFiles["Config Files (app/config)"]:::infra
        AdditionalConfigs["Additional Configs (configs)"]:::infra
    end

    %% Deployment Layer
    subgraph "Containerized Deployment"
        direction TB
        Dockerfile["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
        DockerDir["Docker Directory"]:::infra
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        ExternalLibs["Argon2, AdminLTE, Font Awesome"]:::external
    end

    %% Connections between layers
    Browser -->|"loads"| WebInterface
    Browser -->|"HTTP Request"| Tornado
    WebInterface -->|"Static Content"| Tornado
    Tornado -->|"Routes requests"| BackendModules
    BackendModules -->|"Calls service"| MinecraftLauncher
    BackendModules -->|"Calls service"| BackupManager
    BackendModules -->|"Calls service"| FTPModule
    BackendModules -->|"Calls service"| RemoteComm

    %% Database interactions
    BackendModules -->|"uses"| ConfigFiles
    BackendModules -->|"uses"| AdditionalConfigs

    %% External dependencies usage
    Tornado -->|"utilizes"| ExternalLibs

    %% Deployment relationship
    Dockerfile --- DockerCompose
    DockerCompose --- DockerDir
    DockerDir --- Tornado

    %% Click Events
    click WebInterface "https://github.com/rmdc-crafty/crafty/tree/master/app/web"
    click BackendEntry "https://github.com/rmdc-crafty/crafty/blob/master/crafty.py"
    click BackendModules "https://github.com/rmdc-crafty/crafty/tree/master/app/classes"
    click MinecraftLauncher "https://github.com/rmdc-crafty/crafty/blob/master/app/classes/minecraft_server.py"
    click MinecraftResources "https://github.com/rmdc-crafty/crafty/tree/master/app/minecraft"
    click BackupManager "https://github.com/rmdc-crafty/crafty/blob/master/app/classes/backupmgr.py"
    click FTPModule "https://github.com/rmdc-crafty/crafty/blob/master/app/classes/ftp.py"
    click RemoteComm "https://github.com/rmdc-crafty/crafty/blob/master/app/classes/remote_coms.py"
    click ConfigFiles "https://github.com/rmdc-crafty/crafty/tree/master/app/config"
    click AdditionalConfigs "https://github.com/rmdc-crafty/crafty/tree/master/configs"
    click Dockerfile "https://github.com/rmdc-crafty/crafty/tree/master/Dockerfile"
    click DockerCompose "https://github.com/rmdc-crafty/crafty/blob/master/docker-compose.yml"
    click DockerDir "https://github.com/rmdc-crafty/crafty/tree/master/docker"

    %% Styles
    classDef frontend fill:#ffd1dc,stroke:#c2185b,stroke-width:2px;
    classDef backend fill:#bbdefb,stroke:#1976d2,stroke-width:2px;
    classDef infra fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef external fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
```
