Skip to content

Commit 77c2e39

Browse files
committed
chore: Add AGENTS.md
1 parent bc1ee58 commit 77c2e39

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

AGENTS.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2026 James Harton, Zach Daniel, Alembic Pty and contributors
3+
SPDX-FileCopyrightText: 2026 reactor contributors <https://github.com/ash-project/reactor/graphs.contributors>
4+
5+
SPDX-License-Identifier: MIT
6+
-->
7+
8+
# AGENTS.md
9+
10+
This file provides guidance to coding agents when working with code in this repository.
11+
12+
## Build and Development Commands
13+
14+
```bash
15+
# Run all quality checks (preferred - includes formatter, credo, dialyzer, tests, etc.)
16+
mix check --no-retry
17+
18+
# Run tests
19+
mix test # All tests
20+
mix test test/reactor/step_test.exs # Single test file
21+
mix test test/reactor/step_test.exs:14 # Single test at line
22+
23+
# Individual checks (use mix check instead when possible)
24+
mix format # Format code
25+
mix format --check-formatted # Verify formatting
26+
mix credo --strict # Linting
27+
mix dialyzer # Type checking
28+
29+
# Generate documentation
30+
mix docs # Also runs spark.cheat_sheets and spark.replace_doc_links
31+
32+
# Spark DSL formatting
33+
mix spark.formatter --extensions Reactor.Dsl
34+
```
35+
36+
## Architecture Overview
37+
38+
Reactor is a dynamic, concurrent, dependency-resolving saga orchestrator. It executes workflows as directed acyclic graphs (DAGs) with automatic dependency resolution and concurrent step execution.
39+
40+
### Core Execution Flow
41+
42+
1. **Define** - Reactor defined via DSL (`use Reactor`) or programmatically (`Reactor.Builder`)
43+
2. **Plan** - `Reactor.Planner` converts steps into a `libgraph` DAG based on argument dependencies
44+
3. **Execute** - `Reactor.Executor` processes the DAG, running async-ready steps concurrently
45+
4. **Compensate/Undo** - On failure, steps are compensated then previously successful steps are undone
46+
47+
### Key Modules
48+
49+
- `Reactor` (`lib/reactor.ex`) - Main API: `run/4`, `undo/3`
50+
- `Reactor.Step` (`lib/reactor/step.ex`) - Step behaviour with callbacks: `run/3`, `compensate/4`, `undo/4`, `backoff/4`
51+
- `Reactor.Dsl` (`lib/reactor/dsl.ex`) - Spark DSL definition
52+
- `Reactor.Executor` (`lib/reactor/executor.ex`) - DAG execution engine
53+
- `Reactor.Planner` (`lib/reactor/planner.ex`) - Converts steps to execution graph
54+
- `Reactor.Builder` (`lib/reactor/builder/`) - Programmatic reactor construction
55+
56+
### Step Types (lib/reactor/step/)
57+
58+
Built-in steps for common patterns:
59+
- `AnonFn` - Anonymous function steps (used by DSL `run fn ... end`)
60+
- `Compose` - Embed sub-reactors
61+
- `Map` - Process collections with nested steps
62+
- `Switch` - Conditional branching
63+
- `Group` - Shared before_all/after_all hooks
64+
- `Around` - Wrap step execution (e.g., transactions)
65+
- `Recurse` - Iterative/recursive patterns
66+
67+
### Argument System
68+
69+
Arguments define step dependencies and data flow:
70+
- `input(:name)` - Reference reactor input
71+
- `result(:step_name)` - Reference another step's result
72+
- `value(static)` - Static value
73+
- `element(:map_step)` - Current element in Map context
74+
75+
Dependencies are automatically resolved from argument sources to build the execution graph.
76+
77+
### DSL Transformation Pipeline
78+
79+
1. DSL entities defined in `lib/reactor/dsl/` sections
80+
2. `Reactor.Dsl.Transformer` converts DSL to `Reactor.Step` structs
81+
3. `Reactor.Dsl.Verifier` validates configuration (return exists, no cycles, etc.)
82+
83+
## Testing Patterns
84+
85+
Tests use `ExUnit` with `async: true` where possible. Test support modules are in `test/support/`:
86+
- `Example.Step.*` - Sample step implementations for testing
87+
- Step modules can be tested in isolation using `Builder.new_step!/4`
88+
89+
For deterministic testing of concurrent workflows, use `async?: false` on steps.
90+
91+
## Conventions
92+
93+
- Uses [conventional commits](https://www.conventionalcommits.org/) for changelog generation
94+
- REUSE compliant licensing (SPDX headers in all files)
95+
- Spark DSL formatter configured in `.formatter.exs`
96+
- Documentation follows Diátaxis framework (tutorials, how-to, explanation, reference)

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

0 commit comments

Comments
 (0)