# alleninstitute/bmtk architecture

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

- Interactive diagram: https://gitdiagram.com/alleninstitute/bmtk
- Repository: https://github.com/alleninstitute/bmtk

## Overview

##### Project type and purpose
- BMTK (Brain Modeling Toolkit) is an open‐source Python software suite (a library/CLI toolkit) for multiscale modeling of brain circuits.
- It provides three core functional areas:
- Builder: constructs network models (nodes, edges) from JSON configs into SONATA files (CSV, HDF5).
- Simulator: runs simulations at multiple levels of resolution (biophysical via NEURON, point‐neuron via NEST, filter network, population network).
- Analyzer: loads simulation outputs to compute firing rates, spike trains, cell variables, voltage traces, extracellular potentials, etc.

##### File structure
- Top‐level Python package: `bmtk/` with subpackages:
- `builder/` – network construction classes, I/O, network adapters, edge/node connectors
- `simulator/` – `bionet/`, `filternet/`, `pointnet/`, `popnet/`, each with config schemas, modules, adapters
- `analyzer/` – tools for loading and computing metrics on simulation results
- `utils/` – helpers (HDF5, SONATA, reports, environment creation, mechanism compilation)
- Scripts and entry‐points: CLI wrappers under `bmtk/utils/scripts/`, `bmtk/utils/sim_setup.py`
- Configuration and data directories: examples, docs/examples, tutorials, Docker environment, CI workflows.
- Tests organized under `tests/...` mirroring each major component.

##### README for additional insights
- Confirms the three main workflows (build, simulate, analyze)
- Points to external dependencies (NEURON, NEST, SONATA file formats)
- Mentions documentation, examples, and testing via pytest
- Project uses Docker for reproducible environments and GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Entry-Points"
        direction TB
        runBionet(["run_bionet.py"]):::cli
        runPointnet(["run_pointnet.py"]):::cli
        runFilternet(["run_filternet.py"]):::cli
        runPopnet(["run_popnet.py"]):::cli
        simSetup(["sim_setup.py"]):::cli
    end

    %% Core Modules
    Builder(["Builder Module"]):::coreModule
    SimulatorCore(["Simulator Core"]):::coreModule
    Analyzer(["Analyzer Module"]):::coreModule

    %% Data Stores
    NetFiles(["SONATA Network Files<br/>(CSV/HDF5)"]):::dataStore
    RawOutputs(["Raw Simulation Outputs<br/>(HDF5/CSV)"]):::dataStore

    %% Simulator Engines
    subgraph "Simulation Engines"
        direction TB
        Bionet(["Bionet<br/>Adapter/Engine"]):::adapter
        Pointnet(["Pointnet<br/>Adapter/Engine"]):::adapter
        Filternet(["Filternet<br/>Engine"]):::adapter
        Popnet(["Popnet<br/>Engine"]):::adapter
    end

    %% Utilities & Helpers
    Utils(["Shared Utilities Library"]):::util
    SonataIO(["SONATA I/O & Config Helpers"]):::util
    HDF5IO(["HDF5 & I/O Helpers"]):::util
    Reports(["Reports Framework"]):::util

    %% External Services
    subgraph "External Services"
        direction TB
        Docker(["Docker"]):::external
        CI(["GitHub Actions CI/CD"]):::external
        PyPI(["PyPI Packaging"]):::external
    end

    %% Data Flows
    runBionet -->|invokes| Builder
    runPointnet -->|invokes| Builder
    runFilternet -->|invokes| Builder
    runPopnet -->|invokes| Builder
    simSetup -->|initializes| Builder

    Builder -->|generates| NetFiles
    NetFiles -->|feeds| SimulatorCore

    SimulatorCore -->|routes to| Bionet
    SimulatorCore -->|routes to| Pointnet
    SimulatorCore -->|routes to| Filternet
    SimulatorCore -->|routes to| Popnet

    Bionet -->|produces| RawOutputs
    Pointnet -->|produces| RawOutputs
    Filternet -->|produces| RawOutputs
    Popnet -->|produces| RawOutputs

    RawOutputs -->|consumed by| Analyzer

    %% Utilities usage
    Utils --> Builder
    Utils --> SimulatorCore
    Utils --> Analyzer

    SonataIO --> Builder
    SonataIO --> SimulatorCore

    HDF5IO --> Builder
    HDF5IO --> Analyzer

    Reports --> Analyzer

    %% External interactions
    Docker ---|containerizes| Builder
    Docker ---|containerizes| SimulatorCore
    Docker ---|containerizes| Analyzer
    CI ---|tests & deploys| Builder
    CI ---|tests & deploys| SimulatorCore
    CI ---|tests & deploys| Analyzer
    PyPI ---|publishes| Builder
    PyPI ---|publishes| SimulatorCore
    PyPI ---|publishes| Analyzer

    %% Click Events
    click Builder "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/builder"
    click SimulatorCore "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/simulator/core"
    click Bionet "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/simulator/bionet"
    click Pointnet "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/simulator/pointnet"
    click Filternet "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/simulator/filternet"
    click Popnet "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/simulator/popnet"
    click Analyzer "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/analyzer"
    click Utils "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/utils"
    click SonataIO "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/utils/sonata"
    click HDF5IO "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/hdf5_helper.py"
    click HDF5IO "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/io/ioutils.py"
    click Reports "https://github.com/alleninstitute/bmtk/tree/develop/bmtk/utils/reports"
    click runBionet "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/scripts/bionet/run_bionet.py"
    click runPointnet "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/scripts/pointnet/run_pointnet.py"
    click runFilternet "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/scripts/filternet/run_filternet.py"
    click runPopnet "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/scripts/popnet/run_popnet.py"
    click simSetup "https://github.com/alleninstitute/bmtk/blob/develop/bmtk/utils/sim_setup.py"

    %% Styling
    classDef coreModule fill:#A8DADC,stroke:#457B9D,color:#1D3557
    classDef dataStore fill:#BFFCC6,stroke:#52B788,color:#1B4332
    classDef adapter fill:#F4A261,stroke:#E76F51,color:#9C2E04
    classDef util fill:#E0E0E0,stroke:#888888,color:#333333
    classDef cli fill:#9D4EDD,stroke:#6A3EA1,color:#FFFFFF
    classDef external fill:#CCCCCC,stroke:#888888,color:#333333
```
