# rileycreighton/barterbook architecture

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

- Interactive diagram: https://gitdiagram.com/rileycreighton/barterbook
- Repository: https://github.com/rileycreighton/barterbook

## Overview

BarterBook is a wallet-driven Solana exchange app for exact token baskets and three-person cycles. Participants browse inventory, agree to shared terms, review fee-aware net amounts, authenticate and sign the same reconstructed transaction; the server verifies and submits it, then provides recovery and public receipts. The graph includes the documented optional mint-only demo faucet and durable signing. Some domain wiring is established by the README and SOURCE INDEX rather than complete source excerpts; unsampled implementation details are not inferred.

Main entry points: [`src/server/settlement.ts`](https://github.com/rileycreighton/barterbook/blob/main/src/server/settlement.ts) (Transaction settlement), [`src/client/App.tsx`](https://github.com/rileycreighton/barterbook/blob/main/src/client/App.tsx) (Exchange interface), [`src/server/index.ts`](https://github.com/rileycreighton/barterbook/blob/main/src/server/index.ts) (API router), [`src/shared/transactions.ts`](https://github.com/rileycreighton/barterbook/blob/main/src/shared/transactions.ts) (Transaction protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser experience"]
  node_app["Exchange interface<br/>[App.tsx]"]
  node_trade["Trade views<br/>[TradeViews.tsx]"]
  node_wallet["Wallet signing<br/>[wallet.ts]"]
  node_api["API client<br/>[api.ts]"]
  node_guides["Walkthrough and guides<br/>[DemoGuide.tsx]"]
  node_public["Public history and receipts<br/>[PublicHistory.tsx]"]
end

subgraph group_exchange["Offers and matching"]
  node_server["API router<br/>[index.ts]"]
  node_auth["Wallet authentication<br/>[auth.ts]"]
  node_board["Inventory and rooms<br/>[board.ts]"]
  node_database[("D1 database<br/>[db.ts]")]
end

subgraph group_settlement["Signing and settlement"]
  node_chain["Devnet asset checks<br/>[chain.ts]"]
  node_settle["Transaction settlement<br/>[settlement.ts]"]
  node_nonce["Durable signing<br/>[nonce.ts]"]
  node_faucet["Demo token faucet<br/>[demo-faucet.ts]"]
end

subgraph group_shared["Shared protocol"]
  node_matcher["Cycle matching<br/>[matcher.ts]"]
  node_amounts["Integer fee arithmetic<br/>[amounts.ts]"]
  node_transactions["Transaction protocol<br/>[transactions.ts]"]
  node_receipts["Receipt verification<br/>[receipt.ts]"]
  node_recovery["Recovery evidence<br/>[recovery.ts]"]
  node_nonceprotocol["Nonce operations<br/>[nonce.ts]"]
  node_faucetprotocol["Faucet transaction rules<br/>[demo-faucet.ts]"]
  node_crypto["Cryptographic utilities<br/>[crypto.ts]"]
end

node_participant(("Wallet participant"))
node_solana{{"Solana Devnet"}}

node_participant -->|"uses"| node_app
node_app -->|"renders"| node_trade
node_app -->|"requests"| node_api
node_app -->|"signs with"| node_wallet
node_app -->|"renders"| node_guides
node_app -->|"renders"| node_public
node_api -->|"calls"| node_server
node_server -->|"routes to"| node_auth
node_server -->|"routes to"| node_board
node_server -->|"routes to"| node_settle
node_server -->|"routes to"| node_nonce
node_server -->|"routes to"| node_faucet
node_board -->|"reads and writes"| node_database
node_nonce -->|"reads and writes"| node_database
node_settle -->|"journals"| node_database
node_board -->|"uses"| node_matcher
node_settle -->|"verifies through"| node_chain
node_chain -->|"checks RPC"| node_solana
node_settle -->|"submits and recovers"| node_solana
node_nonce -->|"checks chain state"| node_chain
node_faucet -->|"uses"| node_chain
node_wallet -->|"connects wallet"| node_solana
node_trade -->|"previews fees"| node_amounts
node_trade -->|"validates terms"| node_transactions
node_wallet -->|"verifies signed bytes"| node_transactions
node_wallet -->|"verifies nonce"| node_nonceprotocol
node_wallet -->|"verifies faucet wire"| node_faucetprotocol
node_settle -->|"verifies signatures"| node_transactions
node_settle -->|"builds evidence"| node_receipts
node_settle -->|"records observations"| node_recovery
node_nonce -->|"builds operations"| node_nonceprotocol
node_faucet -->|"reconstructs transactions"| node_faucetprotocol
node_transactions -->|"checks raw amounts"| node_amounts
node_transactions -->|"verifies signatures"| node_crypto
node_receipts -->|"computes deltas"| node_amounts
node_receipts -->|"decodes transactions"| node_transactions
node_receipts -->|"checks evidence"| node_crypto
node_public -->|"loads history"| node_api
node_public -->|"renders receipts"| node_trade

click node_app "https://github.com/rileycreighton/barterbook/blob/main/src/client/App.tsx"
click node_trade "https://github.com/rileycreighton/barterbook/blob/main/src/client/TradeViews.tsx"
click node_wallet "https://github.com/rileycreighton/barterbook/blob/main/src/client/wallet.ts"
click node_api "https://github.com/rileycreighton/barterbook/blob/main/src/client/api.ts"
click node_guides "https://github.com/rileycreighton/barterbook/blob/main/src/client/DemoGuide.tsx"
click node_public "https://github.com/rileycreighton/barterbook/blob/main/src/client/PublicHistory.tsx"
click node_server "https://github.com/rileycreighton/barterbook/blob/main/src/server/index.ts"
click node_auth "https://github.com/rileycreighton/barterbook/blob/main/src/server/auth.ts"
click node_board "https://github.com/rileycreighton/barterbook/blob/main/src/server/board.ts"
click node_matcher "https://github.com/rileycreighton/barterbook/blob/main/src/shared/matcher.ts"
click node_chain "https://github.com/rileycreighton/barterbook/blob/main/src/server/chain.ts"
click node_settle "https://github.com/rileycreighton/barterbook/blob/main/src/server/settlement.ts"
click node_nonce "https://github.com/rileycreighton/barterbook/blob/main/src/server/nonce.ts"
click node_faucet "https://github.com/rileycreighton/barterbook/blob/main/src/server/demo-faucet.ts"
click node_database "https://github.com/rileycreighton/barterbook/blob/main/src/server/db.ts"
click node_amounts "https://github.com/rileycreighton/barterbook/blob/main/src/shared/amounts.ts"
click node_transactions "https://github.com/rileycreighton/barterbook/blob/main/src/shared/transactions.ts"
click node_receipts "https://github.com/rileycreighton/barterbook/blob/main/src/shared/receipt.ts"
click node_recovery "https://github.com/rileycreighton/barterbook/blob/main/src/shared/recovery.ts"
click node_nonceprotocol "https://github.com/rileycreighton/barterbook/blob/main/src/shared/nonce.ts"
click node_faucetprotocol "https://github.com/rileycreighton/barterbook/blob/main/src/shared/demo-faucet.ts"
click node_crypto "https://github.com/rileycreighton/barterbook/blob/main/src/shared/crypto.ts"

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_app,node_trade,node_wallet,node_api,node_guides,node_public toneBlue
class node_server,node_auth,node_board,node_database toneAmber
class node_chain,node_settle,node_nonce,node_faucet toneMint
class node_matcher,node_amounts,node_transactions,node_receipts,node_recovery,node_nonceprotocol,node_faucetprotocol,node_crypto toneRose
class node_participant,node_solana toneIndigo
```

## Components

### Browser experience

- [Exchange interface](https://github.com/rileycreighton/barterbook/blob/main/src/client/App.tsx): `src/client/App.tsx`
- [Trade views](https://github.com/rileycreighton/barterbook/blob/main/src/client/TradeViews.tsx): `src/client/TradeViews.tsx`
- [Wallet signing](https://github.com/rileycreighton/barterbook/blob/main/src/client/wallet.ts): `src/client/wallet.ts`
- [API client](https://github.com/rileycreighton/barterbook/blob/main/src/client/api.ts): `src/client/api.ts`
- [Walkthrough and guides](https://github.com/rileycreighton/barterbook/blob/main/src/client/DemoGuide.tsx): `src/client/DemoGuide.tsx`
- [Public history and receipts](https://github.com/rileycreighton/barterbook/blob/main/src/client/PublicHistory.tsx): `src/client/PublicHistory.tsx`

### Offers and matching

- [API router](https://github.com/rileycreighton/barterbook/blob/main/src/server/index.ts): `src/server/index.ts`
- [Wallet authentication](https://github.com/rileycreighton/barterbook/blob/main/src/server/auth.ts): `src/server/auth.ts`
- [Inventory and rooms](https://github.com/rileycreighton/barterbook/blob/main/src/server/board.ts): `src/server/board.ts`
- [D1 database](https://github.com/rileycreighton/barterbook/blob/main/src/server/db.ts): `src/server/db.ts`

### Signing and settlement

- [Devnet asset checks](https://github.com/rileycreighton/barterbook/blob/main/src/server/chain.ts): `src/server/chain.ts`
- [Transaction settlement](https://github.com/rileycreighton/barterbook/blob/main/src/server/settlement.ts): `src/server/settlement.ts`
- [Durable signing](https://github.com/rileycreighton/barterbook/blob/main/src/server/nonce.ts): `src/server/nonce.ts`
- [Demo token faucet](https://github.com/rileycreighton/barterbook/blob/main/src/server/demo-faucet.ts): `src/server/demo-faucet.ts`

### Shared protocol

- [Cycle matching](https://github.com/rileycreighton/barterbook/blob/main/src/shared/matcher.ts): `src/shared/matcher.ts`
- [Integer fee arithmetic](https://github.com/rileycreighton/barterbook/blob/main/src/shared/amounts.ts): `src/shared/amounts.ts`
- [Transaction protocol](https://github.com/rileycreighton/barterbook/blob/main/src/shared/transactions.ts): `src/shared/transactions.ts`
- [Receipt verification](https://github.com/rileycreighton/barterbook/blob/main/src/shared/receipt.ts): `src/shared/receipt.ts`
- [Recovery evidence](https://github.com/rileycreighton/barterbook/blob/main/src/shared/recovery.ts): `src/shared/recovery.ts`
- [Nonce operations](https://github.com/rileycreighton/barterbook/blob/main/src/shared/nonce.ts): `src/shared/nonce.ts`
- [Faucet transaction rules](https://github.com/rileycreighton/barterbook/blob/main/src/shared/demo-faucet.ts): `src/shared/demo-faucet.ts`
- [Cryptographic utilities](https://github.com/rileycreighton/barterbook/blob/main/src/shared/crypto.ts): `src/shared/crypto.ts`

### Other components

- **Wallet participant**
- **Solana Devnet**

## Connections

- Wallet participant → Exchange interface: uses (evidence: `README.md`)
- Exchange interface → Trade views: renders (evidence: `src/client/App.tsx`)
- Exchange interface → API client: requests (evidence: `src/client/App.tsx`)
- Exchange interface → Wallet signing: signs with (evidence: `src/client/App.tsx`)
- Exchange interface → Walkthrough and guides: renders (evidence: `src/client/App.tsx`)
- Exchange interface → Public history and receipts: renders (evidence: `src/client/App.tsx`)
- API client → API router: calls (evidence: `README.md`)
- API router → Wallet authentication: routes to (evidence: `src/server/index.ts`)
- API router → Inventory and rooms: routes to (evidence: `src/server/index.ts`)
- API router → Transaction settlement: routes to (evidence: `src/server/index.ts`)
- API router → Durable signing: routes to (evidence: `src/server/index.ts`)
- API router → Demo token faucet: routes to (evidence: `src/server/index.ts`)
- Inventory and rooms → D1 database: reads and writes (evidence: `src/server/board.ts`)
- Durable signing → D1 database: reads and writes (evidence: `src/server/nonce.ts`)
- Transaction settlement → D1 database: journals (evidence: `README.md`)
- Inventory and rooms → Cycle matching: uses (evidence: `src/server/index.ts`)
- Transaction settlement → Devnet asset checks: verifies through (evidence: `src/server/settlement.ts`)
- Devnet asset checks → Solana Devnet: checks RPC (evidence: `README.md`)
- Transaction settlement → Solana Devnet: submits and recovers (evidence: `README.md`)
- Durable signing → Devnet asset checks: checks chain state (evidence: `src/server/nonce.ts`)
- Demo token faucet → Devnet asset checks: uses (evidence: `src/server/demo-faucet.ts`)
- Wallet signing → Solana Devnet: connects wallet (evidence: `README.md`)
- Trade views → Integer fee arithmetic: previews fees (evidence: `src/client/TradeViews.tsx`)
- Trade views → Transaction protocol: validates terms (evidence: `src/client/TradeViews.tsx`)
- Wallet signing → Transaction protocol: verifies signed bytes (evidence: `src/client/wallet.ts`)
- Wallet signing → Nonce operations: verifies nonce (evidence: `src/client/wallet.ts`)
- Wallet signing → Faucet transaction rules: verifies faucet wire (evidence: `src/client/wallet.ts`)
- Transaction settlement → Transaction protocol: verifies signatures (evidence: `src/server/settlement.ts`)
- Transaction settlement → Receipt verification: builds evidence (evidence: `src/server/settlement.ts`)
- Transaction settlement → Recovery evidence: records observations (evidence: `src/server/settlement.ts`)
- Durable signing → Nonce operations: builds operations (evidence: `src/server/nonce.ts`)
- Demo token faucet → Faucet transaction rules: reconstructs transactions (evidence: `src/server/demo-faucet.ts`)
- Transaction protocol → Integer fee arithmetic: checks raw amounts (evidence: `src/shared/transactions.ts`)
- Transaction protocol → Cryptographic utilities: verifies signatures (evidence: `src/shared/transactions.ts`)
- Receipt verification → Integer fee arithmetic: computes deltas (evidence: `src/shared/receipt.ts`)
- Receipt verification → Transaction protocol: decodes transactions (evidence: `src/shared/receipt.ts`)
- Receipt verification → Cryptographic utilities: checks evidence (evidence: `src/shared/receipt.ts`)
- Public history and receipts → API client: loads history (evidence: `src/client/PublicHistory.tsx`)
- Public history and receipts → Trade views: renders receipts (evidence: `src/client/PublicHistory.tsx`)
