Skip to content

Commit 1770825

Browse files
authored
docs: add architecture overview (#1)
1 parent 31a084e commit 1770825

3 files changed

Lines changed: 196 additions & 2 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ detached from the repo (you'll need to re-run after `git pull`).
220220
Each script is a self-contained CLI with `--help`. The skill's
221221
[`SKILL.md`](skills/houdiniswap/SKILL.md) tells the agent when to use which.
222222

223+
## Architecture
224+
225+
This repository is structured as an installable Agent Skill package, not a
226+
long-running service. The main runtime is a thin CLI layer over a shared
227+
HoudiniSwap API client, with a separate chain-verification adapter layer for
228+
EVM, Solana, UTXO, Tron, and explorer-only fallbacks.
229+
230+
See
231+
[`skills/houdiniswap/references/architecture.md`](skills/houdiniswap/references/architecture.md)
232+
for the full architecture overview, Mermaid diagrams, and swap-flow sequence.
233+
223234
## Testing
224235

225236
```bash
@@ -263,9 +274,9 @@ HoudiniSkill/
263274
└── skills/
264275
└── houdiniswap/
265276
├── SKILL.md # the skill's contract / instructions
266-
├── scripts/ # 7 helper CLIs (.mjs, ESM, zero deps)
277+
├── scripts/ # helper CLIs (.mjs, ESM, zero deps)
267278
├── tests/ # 65 offline + 2 opt-in live
268-
└── references/ # auth, private-swap, status-codes, examples, testing
279+
└── references/ # architecture, auth, private-swap, status-codes, examples, testing
269280
```
270281

271282
## SafuSkill submission checklist

skills/houdiniswap/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ registered with any adapter (the JSON output still includes a `note` hint).
330330

331331
## Reference docs
332332

333+
- `references/architecture.md` — overall architecture, code layers, and swap-flow diagrams.
333334
- `references/auth.md` — auth modes and how to obtain credentials.
334335
- `references/private-swap.md` — Private Swap vs No-Wallet vs DEX trade-offs.
335336
- `references/status-codes.md` — order state machine and terminal statuses.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Architecture
2+
3+
HoudiniSkill is an installable Agent Skill package for HoudiniSwap, not a
4+
long-running service. The runtime surface is a set of small Node.js CLI scripts
5+
that an agent can call after reading `SKILL.md`.
6+
7+
## System Overview
8+
9+
```mermaid
10+
flowchart TB
11+
U[User natural-language request] --> A[Agent / Codex / Claude / Cursor]
12+
A --> S[SKILL.md instructions and routing rules]
13+
14+
S --> C[Node CLI scripts]
15+
C --> CL[_client.mjs shared runtime]
16+
17+
CL --> H[HoudiniSwap Partner API v2]
18+
C --> V[Verification CLIs]
19+
V --> AD[Chain adapter layer]
20+
AD --> RPC[Chain RPC / REST / Explorer]
21+
22+
I[install.sh / install.ps1] --> D[Agent skills directories]
23+
T[Node test runner] --> M[Mock API server]
24+
T --> C
25+
```
26+
27+
The important boundary is between the agent and the CLI scripts. The agent
28+
decides which script to run, confirms quote and recipient details with the
29+
user, and reports results. The scripts handle deterministic API calls,
30+
validation, JSON output, and exit codes.
31+
32+
## Code Layers
33+
34+
```mermaid
35+
flowchart LR
36+
subgraph Docs["Docs and agent entrypoint"]
37+
R[README.md]
38+
S[skills/houdiniswap/SKILL.md]
39+
Ref[references/*.md]
40+
end
41+
42+
subgraph CLI["Swap CLIs"]
43+
Search[search-tokens]
44+
Chains[list-chains]
45+
Quote[get-quote]
46+
Create[create-exchange]
47+
Order[get-order / wait-for-order]
48+
Multi[multi-swap]
49+
end
50+
51+
subgraph Runtime["Shared runtime"]
52+
Client[_client.mjs]
53+
Env[.env auto-loading]
54+
Auth[Auth header selection]
55+
Errors[Exit codes and JSON output]
56+
end
57+
58+
subgraph Verify["Verification subsystem"]
59+
Addr[verify-address]
60+
Hash[verify-tx-hash]
61+
Tx[verify-tx-onchain]
62+
ListRpc[list-rpc]
63+
Adapters[EVM / Solana / UTXO / Tron / Explorer-only]
64+
end
65+
66+
Docs --> CLI
67+
CLI --> Runtime
68+
Verify --> Runtime
69+
Tx --> Adapters
70+
```
71+
72+
### Docs and agent entrypoint
73+
74+
- `SKILL.md` is the contract an agent reads to decide when and how to use the
75+
skill.
76+
- `README.md` is the human-facing install, configuration, and repository guide.
77+
- `references/*.md` holds deeper operational notes: auth, private-swap
78+
behavior, status codes, examples, verification, testing, and this
79+
architecture note.
80+
81+
### Swap CLI layer
82+
83+
The swap scripts are intentionally thin:
84+
85+
- `search-tokens.mjs` maps user-friendly symbols/chains to HoudiniSwap token
86+
ObjectIds.
87+
- `list-chains.mjs` discovers supported chain short names and metadata.
88+
- `get-quote.mjs` calls `/quotes` and returns quote data that must be shown to
89+
the user before an order is created.
90+
- `create-exchange.mjs` turns a confirmed quote and recipient address into a
91+
HoudiniSwap order and deposit address.
92+
- `get-order.mjs` and `wait-for-order.mjs` inspect order status.
93+
- `multi-swap.mjs` submits a JSON array of orders to `/exchanges/multi`.
94+
95+
### Shared runtime layer
96+
97+
`scripts/_client.mjs` centralizes behavior that every CLI needs:
98+
99+
- `.env` discovery from the skill directory, ancestor directories, and the
100+
fallback Claude skills path.
101+
- Auth precedence: full API key headers first, public partner-id second.
102+
- URL building, JSON request/response handling, timeout and abort behavior.
103+
- Uniform error classes and stable exit codes.
104+
- `runCli`, the wrapper that gives every script consistent `--help`, JSON
105+
stdout, human-readable stderr, and exit behavior.
106+
107+
### Verification subsystem
108+
109+
Verification scripts protect the user before and after an order:
110+
111+
- `verify-address.mjs` checks recipient address format using the regex returned
112+
by `/v2/chains`.
113+
- `verify-tx-hash.mjs` checks transaction hash format based on `chain.kind`.
114+
- `verify-tx-onchain.mjs` routes chain verification to an adapter.
115+
- `list-rpc.mjs` reports built-in RPC coverage and current environment
116+
overrides without making network calls.
117+
118+
The adapter layer implements the chain-specific mechanics:
119+
120+
- EVM: JSON-RPC receipt/transaction/block queries and ERC-20 `Transfer` log
121+
decoding.
122+
- Solana: `getTransaction` plus native and SPL token balance deltas.
123+
- UTXO: Esplora/mempool.space-compatible REST transaction inspection.
124+
- Tron: trongrid REST and TRC20 transfer events.
125+
- Explorer-only: explicit `MANUAL` or `UNVERIFIABLE` verdicts when automatic
126+
verification would be misleading.
127+
128+
## Swap Flow
129+
130+
```mermaid
131+
sequenceDiagram
132+
participant User
133+
participant Agent
134+
participant CLI as HoudiniSkill CLI
135+
participant API as HoudiniSwap API
136+
participant Chain as Chain RPC/REST
137+
138+
User->>Agent: Swap token A to token B with privacy
139+
Agent->>CLI: search-tokens
140+
CLI->>API: GET /tokens
141+
API-->>CLI: Token ObjectIds
142+
143+
Agent->>CLI: get-quote --from --to --amount
144+
CLI->>API: GET /quotes
145+
API-->>CLI: quoteId / amountOut / expiresAt
146+
147+
Agent->>User: Show quote and request confirmation
148+
User-->>Agent: Confirm recipient address
149+
150+
Agent->>CLI: verify-address
151+
CLI->>API: GET /chains
152+
API-->>CLI: Chain addressValidation regex
153+
CLI-->>Agent: valid / invalid
154+
155+
Agent->>CLI: create-exchange --quote-id --address-to
156+
CLI->>API: POST /exchanges
157+
API-->>CLI: houdiniId / depositAddress
158+
159+
Agent->>User: Show depositAddress for source-chain funding
160+
Agent->>CLI: wait-for-order houdiniId
161+
CLI->>API: Poll GET /orders/{id}
162+
API-->>CLI: done / failed / pending
163+
164+
Agent->>CLI: verify-tx-onchain optional
165+
CLI->>Chain: RPC/REST transaction lookup
166+
Chain-->>CLI: PASS / FAIL / MANUAL / UNVERIFIABLE
167+
```
168+
169+
## Design Principles
170+
171+
- **Zero runtime dependencies.** The skill runs on Node.js v22+ built-ins so it
172+
is easy to install in agent environments.
173+
- **CLI-first.** Every capability is scriptable by an agent or a human.
174+
- **Consistent machine interface.** Successful commands write JSON to stdout;
175+
failures write concise diagnostics to stderr and exit with documented codes.
176+
- **Privacy-first routing.** Natural-language privacy intent maps to
177+
HoudiniSwap Private Swap behavior, not ordinary traceable swap defaults.
178+
- **No false verification.** The skill does not sign, broadcast, or pretend to
179+
verify opaque chains. It returns `MANUAL` or `UNVERIFIABLE` when automatic
180+
verification is not supported.
181+
- **Offline-testable.** Most tests run against a local mock server; live API
182+
smoke tests are opt-in.

0 commit comments

Comments
 (0)