# dune-daq/nanorc architecture

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

- Interactive diagram: https://gitdiagram.com/dune-daq/nanorc
- Repository: https://github.com/dune-daq/nanorc

## Overview

1. **What this repository is**
   NanoRC is a Python control application for DUNE DAQ sessions. It is not a data-processing service itself; it is the orchestration layer that starts DAQ apps, drives their finite-state transitions, and coordinates configuration, run numbering, logging, and monitoring.

2. **Primary entrypoints**
   The package exposes multiple runtime entrypoints: `nanorc` for normal use, `nano04rc` for the NP04 production environment, and `nanotimingrc` for timing sessions. These all share the same control core but differ in environment assumptions and defaults.

3. **Control-plane core**
   The central architecture is a command-driven session controller built around a finite state machine. The FSM logic is in `fsm.py`, while `core.py`, `cli.py`, and `common_commands.py` wire the user-facing commands to state transitions such as boot, conf, start, stop, drain, and terminate. The session object and contextual state are managed through `nano_context.py`.

4. **Application lifecycle and per-app state**
   Individual DAQ applications are modeled as nodes/stateful nodes, not just opaque processes. `node.py`, `statefulnode.py`, and `appctrl.py` represent the remote app and its lifecycle state, last command, liveness, and command responses. This is the layer that the status display and UI panels read from.

5. **Process management boundary**
   NanoRC abstracts process launch behind process-manager implementations. The repo contains both SSH-based and Kubernetes-based managers (`sshpm.py`, `k8spm.py`). The SSH path starts apps on hosts via remote execution; the Kubernetes path creates pods in a namespace/session and relies on pod lifecycle and logs. This boundary is important: NanoRC controls apps, but does not own their internal runtime.

6. **Configuration flow**
   Configuration is assembled before boot and then served to applications. `cfgmgr.py`, `cfgsvr.py`, `confserver.py`, and `cfgsvr.py` manage the configuration service side, while `confdata/` contains local configuration metadata such as run number, run registry, and config-service descriptors. The README shows that boot files resolve environment variables and template tokens before launch, including app name, command factory URL, and config location.

7. **Session services and run metadata**
   Run coordination is separated into dedicated support modules: `runmgr.py` handles run number and run/session bookkeeping, `runinfo.py` tracks run-related metadata, `logbook.py` integrates with logging/cataloging, and `opmondash.py` supports operational monitoring dashboards. This makes NanoRC the session coordinator across multiple external services rather than a single monolithic process.

8. **Authentication and remote access**
   `auth.py`, `credmgr.py`, and `rest.py` indicate a boundary around authentication/credentials and REST communication. These are used to talk to remote app command endpoints and supporting services. In practice, the system relies on networked control channels, not shared-memory or in-process calls.

9. **User interfaces**
   There are three interaction surfaces over the same control core: a terminal CLI, a terminal UI (`tui.py` with `tui.css`), and a web UI (`webui.py` plus `webuidata/` templates/static assets). All three are front ends over the same session state and command execution path; they differ only in presentation and input method.

10. **Boot/config generation and external tools**
   The `tools/` directory contains helper utilities for configuration visualization, upload, retrieval, and operational monitoring. These are adjuncts to the main runtime, not separate services. The README also shows integration with external DUNE DAQ tooling such as `fddaqconf_gen`, and with external infrastructure such as `/cvmfs`, shared NFS, SSH hosts, Kubernetes, and the NP04 dashboard/Grafana stack.

11. **Data flow at runtime**
   The normal flow is: load a boot/config description, resolve environment and host substitutions, launch apps via the selected process manager, wait for app responses on the configured listener, then drive FSM transitions across all apps in the session. Status and logs are then surfaced back to the user through the CLI/TUI/web UI, while the underlying apps continue to communicate over their own command and monitoring endpoints.

12. **Testing and validation**
   The `tests/` and `integtests/` directories focus on command behavior, configuration handling, and Kubernetes support. The presence of integration tests for custom commands and k8s indicates that the repo’s critical seams are the process manager boundary and the command/config orchestration path, not algorithmic computation.

Main entry points: [`src/nanorc/core.py`](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/core.py) (Session core), [`src/nanorc/cfgmgr.py`](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgmgr.py) (Cfg mgr), [`src/nanorc/nano_context.py`](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/nano_context.py) (Context), [`src/nanorc/cfgsvr.py`](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgsvr.py) (Cfg server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entry Points"]
  node_nanorc_main(("nanorc<br/>entrypoint<br/>[__main__.py]"))
  node_nanorc_np04(("nano04rc<br/>entrypoint<br/>[__main_np04__.py]"))
  node_nanorc_timing(("nanotimingrc<br/>entrypoint<br/>[__main_timing__.py]"))
end

subgraph group_control["Control Core"]
  node_core["Session core<br/>orchestrator<br/>[core.py]"]
  node_cli["CLI<br/>command shell<br/>[cli.py]"]
  node_commands["Common cmds<br/>command set<br/>[common_commands.py]"]
  node_fsm(("FSM<br/>state machine<br/>[fsm.py]"))
  node_context["Context<br/>session state<br/>[nano_context.py]"]
end

subgraph group_runtime["App Runtime"]
  node_node["Node<br/>app model<br/>[node.py]"]
  node_statefulnode["Stateful node<br/>app state<br/>[statefulnode.py]"]
  node_appctrl["App control<br/>remote control<br/>[appctrl.py]"]
  node_sshpm["SSH PM<br/>process manager<br/>[sshpm.py]"]
  node_k8spm["K8s PM<br/>process manager<br/>[k8spm.py]"]
end

subgraph group_config["Configuration"]
  node_cfgmgr["Cfg mgr<br/>config assembly<br/>[cfgmgr.py]"]
  node_cfgsvr[("Cfg server<br/>config service<br/>[cfgsvr.py]")]
  node_confserver["Conf server<br/>config endpoint<br/>[confserver.py]"]
  node_confdata["Conf data<br/>config data<br/>[__init__.py]"]
end

subgraph group_services["Session Services"]
  node_runmgr["Run mgr<br/>run control<br/>[runmgr.py]"]
  node_runinfo["Run info<br/>run metadata<br/>[runinfo.py]"]
  node_logbook["Logbook<br/>logging service<br/>[logbook.py]"]
  node_opmondash["OpMon dash<br/>monitoring<br/>[opmondash.py]"]
  node_auth["Auth<br/>[auth.py]"]
  node_credmgr["Cred mgr<br/>credentials<br/>[credmgr.py]"]
  node_rest["REST<br/>transport<br/>[rest.py]"]
end

subgraph group_ui["User Interfaces"]
  node_tui["TUI<br/>terminal ui<br/>[tui.py]"]
  node_webui["Web UI<br/>web interface<br/>[webui.py]"]
  node_node_render["Node view<br/>rendering<br/>[node_render.py]"]
end

subgraph group_tools["Tools"]
  node_drawconf["Draw conf<br/>[drawconf.py]"]
  node_get_run_conf["Get run conf<br/>[get_run_conf.py]"]
  node_nano_conf_svc["Conf svc tool<br/>[nano_conf_svc.py]"]
  node_opmon_tool["OpMon tool<br/>[opmon.py]"]
  node_upload_conf["Upload conf<br/>[upload_conf.py]"]
end

node_nanorc_main -->|"starts"| node_core
node_nanorc_np04 -->|"starts"| node_core
node_nanorc_timing -->|"starts"| node_core
node_core -->|"wires"| node_cli
node_core -->|"dispatches"| node_commands
node_commands -->|"drives"| node_fsm
node_core -->|"stores"| node_context
node_context -->|"uses"| node_runmgr
node_context -->|"uses"| node_cfgmgr
node_cfgmgr -->|"serves"| node_cfgsvr
node_cfgsvr -->|"backed by"| node_confserver
node_cfgmgr -->|"loads"| node_confdata
node_core -->|"launches"| node_sshpm
node_core -->|"launches"| node_k8spm
node_sshpm -->|"manages"| node_node
node_k8spm -->|"manages"| node_statefulnode
node_node -->|"controls"| node_appctrl
node_statefulnode -->|"controls"| node_appctrl
node_core -->|"records"| node_runinfo
node_core -->|"logs"| node_logbook
node_core -->|"publishes"| node_opmondash
node_core -->|"authenticates"| node_auth
node_auth -->|"uses"| node_credmgr
node_rest -->|"transports"| node_appctrl
node_tui -->|"fronts"| node_core
node_webui -->|"fronts"| node_core
node_tui -->|"renders"| node_node_render
node_webui -->|"renders"| node_node_render
node_drawconf -->|"inspects"| node_cfgmgr
node_get_run_conf -->|"reads"| node_runmgr
node_nano_conf_svc -->|"talks to"| node_cfgsvr
node_opmon_tool -->|"talks to"| node_opmondash
node_upload_conf -->|"uploads"| node_cfgmgr

click node_nanorc_main "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main__.py"
click node_nanorc_np04 "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main_np04__.py"
click node_nanorc_timing "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main_timing__.py"
click node_core "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/core.py"
click node_cli "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cli.py"
click node_commands "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/common_commands.py"
click node_fsm "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/fsm.py"
click node_context "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/nano_context.py"
click node_node "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/node.py"
click node_statefulnode "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/statefulnode.py"
click node_appctrl "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/appctrl.py"
click node_sshpm "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/sshpm.py"
click node_k8spm "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/k8spm.py"
click node_cfgmgr "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgmgr.py"
click node_cfgsvr "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgsvr.py"
click node_confserver "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/confserver.py"
click node_confdata "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/confdata/__init__.py"
click node_runmgr "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/runmgr.py"
click node_runinfo "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/runinfo.py"
click node_logbook "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/logbook.py"
click node_opmondash "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/opmondash.py"
click node_auth "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/auth.py"
click node_credmgr "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/credmgr.py"
click node_rest "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/rest.py"
click node_tui "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tui.py"
click node_webui "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/webui.py"
click node_node_render "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/node_render.py"
click node_drawconf "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/drawconf.py"
click node_get_run_conf "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/get_run_conf.py"
click node_nano_conf_svc "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/nano_conf_svc.py"
click node_opmon_tool "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/opmon.py"
click node_upload_conf "https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/upload_conf.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nanorc_main,node_nanorc_np04,node_nanorc_timing,node_drawconf,node_get_run_conf,node_nano_conf_svc,node_opmon_tool,node_upload_conf toneBlue
class node_core,node_cli,node_commands,node_fsm,node_context toneAmber
class node_node,node_statefulnode,node_appctrl,node_sshpm,node_k8spm toneMint
class node_cfgmgr,node_cfgsvr,node_confserver,node_confdata toneRose
class node_runmgr,node_runinfo,node_logbook,node_opmondash,node_auth,node_credmgr,node_rest toneIndigo
class node_tui,node_webui,node_node_render toneTeal
```

## Components

### Entry Points

Runtime launchers and user-facing front doors.

- [nanorc](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main__.py): entrypoint · Main package entrypoint for normal session control. · `src/nanorc/__main__.py`
- [nano04rc](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main_np04__.py): entrypoint · NP04-specific entrypoint with environment defaults. · `src/nanorc/__main_np04__.py`
- [nanotimingrc](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/__main_timing__.py): entrypoint · Timing-session entrypoint variant. · `src/nanorc/__main_timing__.py`

### Control Core

Session orchestration, commands, and finite-state control.

- [Session core](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/core.py): orchestrator · Coordinates commands and session lifecycle. · `src/nanorc/core.py`
- [CLI](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cli.py): command shell · Command-line interface for session control. · `src/nanorc/cli.py`
- [Common cmds](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/common_commands.py): command set · Shared boot/conf/start/stop/terminate command handlers. · `src/nanorc/common_commands.py`
- [FSM](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/fsm.py): state machine · Finite-state transitions for the session. · `src/nanorc/fsm.py`
- [Context](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/nano_context.py): session state · Mutable session context and runtime state. · `src/nanorc/nano_context.py`

### App Runtime

Per-application lifecycle and remote process boundaries.

- [Node](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/node.py): app model · Remote application representation and state container. · `src/nanorc/node.py`
- [Stateful node](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/statefulnode.py): app state · State-tracking wrapper for app lifecycle. · `src/nanorc/statefulnode.py`
- [App control](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/appctrl.py): remote control · App command execution, liveness, and responses. · `src/nanorc/appctrl.py`
- [SSH PM](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/sshpm.py): process manager · Launches apps remotely over SSH. · `src/nanorc/sshpm.py`
- [K8s PM](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/k8spm.py): process manager · Launches apps as Kubernetes pods. · `src/nanorc/k8spm.py`

### Configuration

Configuration assembly and config-service integration.

- [Cfg mgr](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgmgr.py): config assembly · Builds and prepares configuration before boot. · `src/nanorc/cfgmgr.py`
- [Cfg server](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/cfgsvr.py): config service · Configuration service integration and serving. · `src/nanorc/cfgsvr.py`
- [Conf server](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/confserver.py): config endpoint · Configuration-server-facing logic. · `src/nanorc/confserver.py`
- [Conf data](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/confdata/__init__.py): config data · Local run/config metadata and service descriptors. · `src/nanorc/confdata/__init__.py`

### Session Services

Run metadata, logging, monitoring, credentials, and transport.

- [Run mgr](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/runmgr.py): run control · Run numbering and session bookkeeping. · `src/nanorc/runmgr.py`
- [Run info](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/runinfo.py): run metadata · Run-related metadata and records. · `src/nanorc/runinfo.py`
- [Logbook](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/logbook.py): logging service · Logging and cataloging integration. · `src/nanorc/logbook.py`
- [OpMon dash](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/opmondash.py): monitoring · Operational monitoring dashboard integration. · `src/nanorc/opmondash.py`
- [Auth](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/auth.py): auth boundary · Authentication and access handling. · `src/nanorc/auth.py`
- [Cred mgr](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/credmgr.py): credentials · Credential management for remote access. · `src/nanorc/credmgr.py`
- [REST](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/rest.py): transport · REST communication layer for remote services. · `src/nanorc/rest.py`

### User Interfaces

Terminal and web presentation layers over the same control core.

- [TUI](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tui.py): terminal ui · Terminal user interface for session control. · `src/nanorc/tui.py`
- [Web UI](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/webui.py): web interface · Web-based interface over the same session core. · `src/nanorc/webui.py`
- [Node view](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/node_render.py): rendering · Renders app/node status for UI displays. · `src/nanorc/node_render.py`

### Tools

Auxiliary operational utilities.

- [Draw conf](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/drawconf.py): utility · Configuration visualization helper. · `src/nanorc/tools/drawconf.py`
- [Get run conf](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/get_run_conf.py): utility · Retrieves run configuration data. · `src/nanorc/tools/get_run_conf.py`
- [Conf svc tool](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/nano_conf_svc.py): utility · Operational helper for config-service interaction. · `src/nanorc/tools/nano_conf_svc.py`
- [OpMon tool](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/opmon.py): utility · Operational monitoring helper utility. · `src/nanorc/tools/opmon.py`
- [Upload conf](https://github.com/dune-daq/nanorc/blob/production/v4/src/nanorc/tools/upload_conf.py): utility · Uploads configuration artifacts. · `src/nanorc/tools/upload_conf.py`

## Connections

- nanorc → Session core: starts · Main entrypoint initializes the session controller.
- nano04rc → Session core: starts · NP04 entrypoint reuses the same control core.
- nanotimingrc → Session core: starts · Timing entrypoint reuses the same control core.
- Session core → CLI: wires · Core binds command handling to the CLI.
- Session core → Common cmds: dispatches · Core routes user actions to shared commands.
- Common cmds → FSM: drives · Commands advance the session finite-state machine.
- Session core → Context: stores · Core reads and updates session context.
- Context → Run mgr: uses · Session context carries run/session bookkeeping.
- Context → Cfg mgr: uses · Context feeds configuration assembly and boot state.
- Cfg mgr → Cfg server: serves · Configuration manager connects to config-service logic.
- Cfg server → Conf server: backed by · Config service is exposed through confserver logic.
- Cfg mgr → Conf data: loads · Local config metadata informs config assembly.
- Session core → SSH PM: launches · Core selects the SSH process-manager path when needed.
- Session core → K8s PM: launches · Core selects the Kubernetes process-manager path when needed.
- SSH PM → Node: manages · SSH launcher creates and tracks app nodes.
- K8s PM → Stateful node: manages · Kubernetes launcher tracks node lifecycle state.
- Node → App control: controls · App nodes encapsulate remote command control.
- Stateful node → App control: controls · Stateful node wraps app control and responses.
- Session core → Run info: records · Session lifecycle updates run metadata.
- Session core → Logbook: logs · Core emits run/session activity to the logbook boundary.
- Session core → OpMon dash: publishes · Core exposes operational state to monitoring.
- Session core → Auth: authenticates · Core gates remote and service access through auth.
- Auth → Cred mgr: uses · Authentication relies on managed credentials.
- REST → App control: transports · REST layer carries remote app command traffic.
- TUI → Session core: fronts · Terminal UI presents the same session control path.
- Web UI → Session core: fronts · Web UI presents the same session control path.
- TUI → Node view: renders · TUI uses node rendering for status display.
- Web UI → Node view: renders · Web UI uses node rendering for status display.
- Draw conf → Cfg mgr: inspects · Tooling helps visualize configuration assembly.
- Get run conf → Run mgr: reads · Utility fetches run configuration details.
- Conf svc tool → Cfg server: talks to · Operational helper interacts with config service.
- OpMon tool → OpMon dash: talks to · Tooling supports operational monitoring integration.
- Upload conf → Cfg mgr: uploads · Utility supports configuration publication.
