# focus1010/txpilot architecture

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

- Interactive diagram: https://gitdiagram.com/focus1010/txpilot
- Repository: https://github.com/focus1010/txpilot

## Overview

#### Purpose and Public Entry Points

txpilot is a Node.js/TypeScript library that makes Solana transaction submission resilient: it selects a priority tip, signs and submits a caller-built transaction, tracks outcome, classifies failures, and retries when safe. The public package surface is exported from `src/index.ts`; the primary API is `SmartTx` in `src/SmartTx.ts`. Consumers construct it with RPC/wallet configuration and call `send()`.

#### Smart Transaction Orchestrator

`SmartTx` is the control-plane owner for a send attempt and retry loop. It accepts a prebuilt `@solana/web3.js` transaction plus an optional lifecycle callback, obtains current network context, applies a decision, submits through the appropriate path, and returns a non-throwing typed result. It owns resource cleanup through `disconnect()`.
- `src/SmartTx.ts`
- `src/types.ts`
- `src/index.ts`

#### Typed Domain Contract

The library’s boundary with consumers is a typed protocol: configuration, tip/retry controls, transaction status updates, send results, failure types, and adapter decision shapes. This keeps lifecycle callbacks and terminal results structured rather than exposing raw Solana/Jito errors.
- `src/types.ts`
- `src/constants.ts`

#### Network Snapshot and Tip Decision Stage

Before submission, the orchestration flow collects Solana/Jito conditions such as slot, congestion, and tip-floor percentiles. A pluggable decision adapter converts that context into a tip and retry-oriented strategy. Default operation uses deterministic rules; AI mode is represented as an alternate adapter boundary.
- `src/adapters/rule-based.ts`
- `src/adapters/ai.ts`
- `src/SmartTx.ts`

#### Submission Boundary: Solana RPC vs. Jito

Transactions are built by the application but signed/submitted by txpilot using the configured wallet. On mainnet, the sender chooses Jito bundle submission during an eligible leader window; otherwise it uses standard Solana RPC. This isolates external transport behavior from application transaction construction.
- `src/SmartTx.ts`
- `src/constants.ts`
- `src/types.ts`

External services include a user-provided Solana RPC endpoint (for example Helius), Jito block-engine/tip-floor endpoints on mainnet, and optionally Groq or Anthropic for AI decisions. `@solana/web3.js` is the peer runtime dependency; Node.js 20+ is the execution runtime.

#### Lifecycle Tracking and Consumer Notifications

After dispatch, the sender tracks the transaction through submitted, processed, confirmed, and finalized states. It emits `StatusUpdate` events through the caller callback, allowing integrations such as bots to report progress without implementing their own polling/control flow. Yellowstone gRPC configuration is an advanced tracking boundary, though the README identifies streaming integration as roadmap work.
- `src/SmartTx.ts`
- `src/types.ts`

#### Failure Classification and Retry Control

Raw submission, simulation, bundle, RPC, and confirmation failures pass through a classifier into a finite typed failure taxonomy. The orchestrator uses that result to abort unsafe retries (for example instruction or funds errors) or retry recoverable conditions with exponential backoff, a refreshed blockhash, and/or a raised tip. Terminal failure returns an actionable reason and suggestion rather than throwing.
- `src/classifier/index.ts`
- `src/SmartTx.ts`
- `src/constants.ts>

#### Integration Examples

Examples demonstrate the intended outer boundary: applications retain transaction composition and user interaction, while txpilot handles delivery. The basic sender is the minimal library integration; the Telegram example maps lifecycle events and final results into chat responses.
- `examples/basic-send.ts`
- `examples/telegram-bot.ts`

Main entry points: [`src/SmartTx.ts`](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts) (SmartTx), [`src/index.ts`](https://github.com/focus1010/txpilot/blob/main/src/index.ts) (Package exports), [`src/adapters/rule-based.ts`](https://github.com/focus1010/txpilot/blob/main/src/adapters/rule-based.ts) (Rule-based adapter), [`src/adapters/ai.ts`](https://github.com/focus1010/txpilot/blob/main/src/adapters/ai.ts) (AI adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_consumer["Applications"]
  node_basic_example["Basic sender example<br/>[basic-send.ts]"]
  node_telegram_example["Telegram bot example<br/>[telegram-bot.ts]"]
end

subgraph group_library["txpilot Library"]
  node_public_api["Package exports<br/>public API<br/>[index.ts]"]
  node_smart_tx["SmartTx<br/>orchestrator<br/>[SmartTx.ts]"]
  node_domain_types["Typed domain contract<br/>types<br/>[types.ts]"]
  node_constants["Policy constants<br/>[constants.ts]"]
  node_network_snapshot["Network snapshot<br/>decision input<br/>[SmartTx.ts]"]
  node_rule_adapter["Rule-based adapter<br/>decision adapter<br/>[rule-based.ts]"]
  node_ai_adapter["AI adapter<br/>decision adapter<br/>[ai.ts]"]
  node_submission["Signing and submission<br/>transport selector<br/>[SmartTx.ts]"]
  node_tracking["Lifecycle tracking<br/>status tracker<br/>[SmartTx.ts]"]
  node_classifier["Failure classifier<br/>failure taxonomy<br/>[index.ts]"]
  node_retry_control["Safe retry control<br/>retry loop<br/>[SmartTx.ts]"]
end

subgraph group_external["External Services"]
  node_solana_rpc[("Solana RPC<br/>external RPC")]
  node_jito[("Jito services<br/>external service")]
  node_ai_providers{{"Groq / Anthropic<br/>AI provider"}}
  node_wallet_web3{{"Wallet + web3.js<br/>peer runtime"}}
end

node_basic_example -->|"uses"| node_public_api
node_telegram_example -->|"uses"| node_public_api
node_public_api -->|"exports"| node_smart_tx
node_smart_tx -->|"accepts and returns"| node_domain_types
node_smart_tx -->|"collects"| node_network_snapshot
node_network_snapshot -->|"queries"| node_solana_rpc
node_network_snapshot -->|"reads tip floors"| node_jito
node_smart_tx -->|"uses by default"| node_rule_adapter
node_smart_tx -.->|"uses optionally"| node_ai_adapter
node_rule_adapter -->|"applies"| node_constants
node_ai_adapter -.->|"requests decisions"| node_ai_providers
node_smart_tx -->|"dispatches"| node_submission
node_submission -->|"signs with"| node_wallet_web3
node_submission -->|"standard path"| node_solana_rpc
node_submission -->|"eligible bundle path"| node_jito
node_smart_tx -->|"tracks outcome"| node_tracking
node_tracking -->|"confirms status"| node_solana_rpc
node_tracking -->|"emits status updates"| node_domain_types
node_smart_tx -->|"classifies failures"| node_classifier
node_classifier -->|"determines safety"| node_retry_control
node_retry_control -->|"retries or returns terminal result"| node_smart_tx
node_retry_control -->|"uses backoff policy"| node_constants

click node_basic_example "https://github.com/focus1010/txpilot/blob/main/examples/basic-send.ts"
click node_telegram_example "https://github.com/focus1010/txpilot/blob/main/examples/telegram-bot.ts"
click node_public_api "https://github.com/focus1010/txpilot/blob/main/src/index.ts"
click node_smart_tx "https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts"
click node_domain_types "https://github.com/focus1010/txpilot/blob/main/src/types.ts"
click node_constants "https://github.com/focus1010/txpilot/blob/main/src/constants.ts"
click node_network_snapshot "https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts"
click node_rule_adapter "https://github.com/focus1010/txpilot/blob/main/src/adapters/rule-based.ts"
click node_ai_adapter "https://github.com/focus1010/txpilot/blob/main/src/adapters/ai.ts"
click node_submission "https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts"
click node_tracking "https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts"
click node_classifier "https://github.com/focus1010/txpilot/blob/main/src/classifier/index.ts"
click node_retry_control "https://github.com/focus1010/txpilot/blob/main/src/SmartTx.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_basic_example,node_telegram_example toneBlue
class node_public_api,node_smart_tx,node_domain_types,node_constants,node_network_snapshot,node_rule_adapter,node_ai_adapter,node_submission,node_tracking,node_classifier,node_retry_control toneAmber
class node_solana_rpc,node_jito,node_ai_providers,node_wallet_web3 toneMint
```

## Components

### Applications

- [Basic sender example](https://github.com/focus1010/txpilot/blob/main/examples/basic-send.ts): example · `examples/basic-send.ts`
- [Telegram bot example](https://github.com/focus1010/txpilot/blob/main/examples/telegram-bot.ts): example · Maps lifecycle events and results to chat responses. · `examples/telegram-bot.ts`

### txpilot Library

- [Package exports](https://github.com/focus1010/txpilot/blob/main/src/index.ts): public API · `src/index.ts`
- [SmartTx](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts): orchestrator · Owns send attempts, retry control, tracking, and cleanup. · `src/SmartTx.ts`
- [Typed domain contract](https://github.com/focus1010/txpilot/blob/main/src/types.ts): types · Configuration, status updates, results, failures, and adapter decisions. · `src/types.ts`
- [Policy constants](https://github.com/focus1010/txpilot/blob/main/src/constants.ts): policy · Tip and retry controls. · `src/constants.ts`
- [Network snapshot](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts): decision input · Collects slot, congestion, and Jito tip-floor conditions. · `src/SmartTx.ts`
- [Rule-based adapter](https://github.com/focus1010/txpilot/blob/main/src/adapters/rule-based.ts): decision adapter · Default deterministic tip and retry strategy. · `src/adapters/rule-based.ts`
- [AI adapter](https://github.com/focus1010/txpilot/blob/main/src/adapters/ai.ts): decision adapter · Optional AI-backed decision boundary. · `src/adapters/ai.ts`
- [Signing and submission](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts): transport selector · Uses the configured wallet and selects RPC or eligible Jito bundles. · `src/SmartTx.ts`
- [Lifecycle tracking](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts): status tracker · Emits submitted through finalized updates. · `src/SmartTx.ts`
- [Failure classifier](https://github.com/focus1010/txpilot/blob/main/src/classifier/index.ts): failure taxonomy · Converts raw transport and confirmation errors into typed failures. · `src/classifier/index.ts`
- [Safe retry control](https://github.com/focus1010/txpilot/blob/main/src/SmartTx.ts): retry loop · Backs off, refreshes blockhashes, and raises tips only when safe. · `src/SmartTx.ts`

### External Services

- **Solana RPC**: external RPC · User-provided endpoint for standard submission and network context.
- **Jito services**: external service · Block-engine bundle submission and tip-floor data on mainnet.
- **Groq / Anthropic**: AI provider · Optional providers for AI decisions.
- **Wallet + web3.js**: peer runtime · Signs caller-built Solana transactions.

## Connections

- Basic sender example → Package exports: uses
- Telegram bot example → Package exports: uses
- Package exports → SmartTx: exports
- SmartTx → Typed domain contract: accepts and returns
- SmartTx → Network snapshot: collects
- Network snapshot → Solana RPC: queries
- Network snapshot → Jito services: reads tip floors
- SmartTx → Rule-based adapter: uses by default
- SmartTx → AI adapter: uses optionally
- Rule-based adapter → Policy constants: applies
- AI adapter → Groq / Anthropic: requests decisions
- SmartTx → Signing and submission: dispatches
- Signing and submission → Wallet + web3.js: signs with
- Signing and submission → Solana RPC: standard path
- Signing and submission → Jito services: eligible bundle path
- SmartTx → Lifecycle tracking: tracks outcome
- Lifecycle tracking → Solana RPC: confirms status
- Lifecycle tracking → Typed domain contract: emits status updates
- SmartTx → Failure classifier: classifies failures
- Failure classifier → Safe retry control: determines safety
- Safe retry control → SmartTx: retries or returns terminal result
- Safe retry control → Policy constants: uses backoff policy
