# nest/nest-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/nest/nest-simulator
- Repository: https://github.com/nest/nest-simulator

## Overview

##### Main Components
- Simulation Kernel: Represent the core engine that defines network dynamics and event handling. This includes the “nestkernel” directory (which houses submodules like connection handling, event management, MPI manager, device management, and recording backends) and the “nest” directory (further encapsulating startup routines and main simulation logic).
- Model and Neural Component Libraries: Group together directories such as “models”, “lib”, and “libnestutil” that provide a large collection of neurons, synapses, and other reproducible models.
- Scripting and Interface Layer: Highlight “sli” – the interpreter language that underpins script-based simulations – and “pynest” which contains Python bindings and example scripts. This layer translates user scripts (in Python or SLI) into simulation commands.
- User Interface & Examples: Include modules from “examples”, “doc”, and “pynest/examples” which show how users interact with the simulator.
- Build, Test, and Documentation Infrastructure: Capture directories such as “cmake”, “build_support”, “testsuite”, “thirdparty”, and “doc” that manage the build processes, testing routines, continuous integration (as seen in CI workflows), and documentation generation.

##### Relationships and Interactions
- The User Interface Layer (via Python interface in “pynest” or command-line/SLI commands) submits simulation configurations.
- Requests flow from these interfaces into the Simulation Kernel that schedules events, manages the network’s state, and uses MPI for parallel simulation on clusters.
- The Models Library feeds into the simulation kernel by supplying the neuron and synapse models.
- Communication flows both upwards (results and recordings sent to the UI, possibly through recording backends and visualization modules) and downwards (simulation parameters and network definitions provided by the UI).
- The build and test systems continuously ensure code quality and help integrate thirdparty libraries (such as Random123) ensuring the kernel’s performance and reproducibility.

##### Architectural Patterns and Design Principles
- Modular separation: The clear separation between the simulation engine, model libraries, and user interface reflects a layered architecture.
- Extensibility: Not only can the core be extended via custom modules (see “modelsets” and “libnestutil”), but the SLI interpreter and Python API enable straightforward integration with external tools.
- Scalability and parallelism: With MPI subcomponents (visible in “nest-server-mpi”, “testsuite/mpitests”, etc.) and careful design of the simulation kernel, NEST is scalable from laptops to supercomputers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface & Examples Layer
    subgraph "User Interface & Examples"
        UI1["Examples (examples)"]:::ui
        UI2["Python Examples (pynest/examples)"]:::ui
        UI3["Documentation (doc/htmldoc)"]:::ui
    end

    %% Scripting Interface Layer
    subgraph "Scripting Interface"
        SI1["SLI Interpreter (sli)"]:::scripting
        SI2["Python Bindings (pynest)"]:::scripting
    end

    %% Simulation Core Layer
    subgraph "Simulation Core"
        SC1["NEST Kernel (nestkernel)"]:::simulationCore
        SC2["NEST Main (nest)"]:::simulationCore
    end

    %% Models and Libraries Layer
    subgraph "Models and Libraries"
        M1["Neuronal Models (models)"]:::modelLib
        M2["Additional Libraries (lib)"]:::modelLib
        M3["Utilities (libnestutil)"]:::modelLib
    end

    %% Build, Testing & Deployment Layer
    subgraph "Build, Testing & Deployment"
        B1["Build Config (cmake)"]:::infrastructure
        B2["Build Support (build_support)"]:::infrastructure
        T1["Testing Suite (testsuite)"]:::infrastructure
        CI["CI Workflows (.github/workflows)"]:::infrastructure
    end

    %% Connections from UI to Scripting Interface
    UI1 -->|"submit"| SI1
    UI2 -->|"submit"| SI2
    UI3 -->|"info"| SI1

    %% Connections from Scripting Interface to Simulation Core
    SI1 -->|"run_sim"| SC1
    SI2 -->|"run_sim"| SC1

    %% Connections from Models & Libraries to Simulation Core
    M1 -->|"provide_models"| SC1
    M2 -->|"provide_libs"| SC1
    M3 -->|"provide_utils"| SC1

    %% Feedback from Simulation Core to UI
    SC1 -->|"output_data"| UI1
    SC1 -->|"output_data"| UI2

    %% Integration with Build, Testing & Deployment
    B1 -->|"build"| SC1
    B2 -->|"support_build"| SC1
    T1 -->|"test"| SC1
    CI -->|"CI_check"| SC1

    %% Class Definitions
    classDef ui fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef scripting fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef simulationCore fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef modelLib fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef infrastructure fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events for User Interface & Examples
    click UI1 "https://github.com/nest/nest-simulator/tree/master/examples/"
    click UI2 "https://github.com/nest/nest-simulator/tree/master/pynest/examples/"
    click UI3 "https://github.com/nest/nest-simulator/tree/master/doc/htmldoc"

    %% Click Events for Scripting Interface
    click SI1 "https://github.com/nest/nest-simulator/tree/master/sli/"
    click SI2 "https://github.com/nest/nest-simulator/tree/master/pynest/"

    %% Click Events for Simulation Core
    click SC1 "https://github.com/nest/nest-simulator/tree/master/nestkernel/"
    click SC2 "https://github.com/nest/nest-simulator/tree/master/nest/"

    %% Click Events for Models and Libraries
    click M1 "https://github.com/nest/nest-simulator/tree/master/models/"
    click M2 "https://github.com/nest/nest-simulator/tree/master/lib/"
    click M3 "https://github.com/nest/nest-simulator/tree/master/libnestutil/"

    %% Click Events for Build, Testing & Deployment
    click B1 "https://github.com/nest/nest-simulator/tree/master/cmake/"
    click B2 "https://github.com/nest/nest-simulator/tree/master/build_support/"
    click T1 "https://github.com/nest/nest-simulator/tree/master/testsuite/"
    click CI "https://github.com/nest/nest-simulator/tree/master/.github/workflows/"
```
