# hasiotis/netsplit architecture

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

- Interactive diagram: https://gitdiagram.com/hasiotis/netsplit
- Repository: https://github.com/hasiotis/netsplit

## Overview

##### Main Components
- Command Line Interface (CLI) Layer:
– Represented by the “netsplit/cli.py” file.
– This is the entry point that handles user input (via command line arguments) and delegates tasks.
- Core Logic / Subnet Planning Engine:
– Although the core logic is implicit in the module (likely within “netsplit/__init__.py” and possibly other internal functions called from cli.py), this part processes the network plan, computes subnets and reserved IP space.
– Processes configuration data (from TOML files provided as “plan” files in the examples and tests directories).
- Configuration and Parsing Component:
– Responsible for reading and parsing TOML files (examples, tests/plans). This could either be directly integrated within the core logic or be a distinct sub-module.
- Testing Suite:
– Represented by the “tests” directory and its subdirectories. This component is critical for validating the subnet computations and core logic.
- Auxiliary/Supporting Components:
– Build and deployment configurations (e.g., Makefile, GitHub workflows in “.github/”) and the configuration management (pyproject.toml, setup.cfg). Although these are not “runtime” components, they are important from a life-cycle and maintenance perspective.

##### Relationships and Interactions
- The CLI component receives the user’s command (e.g., "netsplit plan -p <config> -r <[replicas/reservations]>") and passes it to the subnet planning engine.
- The planning engine loads the specified TOML file, parses the network layout, computes the divisions, and either prints or renders the output to the terminal.
- For testing, the test suite simulates various plan configurations (JSON and TOML files) to validate that the engine produces correct subnet allocations.
- Deployment scripts (Makefile, GitHub Action workflows) are used to automate testing, building, and releasing but aren’t part of the run-time flow.

##### Architectural Patterns and Design Principles
- Layered/Modular Architecture:
– The separation between the CLI and the core logic underscores a modular design; the CLI is simply a wrapper that calls deeper logic.
- Input-Process-Output Flow:
– The main flow starts from input (user-provided TOML configuration), then processing (network calculation), and finally output (rendered table view of subnets).
- Test-Driven Development:
– The inclusion of a comprehensive “tests” directory suggests the project follows TDD or at least emphasizes validation of the core functionality.
- Configuration and Extensibility:
– The use of TOML for configuration makes it extensible for various network planning use cases, evident in the “examples” and “tests” directories.

##### Relevant Technologies and Frameworks
- Python is the primary language, with packaging managed via pyproject.toml and setup.cfg.
- Use of GitHub Actions (in the “.github/workflows” directory) marking continuous integration.
- TOML is used for configuration.
- Command line parsing libraries (if any, such as argparse or click) might be used in the CLI layer, though not explicitly shown in the tree.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        A["User CLI Input"]:::external
        B["CLI Controller (netsplit/cli.py)"]:::runtime
    end

    subgraph "Configuration"
        C1["Example Config (TOML)"]:::config
        C2["Test Plan Config (TOML)"]:::config
        CP["Config Parser"]:::config
    end

    subgraph "Core Processing"
        D["Subnet Planning Engine (netsplit/__init__.py)"]:::runtime
        E["Output Renderer/Terminal"]:::runtime
    end

    subgraph "Testing"
        F["Test Suite (tests)"]:::test
    end

    subgraph "Infrastructure & CI/CD"
        G1["Makefile"]:::infra
        G2[".github/workflows (pr.yml)"]:::infra
        H1["pyproject.toml"]:::infra
        H2["setup.cfg"]:::infra
    end

    A -->|"sends_command"| B
    B -->|"loads_config"| CP
    C1 --> CP
    C2 --> CP
    CP -->|"parsed_data"| D
    D -->|"renders_plan"| E
    F -->|"validates_engine"| D

    G1 ---|"triggers"| F
    G1 ---|"builds"| D
    G2 ---|"automates"| D
    H1 ---|"configures"| D
    H2 ---|"configures"| D

    click B "https://github.com/hasiotis/netsplit/blob/main/netsplit/cli.py"
    click D "https://github.com/hasiotis/netsplit/blob/main/netsplit/__init__.py"
    click C1 "https://github.com/hasiotis/netsplit/blob/main/examples/netsplit-simple.toml"
    click C2 "https://github.com/hasiotis/netsplit/blob/main/tests/plans/Simple.toml"
    click F "https://github.com/hasiotis/netsplit/blob/main/tests/test_get_subnets.py"
    click G1 "https://github.com/hasiotis/netsplit/tree/main/Makefile"
    click G2 "https://github.com/hasiotis/netsplit/blob/main/.github/workflows/pr.yml"
    click H1 "https://github.com/hasiotis/netsplit/blob/main/pyproject.toml"
    click H2 "https://github.com/hasiotis/netsplit/blob/main/setup.cfg"

    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef runtime fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef config fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef test fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
