Architecture Overview
Synapse SDK is built with a layered architecture that separates high-level application APIs from low-level protocol interactions. Understanding this structure helps you use the SDK effectively and troubleshoot issues.System Architecture
The Filecoin Onchain Cloud stack consists of multiple layers:SDK Package Structure
The SDK is organized into focused modules:@filoz/synapse-sdk
High-level SDK for application developers.@filoz/synapse-core
Low-level protocol library built on viem.Core Classes
Synapse
Main entry point providing unified access to all services. File:packages/synapse-sdk/src/synapse.ts
- Auto-detects network from chain ID
- Manages service instances
- Handles session key delegation
- Provides unified error handling
StorageManager
Orchestrates multi-copy uploads and SP-agnostic downloads. File:packages/synapse-sdk/src/storage/manager.ts
- Provider selection (endorsed primary + approved secondaries)
- Multi-copy orchestration (store → pull → commit)
- Failure handling and retries
- Context caching and reuse
StorageContext
Represents a specific provider + data set pair. File:packages/synapse-sdk/src/storage/context.ts
- Fine-grained control over upload flow
- Multiple files to same provider (batch commits)
- Custom provider selection
- Split operations for efficiency
PaymentsService
Manages deposits, withdrawals, and operator approvals. File:packages/synapse-sdk/src/payments/service.ts
Data Flow
Understanding how data flows through the system:Upload Flow
Download Flow
Contract Interactions
Smart Contract Architecture
Base Layer: Filecoin Pay- Generic payment rails (deposits, withdrawals, operator approvals)
- Rate-based continuous payments
- Settlement and accounting
- Client authentication via EIP-712
- Provider whitelist management
- Payment rail creation
- PDPListener callbacks
- Split into main contract (writes) + StateView (reads)
- Neutral proof verification
- No business logic
- Delegates to service contracts via callbacks
- Curio only talks to PDPVerifier
- Provider registration and metadata
- Product offerings
- Endorsed vs approved providers
Transaction Flow
Design Principles
1. Simple Golden Path
The mainSynapse class provides the simplest API:
2. Composable Components
All services are exported independently for flexibility:3. Environment Agnostic
No Node.js-specific APIs:- Uses
ReadableStreaminstead of Node streams - Uses
fetchinstead ofhttp/https - No
Buffer,fs,path, orprocess - Works in browsers and Node.js
4. Type Safety
Full TypeScript support with strict types:- All options are typed
- Return values are precisely typed
- Error types are exported
5. Failure Transparency
Individual failures don’t throw; they’re reported:Next Steps
Storage Pipeline
Learn the store → pull → commit flow in detail
Multi-Copy Upload
Understand how redundancy works
Provider Selection
How the SDK chooses storage providers
Session Keys
Delegated signing without exposing your main wallet