How Hyperstack Works
Hyperstack is a declarative data layer for Solana. You define the data shape you need, and Hyperstack handles all the infrastructure to stream it to your app in real-time.
The Problem
Section titled “The Problem”Building data pipelines for Solana apps is painful:
- Manual parsing - You write custom code to decode accounts and instructions
- ETL complexity - You build pipelines to transform, aggregate, and store data
- RPC overhead - You manage websocket connections, retries, and state sync
- Type mismatches - On-chain types don’t match your app types
Most teams spend weeks on infrastructure before shipping features.
The Hyperstack Solution
Section titled “The Hyperstack Solution”Instead of building infrastructure, you declare what data you need:
#[entity(name = "Token")]pub struct Token { #[from_instruction(Create::mint, primary_key)] pub mint: String,
#[map(BondingCurve::virtual_sol_reserves)] pub sol_reserves: u64,
#[aggregate(from = Buy, field = amount, strategy = Sum)] pub total_volume: u64,}Hyperstack then:
- Subscribes to the relevant on-chain events
- Transforms raw data into your entity shape
- Streams updates to your app in real-time
- Generates type-safe SDKs for your frontend
Architecture Overview
Section titled “Architecture Overview”+-------------------------------------------------------------+| YOUR SPEC || (Rust macros defining entities, mappings, aggregates) |+-------------------------------------------------------------+ |+-------------------------------------------------------------+| HYPERSTACK CLOUD || || +------------+ +------------+ +------------+ || | Compiler | -> | VM | -> | Streamer | || +------------+ +------------+ +------------+ || ^ ^ | || AST Bytecode State Tables WebSocket || || +----------------------------------------------------+ || | Yellowstone gRPC | || | (Real-time Solana data feed) | || +----------------------------------------------------+ |+-------------------------------------------------------------+ |+-------------------------------------------------------------+| YOUR APP || || const { data } = stack.views.tokens.list.use() || |+-------------------------------------------------------------+Key Concepts
Section titled “Key Concepts”1. Streams
Section titled “1. Streams”A stream is a declarative definition of your data model. Written in Rust using macros:
#[hyperstack(idl = "parser/idl.json")]pub mod my_stream { #[entity(name = "Token")] pub struct Token { // Entity fields with mappings... }}The stream defines:
- Entities - The data structures you want
- Mappings - How on-chain data maps to fields
- Aggregations - How to compute derived values
- Events - Which instructions to capture
2. Entities
Section titled “2. Entities”An entity is a structured object representing on-chain state. Each entity has:
- Primary key - Unique identifier (usually a pubkey)
- Fields - Data attributes with population strategies
- Sections - Logical groupings of fields
#[entity(name = "Token")]pub struct Token { pub id: TokenId, // Primary key section pub info: TokenInfo, // Metadata section pub trading: Trading, // Metrics section}3. Mappings
Section titled “3. Mappings”Mappings define how on-chain data flows into entity fields:
| Mapping Type | Source | Example |
|---|---|---|
#[map] | Account field | #[map(BondingCurve::reserves)] |
#[from_instruction] | Instruction arg/account | #[from_instruction(Create::mint)] |
#[snapshot] | Account snapshot | #[snapshot(from = Account)] |
#[derive_from] | Derive from instruction | #[derive_from(from = Buy, field = user)] |
#[aggregate] | Computed from events | #[aggregate(from = Buy, strategy = Sum)] |
#[event] | Captured instruction | #[event(strategy = Append)] |
#[computed] | Derived from fields | #[computed(field_a + field_b)] |
4. Population Strategies
Section titled “4. Population Strategies”Strategies control how field values are updated:
| Strategy | Behavior |
|---|---|
SetOnce | Set once, never overwrite |
LastWrite | Always use latest value |
Append | Collect into array |
Sum | Running total |
Count | Event counter |
UniqueCount | Count unique values |
Max / Min | Track extremes |
5. Stacks
Section titled “5. Stacks”A stack is the client-side interface to your spec. It provides:
- Views - Real-time data subscriptions
- Transactions - Instruction builders
- Helpers - Utility functions
const TokenStack = defineStack({ name: 'my-tokens', views: { tokens: { list: createListView<Token>('Token/list'), state: createStateView<Token>('Token/state'), } }});Data Flow
Section titled “Data Flow”Specification Time
Section titled “Specification Time”- Write spec using Rust macros
- Build generates AST (
.hyperstack/*.ast.json) - Deploy with
hyperstack up - Cloud compiles AST to bytecode
Runtime
Section titled “Runtime”- Solana events arrive via Yellowstone gRPC
- VM routes events to handlers
- Handlers execute bytecode:
- Extract fields from events
- Resolve primary keys
- Apply mappings and transforms
- Update state tables
- Changes stream to connected clients
Client
Section titled “Client”- Connect to WebSocket
- Subscribe to views
- Receive real-time updates
- React components re-render automatically
View Modes
Section titled “View Modes”| Mode | Path | Returns | Use Case |
|---|---|---|---|
state | Entity/state | Single entity | Get by key |
list | Entity/list | Array of entities | All entities |
kv | Entity/kv | Key-value map | Lookup by key |
// List - all tokens as arrayconst { data: tokens } = stack.views.tokens.list.use()
// State - single token by keyconst { data: token } = stack.views.tokens.state.use({ key: mintAddress })Type Safety
Section titled “Type Safety”Hyperstack provides end-to-end type safety:
- Spec types - Rust ensures valid mappings at compile time
- Generated types - SDK types match your entity definitions
- Runtime types - Data arrives pre-shaped, no parsing needed
// TypeScript knows token.mint is string, token.volume is bigintconst { data: token } = stack.views.tokens.state.use({ key })console.log(token.mint) // stringconsole.log(token.volume) // bigintSelf-Hosting vs Managed
Section titled “Self-Hosting vs Managed”| Aspect | Self-Hosted | Managed (Hyperstack Cloud) |
|---|---|---|
| Setup | Bring your own Geyser gRPC | Zero config |
| Scaling | You manage | We handle |
| Cost | Infrastructure only | Subscription + bandwidth |
| Best for | Single stream, experimentation | Production apps |
Next Steps
Section titled “Next Steps”- React Quickstart - Build your first app
- Stack API - Client-side API reference
- Creating Specs - Create custom data streams
- CLI Commands - Deployment and management