# bhooyas/enigma architecture

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

- Interactive diagram: https://gitdiagram.com/bhooyas/enigma
- Repository: https://github.com/bhooyas/enigma

## Overview

##### Project Type and Purpose
- This is a Python-based implementation of the historic Enigma cipher machine.
- It provides:
- A core Enigma engine (rotors, reflector, plugboard) in `enigma.py`, `rotor.py`, `reflector.py`, `plugboard.py`.
- A command-line interface (`main.py`) for offline encryption/decryption.
- A Flask-powered HTTP API (`app.py`) with minimal frontend (`templates/` + `static/`).
- Containerization via `Dockerfile` for easy deployment.

##### File Structure Analysis
Top-level:
- Configuration: `.gitignore`, `.dockerignore`, GitHub Actions, `Dockerfile`.
- Core logic modules: `enigma.py`, `rotor.py`, `reflector.py`, `plugboard.py`.
- Entry points:
– `main.py` (CLI, uses `argparse`).
– `app.py` (Flask app exposing REST endpoints).
- Web UI:
– `templates/` (`index.html`, `cipher.html`).
– `static/` (CSS/JS assets if any).
There is no database or external persistence—everything is in-memory.

a. Main components:
1. Client Layer:
– Web Browser (User UI)
– CLI (Terminal)
2. Server Layer:
– Flask App (`app.py`)
3. Core Engine:
– Enigma class (`enigma.py`)
– Rotor module (`rotor.py`)
– Reflector module (`reflector.py`)
– Plugboard module (`plugboard.py`)
4. Infrastructure:
– Docker Container
– CI/CD (GitHub Actions) (optional, for deploy pipeline)
b. Relationships / Data Flow:
- Web Browser → HTTP request → Flask App → Enigma Engine → HTTP response → Browser
- Terminal → CLI (`main.py`) → Enigma Engine → Console output
- Flask App & CLI both depend on the same core engine modules.
- Docker container wraps the Flask App (and its dependencies) for deployment.
c. Architectural Patterns & Principles:
– Single-responsibility: each module handles one aspect of the cipher (rotor, plugboard, reflector).
– Layered separation: UI ↔ API ↔ Core Logic.
– Stateless design: no persistence layer; each request is independent.
– Containerized deployment: infrastructure as code.
d. Key Technologies:
– Python 3
– Flask (HTTP API + templating)
– Argparse (CLI)
– Docker
– GitHub Actions (CI for image build & tests)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User-facing layer
    Browser["Web Browser (UI)"]:::user
    CLI["CLI Client (Terminal UI)"]:::user

    %% Application layer
    subgraph "Application Layer"
        API["Flask API Server (app.py)"]:::app
        subgraph "Enigma Engine" 
            direction TB
            EnigmaCore["Enigma (enigma.py)"]:::core
            Rotor["Rotor (rotor.py)"]:::core
            Reflector["Reflector (reflector.py)"]:::core
            Plugboard["Plugboard (plugboard.py)"]:::core
        end
    end

    %% Infrastructure layer
    subgraph "Infrastructure"
        DockerDef["Docker Definition"]:::infra
        CI["GitHub Actions CI"]:::infra
        Container["Docker Container"]:::infra
    end

    %% Configuration & Docs
    subgraph "Repository Config & Docs"
        Gitignore[".gitignore"]:::infra
        Readme["README.md"]:::infra
    end

    %% Web UI Resources
    subgraph "Web UI Templates & Static"
        IndexHTML["Index Page (templates/index.html)"]:::app
        CipherHTML["Cipher Page (templates/cipher.html)"]:::app
        StaticAssets["Static Assets (static/)"]:::app
    end

    %% Data flows
    Browser -->|POST /encrypt| API
    API -->|"calls encrypt()"| EnigmaCore
    EnigmaCore -->|uses Rotor, Reflector, Plugboard| Rotor
    EnigmaCore --> Reflector
    EnigmaCore --> Plugboard
    EnigmaCore -->|"returns result"| API
    API -->|HTTP Response| Browser

    CLI -->|"encrypt() call"| EnigmaCore
    EnigmaCore -->|result| CLI

    CI -->|build image| DockerDef
    DockerDef -->|"docker build"| Container
    Container -->|"hosts Flask App"| API

    API -->|serves UI| IndexHTML
    API --> IndexHTML
    API --> CipherHTML
    API --> StaticAssets

    %% Click events
    click EnigmaCore "https://github.com/bhooyas/enigma/blob/main/enigma.py"
    click Rotor "https://github.com/bhooyas/enigma/blob/main/rotor.py"
    click Reflector "https://github.com/bhooyas/enigma/blob/main/reflector.py"
    click Plugboard "https://github.com/bhooyas/enigma/blob/main/plugboard.py"
    click CLI "https://github.com/bhooyas/enigma/blob/main/main.py"
    click API "https://github.com/bhooyas/enigma/blob/main/app.py"
    click IndexHTML "https://github.com/bhooyas/enigma/blob/main/templates/index.html"
    click CipherHTML "https://github.com/bhooyas/enigma/blob/main/templates/cipher.html"
    click StaticAssets "https://github.com/bhooyas/enigma/tree/main/static/"
    click DockerDef "https://github.com/bhooyas/enigma/tree/main/Dockerfile"
    click DockerDef "https://github.com/bhooyas/enigma/blob/main/.dockerignore"
    click CI "https://github.com/bhooyas/enigma/blob/main/.github/workflows/docker-image-builder.yaml"
    click Gitignore "https://github.com/bhooyas/enigma/blob/main/.gitignore"
    click Readme "https://github.com/bhooyas/enigma/blob/main/README.md"

    %% Styles
    classDef user fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef app fill:#90EE90,stroke:#000,stroke-width:1px
    classDef core fill:#98FB98,stroke:#000,stroke-width:1px
    classDef infra fill:#FFA500,stroke:#000,stroke-width:1px
```
