How usainbluntmx/paykit works
1. Repository shape
- This is a three-part Solana dApp repo:
- programs/paykit contains the on-chain Anchor program in Rust.
- sdk contains the JavaScript/TypeScript client, tests, and an autonomous agent demo.
- frontend contains the Next.js app for the landing page, docs, and dashboard.
- The root also includes shared build/deploy config such as Anchor.toml, Rust toolchain settings, and workspace manifests.
2. Core architecture: on-chain accountability layer
- The central system is the Solana program, not the frontend.
- PayKit models each agent as an on-chain PDA account tied to an owner wallet.
- The program is responsible for enforcing spend limits, daily limits, expiration, activation state, and payment history invariants at the protocol level.
3. Smart contract boundary
- programs/paykit/src/lib.rs is the trust boundary for all spending logic.
- The contract exposes instructions for:
- registering an agent
- recording a payment
- agent-to-agent payment
- updating spend limits
- deactivating agents
- renewing agents
- Any client-side SDK or UI is a convenience layer; spending constraints are enforced only by the program.
4. State model
- The main persisted account is AgentAccount, which stores:
- owner, name, and PDA metadata
- spend limit and total spent
- payment count
- active/inactive flag
- daily spend and daily reset timestamp
- last payment timestamp
- expiration timestamp
- This account is the source of truth for agent identity and budget status.
5. Payment flow
- A typical flow is:
1. the owner registers an agent PDA
2. the agent spends through record_payment or agent_to_agent_payment
3. the program checks total budget, daily budget, active status, and expiration
4. the contract updates counters and emits on-chain activity for later indexing
- Batch payment is implemented as a higher-level capability in the SDK and UI, but the actual enforcement still depends on the underlying program instructions.
6. SDK as the application-facing layer
- sdk/src/index.js is the main client abstraction for developers.
- It wraps Solana/Anchor interactions into operations like register, pay, renew, estimate fee, fetch agents, and read history.
- sdk/src/types.ts provides type definitions for consumers.
- sdk/src/errors.js centralizes program/client error handling.
- The SDK is the integration layer for bots, services, and automation workflows.
7. Agent automation demo
- sdk/src/agent-demo.js is a real autonomous-agent example rather than a library primitive.
- It uses Anthropic API access plus the PayKit SDK to:
- inspect on-chain state
- decide to delegate work
- execute payment transactions
- verify results
- This demonstrates the intended integration pattern: AI decides, Solana enforces, the SDK mediates.
8. Frontend responsibilities
- frontend is a Next.js app with three visible surfaces:
- / landing page
- /docs documentation
- /dashboard live demo / audit UI
- It is presentation and interaction only; it does not own business rules.
- The frontend likely reads the IDL from frontend/public/idl/paykit.json, which is the bridge between the UI and the Anchor program interface.
9. Dashboard data flow
- The dashboard is the main operational UI for inspecting agents and payment history.
- Its architecture is centered on:
- wallet connection
- querying on-chain agent accounts by PDA
- rendering payment activity and expiration status
- showing audit/history views for arbitrary agents
- Because the state lives on Solana, the dashboard is effectively an index-and-display client over chain data.
10. Contract-to-frontend coupling
- The IDL file in frontend/public/idl/paykit.json is the explicit compatibility boundary between the Rust program and the web UI.
- When the contract interface changes, the IDL must be regenerated/copied so the frontend and SDK can continue to interpret instructions and account layouts correctly.
11. Testing and validation
- sdk/src/__tests__/paykit.test.js contains unit tests for SDK behavior.
- sdk/src/test.js is an integration test against Devnet.
- tests/paykit.ts suggests additional TypeScript-level integration or harness testing around the program or SDK.
- The repo therefore validates both client logic and live-chain behavior.
12. Deployment/runtime context
- The architecture is built around Solana Devnet for development, with mainnet support planned/possible through the SDK.
- Anchor 0.31.1 is the contract framework and build/deploy system.
- The frontend is a Next.js application, while the SDK runs in Node.js and can be used in scripts, services, or agent runtimes.
13. Important system boundaries
- On-chain boundary: all authoritative state and spend enforcement.
- Client boundary: SDK and frontend, which initiate transactions and display state.
- External AI boundary: Anthropic-powered demo agent, which can make decisions but cannot bypass on-chain constraints.
- Indexing/audit boundary: history is derived from on-chain events and queried by the dashboard.
14. What to draw in an architecture diagram
- Draw Solana as the center with the PayKit program and agent PDAs.
- Connect the SDK as the primary transaction client.
- Connect the Next.js dashboard/docs/landing page as the human-facing layer, reading the IDL and chain state.
- Connect the Anthropic-based demo as an external AI consumer of the SDK.
- Show tests and deployment tooling around the repo, but outside the runtime path.
Main entry points: lib.rs PayKit Program · index.js SDK Core · page.tsx Dashboard · app Next.js App
Components 18
On-chain Core
Anchor program and Solana state that enforce PayKit spending rules.
- Solana · Execution and state layer where PayKit accounts and transactions live.
- PayKit Program · Trust boundary for registration, payments, limits, renewal, and deactivation.
programs/paykit/src/lib.rs - Agent Account · Persistent source of truth for agent identity, limits, activity, and payment history.
- Spend Rules · Enforces total spend, daily limits, expiration, activation state, and invariants.
programs/paykit/src/lib.rs - Payment Events · Recorded activity used for later indexing and audit views.
SDK Layer
Developer-facing client, automation demo, and tests.
- SDK Core · Main JavaScript client abstraction for developers and services.
sdk/src/index.js - Types · Consumer-facing type definitions for SDK integration.
sdk/src/types.ts - Error Layer · Centralized mapping and handling for program and client errors.
sdk/src/errors.js - Agent Demo · Anthropic-powered autonomous agent example that delegates work and executes payments.
sdk/src/agent-demo.js - SDK Tests · Unit and integration checks for SDK behavior and live-chain flows.
sdk/src/__tests__/paykit.test.js - Devnet Test · Live Solana test script against development network behavior.
sdk/src/test.js
Web App
Next.js surfaces for landing, docs, and dashboard.
- Next.js App · Human-facing frontend shell for landing, docs, and dashboard.
frontend/app - Landing · Public marketing and entry page.
frontend/app/page.tsx - Docs · Documentation surface for the PayKit product and protocol.
frontend/app/docs/page.tsx - Dashboard · Operational UI for inspecting agents, payments, and expiration status.
frontend/app/dashboard/page.tsx - Program IDL · Compatibility boundary between the Rust program and UI/client code.
frontend/public/idl/paykit.json
Repo Infra
Workspace, build, and deployment configuration.
- Workspace · Root manifests, Anchor config, and Rust toolchain settings.
Cargo.toml - Program Tests · Additional TypeScript-level testing around program or SDK behavior.
tests/paykit.ts
Connections 23
- Solana → PayKit Program: hosts · Solana executes the PayKit contract and stores its accounts.
- PayKit Program → Agent Account: owns · The program creates and updates the agent PDA state.
- PayKit Program → Spend Rules: enforces · All spend and lifecycle checks are enforced in-program.
- PayKit Program → Payment Events: emits · Successful activity becomes chain data for later indexing.
- SDK Core → PayKit Program: invokes · Client operations submit Anchor/Solana transactions to the program.
- SDK Core → Agent Account: reads · The SDK fetches agent state and history from chain accounts.
- SDK Core → Types: exports · Type definitions support downstream consumers.
- SDK Core → Error Layer: uses · Client calls normalize failures through shared error handling.
- Agent Demo → SDK Core: drives · The autonomous demo uses the SDK to inspect state and pay.
- Agent Demo → Spend Rules: respects · The demo can decide, but enforcement still comes from the contract.
- SDK Tests → SDK Core: verifies · Unit tests validate SDK behavior.
- Devnet Test → PayKit Program: exercises · Integration testing runs against live Devnet contract behavior.
- Next.js App → Landing: contains · The web app exposes a public landing surface.
- Next.js App → Docs: contains · The web app exposes documentation pages.
- Next.js App → Dashboard: contains · The web app exposes the live operational dashboard.
- Dashboard → Program IDL: loads · The dashboard uses the IDL to interpret accounts and instructions.
- Dashboard → Agent Account: queries · The UI reads on-chain agent state for display and audit.
- Dashboard → Payment Events: renders · History and audit views are derived from on-chain events.
- Program IDL → PayKit Program: matches · The IDL mirrors the program interface and account layout.
- Workspace → PayKit Program: builds · Root config drives Anchor/Rust contract builds and deployment.
- Workspace → Next.js App: builds · Root workspace also supports the frontend application.
- Workspace → SDK Core: packages · Workspace manifests and package config support the SDK.
- Program Tests → PayKit Program: checks · Additional TypeScript harness tests the program or client boundary.