The Stellar Micro-Donation API is a Node.js/Express application that enables micro-donations using the Stellar blockchain network. The system supports one-time donations, recurring donation schedules, and provides analytics on donation patterns.
graph TB
subgraph "Client Layer"
Client[API Clients<br/>Web/Mobile Apps]
end
subgraph "API Layer - Express.js"
Router[Express Router]
DonationRoutes[/donations<br/>Donation Routes]
WalletRoutes[/wallets<br/>Wallet Routes]
StreamRoutes[/stream<br/>Recurring Donations]
StatsRoutes[/stats<br/>Analytics Routes]
end
subgraph "Service Layer"
StellarService[Stellar Service<br/>Blockchain Integration]
MockStellarService[Mock Stellar Service<br/>Testing/Development]
Scheduler[Recurring Donation<br/>Scheduler<br/>Runs every 60s]
end
subgraph "Data Layer"
DB[(SQLite Database<br/>stellar_donations.db)]
Tables[Tables:<br/>- users<br/>- transactions<br/>- recurring_donations]
end
subgraph "External Services"
Stellar[Stellar Network<br/>Testnet/Mainnet]
Horizon[Horizon API<br/>Stellar Gateway]
end
Client -->|HTTP Requests| Router
Router --> DonationRoutes
Router --> WalletRoutes
Router --> StreamRoutes
Router --> StatsRoutes
DonationRoutes -->|Create/Verify| StellarService
WalletRoutes -->|Query Transactions| DB
StreamRoutes -->|Schedule Management| DB
StatsRoutes -->|Analytics Queries| DB
StellarService -->|Submit Transactions| Horizon
MockStellarService -->|Simulate Transactions| DB
Horizon -->|Blockchain Operations| Stellar
Scheduler -->|Check Due Schedules| DB
Scheduler -->|Execute Donations| MockStellarService
Scheduler -->|Record Transactions| DB
DonationRoutes -.->|Development Mode| MockStellarService
StreamRoutes --> Scheduler
style Client fill:#e1f5ff
style Router fill:#fff4e1
style DB fill:#e8f5e9
style Stellar fill:#f3e5f5
style Scheduler fill:#fff9c4
Main Components:
app.js- Application entry point, middleware configuration- Route handlers for different API endpoints
Endpoints:
POST /donations- Create a new donationGET /donations- List all donationsGET /donations/recent- Get recent donationsGET /donations/:id- Get specific donationPOST /donations/verify- Verify transaction on blockchain
POST /wallets- Create wallet metadataGET /wallets- List all walletsGET /wallets/:id- Get specific walletGET /wallets/:publicKey/transactions- Get all transactions for a walletPATCH /wallets/:id- Update wallet metadata
POST /stream/create- Create recurring donation scheduleGET /stream/schedules- List all schedulesGET /stream/schedules/:id- Get specific scheduleDELETE /stream/schedules/:id- Cancel schedule
GET /stats/donations- Get donation statisticsGET /stats/summary- Get summary analytics
- Integrates with Stellar blockchain via Horizon API
- Handles transaction submission and verification
- Manages wallet operations on testnet/mainnet
- Simulates Stellar operations for development/testing
- In-memory transaction storage
- No external network calls required
- Background service that runs every 60 seconds
- Checks for due recurring donation schedules
- Automatically executes donations via Stellar Service
- Updates schedule execution status and next run time
Database Schema:
-- Users table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
publicKey TEXT NOT NULL UNIQUE,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Transactions table
CREATE TABLE transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
senderId INTEGER NOT NULL,
receiverId INTEGER NOT NULL,
amount REAL NOT NULL,
memo TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (senderId) REFERENCES users(id),
FOREIGN KEY (receiverId) REFERENCES users(id)
);
-- Recurring donations table
CREATE TABLE recurring_donations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
donorId INTEGER NOT NULL,
recipientId INTEGER NOT NULL,
amount REAL NOT NULL,
frequency TEXT NOT NULL,
startDate DATETIME DEFAULT CURRENT_TIMESTAMP,
nextExecutionDate DATETIME NOT NULL,
status TEXT DEFAULT 'active',
lastExecutionDate DATETIME,
executionCount INTEGER DEFAULT 0,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (donorId) REFERENCES users(id),
FOREIGN KEY (recipientId) REFERENCES users(id)
);1. Client sends POST /donations
↓
2. Donation Route validates request
↓
3. Stellar Service submits transaction to Horizon API
↓
4. Horizon API processes on Stellar Network
↓
5. Transaction recorded in database
↓
6. Success response returned to client
1. Client sends POST /stream/create
↓
2. Stream Route validates and stores schedule in DB
↓
3. Scheduler checks every 60 seconds for due schedules
↓
4. When schedule is due:
- Scheduler executes donation via Stellar Service
- Transaction recorded in database
- Schedule updated with next execution date
↓
5. Process repeats until schedule is cancelled
1. Client sends GET /wallets/:publicKey/transactions
↓
2. Wallet Route queries database for user
↓
3. Database returns all transactions (sent + received)
↓
4. Response formatted and returned to client
- Runtime: Node.js
- Framework: Express.js
- Database: SQLite3
- Blockchain: Stellar Network (via stellar-sdk)
- Testing: Jest (for unit/integration tests)
- Development Tools: Nodemon, ESLint
- Input Validation: All API endpoints validate input data
- Error Handling: Comprehensive error handling prevents information leakage
- Rate Limiting: Should be implemented for production
- Secret Management: Stellar secret keys should be stored securely (env variables)
- HTTPS: All production traffic should use HTTPS
- CORS: Configure CORS policies for production
┌─────────────────────────────────────────────────────┐
│ Load Balancer │
└─────────────────┬───────────────────────────────────┘
│
┌─────────┴─────────┐
│ │
┌───────▼────────┐ ┌───────▼────────┐
│ API Server 1 │ │ API Server 2 │
│ (Node.js) │ │ (Node.js) │
└───────┬────────┘ └───────┬────────┘
│ │
└─────────┬─────────┘
│
┌─────────▼─────────┐
│ SQLite Database │
│ (or PostgreSQL) │
└───────────────────┘
- Database: For production, consider migrating from SQLite to PostgreSQL or MySQL
- Caching: Implement Redis for frequently accessed data
- Queue System: Use message queue (RabbitMQ/Redis) for async operations
- Horizontal Scaling: Multiple API instances behind load balancer
- Monitoring: Implement logging and monitoring (e.g., Winston, Prometheus)
- WebSocket support for real-time transaction updates
- Multi-currency support
- Advanced analytics dashboard
- Email notifications for recurring donations
- Webhook support for transaction events
- GraphQL API option
- Rate limiting and API key management
- Comprehensive audit logging