A comprehensive backend API for the SubStream Protocol, supporting wallet-based authentication, tier-based content access, real-time analytics, and multi-region storage replication.
- Wallet-based authentication using Sign In With Ethereum
- JWT token generation and validation
- Nonce-based security
- Multi-tier user support (Bronze, Silver, Gold)
- View-time event aggregation
- On-chain withdrawal event tracking
- Heatmap generation for content engagement
- Server-sent events for real-time updates
- Creator analytics dashboard
- IPFS content replication across multiple services
- Automatic failover between regions
- Health monitoring and service recovery
- Support for Pinata, Web3.Storage, and Infura
- Content filtering based on user subscription tier
- Censored previews for unauthorized content
- Database-level access control
- Upgrade suggestions and tier management
- Node.js 16+
- npm or yarn
- Clone the repository:
git clone https://github.com/jobbykings/SubStream-Protocol-Backend.git
cd SubStream-Protocol-Backend- Install dependencies:
npm install- Copy environment variables:
cp .env.example .env- Configure your environment variables in
.env:
- Set your JWT secret
- Add IPFS service API keys
- Configure database connections (optional for development)
- Start the server:
# Development
npm run dev
# Production
npm startThe API will be available at http://localhost:3000
GET /auth/nonce?address={address}- Get nonce for SIWEPOST /auth/login- Authenticate with wallet signature
GET /content- List content (filtered by user tier)GET /content/{id}- Get specific contentPOST /content- Create new content (requires authentication)PUT /content/{id}- Update content (creator only)DELETE /content/{id}- Delete content (creator only)GET /content/{id}/access- Check access permissionsGET /content/upgrade/suggestions- Get upgrade suggestions
POST /analytics/view-event- Record view-time eventPOST /analytics/withdrawal-event- Record withdrawal eventGET /analytics/heatmap/{videoId}- Get content heatmapGET /analytics/creator/{address}- Get creator analyticsGET /analytics/stream/{videoId}- Real-time analytics stream
POST /storage/pin- Pin content to multiple regionsGET /storage/content/{id}- Get content with failoverGET /storage/metadata/{id}- Get content metadataGET /storage/health- Check storage service healthGET /storage/url/{id}- Get content URLs
GET /- API informationGET /health- Health check
// 1. Get nonce
const nonceResponse = await fetch('/auth/nonce?address=0x742d35Cc6634C0532925a3b8D4C9db96C4b4Db45');
const { nonce } = await nonceResponse.json();
// 2. Sign message with wallet
const message = `Sign in to SubStream Protocol at ${new Date().toISOString()}\n\nNonce: ${nonce}\nAddress: 0x742d35Cc6634C0532925a3b8D4C9db96C4b4Db45`;
const signature = await signer.signMessage(message);
// 3. Login
const loginResponse = await fetch('/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ address, signature, message, nonce })
});
const { token } = await loginResponse.json();// Get content list (automatically filtered by tier)
const response = await fetch('/content', {
headers: { 'Authorization': `Bearer ${token}` }
});
const { content } = await response.json();
// Content will be full or censored based on user tier// Record view event
await fetch('/analytics/view-event', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
videoId: 'video_001',
watchTime: 120,
totalDuration: 300
})
});
// Get heatmap
const heatmapResponse = await fetch('/analytics/heatmap/video_001', {
headers: { 'Authorization': `Bearer ${token}` }
});- AuthService: Handles SIWE authentication and JWT management
- ContentService: Manages content with tier-based filtering
- AnalyticsService: Processes real-time analytics and generates heatmaps
- StorageService: Manages multi-region IPFS replication
- Authentication: JWT token validation
- Tier Access: Role-based access control
- Error Handling: Centralized error management
- User authenticates via wallet signature
- JWT token issued with tier information
- All subsequent requests include token
- Content filtered based on user tier
- Analytics events tracked in real-time
- Content replicated across multiple regions
See .env.example for all available configuration options.
npm testβββ routes/ # API route handlers
βββ middleware/ # Express middleware
βββ services/ # Business logic services
βββ docs/ # API documentation
βββ tests/ # Test files
βββ index.js # Main application entry
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions, please open an issue on GitHub.