# martian-lang/martian architecture

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

- Interactive diagram: https://gitdiagram.com/martian-lang/martian
- Repository: https://github.com/martian-lang/martian

## Overview

Martian is a language and runtime for computational pipelines. Users define pipelines in MRO, then can check or visualize them, refactor them, or run them as a pipestance; the runtime coordinates jobs and tracks their state and files. The repository also includes stage adapters, cluster job-manager integrations, and status/UI interfaces. The principal workflow is documented at the product level, but several runtime handoffs are not visible in the sampled excerpts, so those links are marked as unverified rather than asserted.

Main entry points: [`martian/syntax`](https://github.com/martian-lang/martian/tree/master/martian/syntax) (MRO syntax), [`cmd/mro/main.go`](https://github.com/martian-lang/martian/blob/master/cmd/mro/main.go) (MRO command), [`cmd/mrp/main.go`](https://github.com/martian-lang/martian/blob/master/cmd/mrp/main.go) (Pipeline runner), [`martian/api`](https://github.com/martian-lang/martian/tree/master/martian/api) (Monitoring API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["MRO language"]
  node_mro_syntax["MRO syntax"]
  node_mro_parser["MRO parser<br/>[parser.go]"]
  node_ast_builder["AST builder<br/>[exp.go]"]
  node_pipeline_compile["Pipeline compiler"]
  node_call_graph["Call graph<br/>[dot.go]"]
end

subgraph group_authoring["Pipeline tools"]
  node_mro_cli["MRO command<br/>[main.go]"]
  node_mro_check["Pipeline checks<br/>[main.go]"]
  node_mro_edit["Pipeline refactoring<br/>[main.go]"]
  node_mro_graph["Graph analysis<br/>[main.go]"]
  node_mro_format["MRO formatter<br/>[main.go]"]
  node_invocation_tool["Invocation converter<br/>[main.go]"]
  node_go_generator["Stage code generator<br/>[main.go]"]
end

subgraph group_runtime["Execution runtime"]
  node_runner["Pipeline runner<br/>[main.go]"]
  node_runloop["Runtime run loop<br/>[runloop.go]"]
  node_pipestance["Pipestance state<br/>[pipestance.go]"]
  node_stage_runtime["Stage runtime<br/>[stage.go]"]
  node_storage_recovery["Storage recovery<br/>[storage.go]"]
end

subgraph group_jobs["Job execution"]
  node_job_manager["Job manager<br/>[jobmanager.go]"]
  node_local_jobs["Local job manager"]
  node_remote_jobs["Remote job manager"]
  node_python_adapter["Python stage adapter<br/>[martian_shell.py]"]
  node_python_api["Python stage API<br/>[martian.py]"]
  node_queue_integrations["Cluster queue adapters"]
end

subgraph group_operations["Operations"]
  node_webserver["Monitoring server<br/>[webserver.go]"]
  node_api["Monitoring API"]
  node_graph_ui["Graph UI<br/>[graph.js]"]
  node_status_cli["Status client<br/>[main.go]"]
end

node_pipeline_author(("Pipeline author"))
node_pipeline_user(("Pipeline operator"))

node_pipeline_author -.->|"writes MRO"| node_mro_parser
node_mro_cli -->|"dispatches check"| node_mro_check
node_mro_cli -->|"dispatches edit"| node_mro_edit
node_mro_cli -->|"dispatches format"| node_mro_format
node_mro_cli -->|"dispatches graph"| node_mro_graph
node_mro_check -->|"compiles MRO"| node_mro_syntax
node_mro_graph -->|"compiles MRO"| node_mro_syntax
node_mro_graph -->|"builds graph"| node_call_graph
node_mro_edit -.->|"loads pipeline"| node_mro_syntax
node_invocation_tool -->|"parses source"| node_mro_syntax
node_go_generator -->|"parses MRO"| node_mro_syntax
node_mro_parser -.->|"builds syntax"| node_ast_builder
node_mro_syntax -.->|"resolves pipelines"| node_pipeline_compile
node_runner -.->|"invokes pipeline"| node_pipestance
node_runner -.->|"runs workflow"| node_runloop
node_runloop -.->|"schedules stages"| node_stage_runtime
node_runloop -.->|"dispatches jobs"| node_job_manager
node_stage_runtime -.->|"tracks files"| node_storage_recovery
node_job_manager -.->|"selects local"| node_local_jobs
node_job_manager -.->|"selects remote"| node_remote_jobs
node_python_adapter -->|"uses stage API"| node_python_api
node_runner -.->|"starts monitoring"| node_webserver
node_webserver -->|"serves endpoints"| node_api
node_api -->|"reports state"| node_pipestance
node_graph_ui -.->|"loads graph"| node_api
node_pipeline_user -.->|"starts run"| node_runner
node_status_cli -->|"queries status"| node_api
node_pipeline_user -.->|"runs tools"| node_mro_cli

click node_mro_syntax "https://github.com/martian-lang/martian/tree/master/martian/syntax"
click node_mro_parser "https://github.com/martian-lang/martian/blob/master/martian/syntax/parser.go"
click node_ast_builder "https://github.com/martian-lang/martian/blob/master/martian/syntax/ast_builder/exp.go"
click node_pipeline_compile "https://github.com/martian-lang/martian/blob/master/martian/syntax/compile_pipelines.go"
click node_call_graph "https://github.com/martian-lang/martian/blob/master/martian/syntax/graph/dot.go"
click node_mro_cli "https://github.com/martian-lang/martian/blob/master/cmd/mro/main.go"
click node_mro_check "https://github.com/martian-lang/martian/blob/master/cmd/mro/check/main.go"
click node_mro_edit "https://github.com/martian-lang/martian/blob/master/cmd/mro/edit/main.go"
click node_mro_graph "https://github.com/martian-lang/martian/blob/master/cmd/mro/graph/main.go"
click node_mro_format "https://github.com/martian-lang/martian/blob/master/cmd/mro/format/main.go"
click node_invocation_tool "https://github.com/martian-lang/martian/blob/master/cmd/mrg/main.go"
click node_go_generator "https://github.com/martian-lang/martian/blob/master/cmd/mro2go/main.go"
click node_runner "https://github.com/martian-lang/martian/blob/master/cmd/mrp/main.go"
click node_runloop "https://github.com/martian-lang/martian/blob/master/cmd/mrp/runloop.go"
click node_pipestance "https://github.com/martian-lang/martian/blob/master/martian/core/pipestance.go"
click node_stage_runtime "https://github.com/martian-lang/martian/blob/master/martian/core/stage.go"
click node_storage_recovery "https://github.com/martian-lang/martian/blob/master/martian/core/storage.go"
click node_job_manager "https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager.go"
click node_local_jobs "https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager_local.go"
click node_remote_jobs "https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager_remote.go"
click node_python_adapter "https://github.com/martian-lang/martian/blob/master/adapters/python/martian_shell.py"
click node_python_api "https://github.com/martian-lang/martian/blob/master/adapters/python/martian.py"
click node_queue_integrations "https://github.com/martian-lang/martian/tree/master/jobmanagers"
click node_webserver "https://github.com/martian-lang/martian/blob/master/cmd/mrp/webserver.go"
click node_api "https://github.com/martian-lang/martian/tree/master/martian/api"
click node_graph_ui "https://github.com/martian-lang/martian/blob/master/web/martian/client/graph.js"
click node_status_cli "https://github.com/martian-lang/martian/blob/master/cmd/mrstat/main.go"

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_mro_syntax,node_mro_parser,node_ast_builder,node_pipeline_compile,node_call_graph toneBlue
class node_mro_cli,node_mro_check,node_mro_edit,node_mro_graph,node_mro_format,node_invocation_tool,node_go_generator toneAmber
class node_runner,node_runloop,node_pipestance,node_stage_runtime,node_storage_recovery toneMint
class node_job_manager,node_local_jobs,node_remote_jobs,node_python_adapter,node_python_api,node_queue_integrations toneRose
class node_webserver,node_api,node_graph_ui,node_status_cli,node_pipeline_author,node_pipeline_user toneIndigo
```

## Components

### MRO language

- [MRO syntax](https://github.com/martian-lang/martian/tree/master/martian/syntax): `martian/syntax`
- [MRO parser](https://github.com/martian-lang/martian/blob/master/martian/syntax/parser.go): `martian/syntax/parser.go`
- [AST builder](https://github.com/martian-lang/martian/blob/master/martian/syntax/ast_builder/exp.go): `martian/syntax/ast_builder/exp.go`
- [Pipeline compiler](https://github.com/martian-lang/martian/blob/master/martian/syntax/compile_pipelines.go): `martian/syntax/compile_pipelines.go`
- [Call graph](https://github.com/martian-lang/martian/blob/master/martian/syntax/graph/dot.go): `martian/syntax/graph/dot.go`

### Pipeline tools

- [MRO command](https://github.com/martian-lang/martian/blob/master/cmd/mro/main.go): `cmd/mro/main.go`
- [Pipeline checks](https://github.com/martian-lang/martian/blob/master/cmd/mro/check/main.go): `cmd/mro/check/main.go`
- [Pipeline refactoring](https://github.com/martian-lang/martian/blob/master/cmd/mro/edit/main.go): `cmd/mro/edit/main.go`
- [Graph analysis](https://github.com/martian-lang/martian/blob/master/cmd/mro/graph/main.go): `cmd/mro/graph/main.go`
- [MRO formatter](https://github.com/martian-lang/martian/blob/master/cmd/mro/format/main.go): `cmd/mro/format/main.go`
- [Invocation converter](https://github.com/martian-lang/martian/blob/master/cmd/mrg/main.go): `cmd/mrg/main.go`
- [Stage code generator](https://github.com/martian-lang/martian/blob/master/cmd/mro2go/main.go): `cmd/mro2go/main.go`

### Execution runtime

- [Pipeline runner](https://github.com/martian-lang/martian/blob/master/cmd/mrp/main.go): `cmd/mrp/main.go`
- [Runtime run loop](https://github.com/martian-lang/martian/blob/master/cmd/mrp/runloop.go): `cmd/mrp/runloop.go`
- [Pipestance state](https://github.com/martian-lang/martian/blob/master/martian/core/pipestance.go): `martian/core/pipestance.go`
- [Stage runtime](https://github.com/martian-lang/martian/blob/master/martian/core/stage.go): `martian/core/stage.go`
- [Storage recovery](https://github.com/martian-lang/martian/blob/master/martian/core/storage.go): `martian/core/storage.go`

### Job execution

- [Job manager](https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager.go): `martian/core/jobmanager.go`
- [Local job manager](https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager_local.go): `martian/core/jobmanager_local.go`
- [Remote job manager](https://github.com/martian-lang/martian/blob/master/martian/core/jobmanager_remote.go): `martian/core/jobmanager_remote.go`
- [Python stage adapter](https://github.com/martian-lang/martian/blob/master/adapters/python/martian_shell.py): `adapters/python/martian_shell.py`
- [Python stage API](https://github.com/martian-lang/martian/blob/master/adapters/python/martian.py): `adapters/python/martian.py`
- [Cluster queue adapters](https://github.com/martian-lang/martian/tree/master/jobmanagers): `jobmanagers`

### Operations

- [Monitoring server](https://github.com/martian-lang/martian/blob/master/cmd/mrp/webserver.go): `cmd/mrp/webserver.go`
- [Monitoring API](https://github.com/martian-lang/martian/tree/master/martian/api): `martian/api`
- [Graph UI](https://github.com/martian-lang/martian/blob/master/web/martian/client/graph.js): `web/martian/client/graph.js`
- [Status client](https://github.com/martian-lang/martian/blob/master/cmd/mrstat/main.go): `cmd/mrstat/main.go`

### Other components

- **Pipeline author**
- **Pipeline operator**

## Connections

- Pipeline author → MRO parser: writes MRO
- MRO command → Pipeline checks: dispatches check (evidence: `cmd/mro/main.go`)
- MRO command → Pipeline refactoring: dispatches edit (evidence: `cmd/mro/main.go`)
- MRO command → MRO formatter: dispatches format (evidence: `cmd/mro/main.go`)
- MRO command → Graph analysis: dispatches graph (evidence: `cmd/mro/main.go`)
- Pipeline checks → MRO syntax: compiles MRO (evidence: `cmd/mro/check/main.go`)
- Graph analysis → MRO syntax: compiles MRO (evidence: `cmd/mro/graph/main.go`)
- Graph analysis → Call graph: builds graph (evidence: `cmd/mro/graph/main.go`)
- Pipeline refactoring → MRO syntax: loads pipeline (evidence: `cmd/mro/edit/main.go`)
- Invocation converter → MRO syntax: parses source (evidence: `cmd/mrg/main.go`)
- Stage code generator → MRO syntax: parses MRO (evidence: `cmd/mro2go/main.go`)
- MRO parser → AST builder: builds syntax
- MRO syntax → Pipeline compiler: resolves pipelines
- Pipeline runner → Pipestance state: invokes pipeline
- Pipeline runner → Runtime run loop: runs workflow
- Runtime run loop → Stage runtime: schedules stages
- Runtime run loop → Job manager: dispatches jobs
- Stage runtime → Storage recovery: tracks files
- Job manager → Local job manager: selects local
- Job manager → Remote job manager: selects remote
- Python stage adapter → Python stage API: uses stage API (evidence: `adapters/python/martian.py`)
- Pipeline runner → Monitoring server: starts monitoring
- Monitoring server → Monitoring API: serves endpoints (evidence: `cmd/mrp/webserver.go`)
- Monitoring API → Pipestance state: reports state (evidence: `martian/api/pipestance_info.go`)
- Graph UI → Monitoring API: loads graph
- Pipeline operator → Pipeline runner: starts run
- Status client → Monitoring API: queries status (evidence: `cmd/mrstat/main.go`)
- Pipeline operator → MRO command: runs tools
