A Node.js/Express API for managing micro-donations on the Stellar blockchain network. Supports one-time donations, recurring donation schedules, wallet management, and donation analytics.
- Features
- Architecture
- Getting Started
- Runtime Configuration
- API Endpoints
- Database Schema
- Development
- Testing
- Troubleshooting
- Documentation
- One-Time Donations: Create and verify donations on Stellar testnet/mainnet
- Recurring Donations: Schedule automated recurring donations (daily, weekly, monthly)
- Wallet Management: Track wallets and query transaction history
- Analytics: Get donation statistics and summaries
- API Key Rotation: Zero-downtime key rotation with versioning and graceful deprecation
- Mock Mode: Development mode with simulated Stellar operations
- Debug Mode: Configurable verbose logging for local development troubleshooting
- Failure Simulation: Comprehensive network failure testing for robust error handling
- Automated Scheduler: Background service for executing recurring donations
- Rate Limiting: Protection against abuse with configurable request limits on donation endpoints
- Idempotency: Prevent duplicate transactions with idempotency key support
- Sensitive Data Masking: Automatic masking of secrets, API keys, and private values in all logs
βββββββββββββββ
β Clients β
β (Web/Mobile)β
ββββββββ¬βββββββ
β HTTP/HTTPS
βΌ
βββββββββββββββββββββββββββββββββββ
β Express.js API Layer β
β /donations /wallets /stream β
ββββββββ¬βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Service Layer β
β Stellar Service | Scheduler β
ββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββββ¬βββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ βββββββββββ
β SQLite β β Stellar β β Horizon β
β Database β β Network β β API β
ββββββββββββ ββββββββββββ βββββββββββ
For detailed architecture documentation, see:
- Full Architecture Documentation - Comprehensive diagrams and component details
- Simple Architecture Diagram - ASCII art overview
- API Layer: Express.js routes handling HTTP requests
- Service Layer: Business logic and Stellar blockchain integration
- Data Layer: SQLite database for persistent storage
- Scheduler: Background service for recurring donations (runs every 60s)
- Node.js (v14 or higher)
- npm or yarn
- SQLite3
- Clone the repository:
git clone https://github.com/yourusername/Stellar-Micro-Donation-API.git
cd Stellar-Micro-Donation-API- Install dependencies:
npm install- Initialize the database:
npm run init-db- Start the server:
npm startThe API will be available at http://localhost:3000
For development with auto-reload:
npm run devEnable verbose logging for troubleshooting:
# Add to .env file
DEBUG_MODE=true
# Start server with debug logging
npm startSee Debug Mode Documentation for details.
For comprehensive documentation of runtime environment assumptions, timeouts, retry logic, persistence requirements, background services, and operational procedures, see:
RUNTIME_ASSUMPTIONS.md - Complete runtime environment documentation
This document covers:
- Network Configuration: Timeouts, retry logic, external dependencies
- Persistence Layer: Database paths, storage requirements, backup strategies
- Background Services: Scheduler intervals, service behavior, lifecycle management
- Resource Requirements: Memory, disk, CPU, and network requirements by deployment scale
- Configuration Reference: All environment variables with validation rules
- Production Deployment: Warnings, readiness checklist, monitoring recommendations
- Operational Procedures: Graceful shutdown, troubleshooting guide
For detailed request/response examples with error handling, see the Complete API Examples Documentation.
POST /donations- Create a new donationGET /donations- List all donationsGET /donations/recent?limit=10- Get recent donationsGET /donations/:id- Get specific donationGET /donations/limits- Get donation amount limitsPOST /donations/verify- Verify transaction on blockchainPATCH /donations/:id/status- Update donation status
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/daily- Get daily donation statisticsGET /stats/weekly- Get weekly donation statisticsGET /stats/summary- Get summary analyticsGET /stats/donors- Get donor statisticsGET /stats/recipients- Get recipient statisticsGET /stats/analytics-fees- Get analytics fee summaryGET /stats/wallet/:walletAddress/analytics- Get wallet analytics
GET /transactions- Get paginated transactionsPOST /transactions/sync- Sync wallet transactions from Stellar network
GET /health- API health status
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
publicKey TEXT NOT NULL UNIQUE,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
);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)
);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,
nextExecutionDate DATETIME NOT NULL,
status TEXT DEFAULT 'active',
executionCount INTEGER DEFAULT 0,
FOREIGN KEY (donorId) REFERENCES users(id),
FOREIGN KEY (recipientId) REFERENCES users(id)
);Stellar-Micro-Donation-API/
βββ src/
β βββ config/ # Configuration files
β βββ middleware/ # Express middleware
β βββ routes/ # API route handlers
β β βββ app.js
β β βββ donation.js
β β βββ wallet.js
β β βββ stream.js
β β βββ transaction.js
β β βββ stats.js
β βββ services/ # Business logic services
β β βββ StellarService.js
β β βββ MockStellarService.js
β β βββ RecurringDonationScheduler.js
β βββ scripts/ # Database scripts
β β βββ initDB.js
β βββ utils/ # Utility functions
β βββ database.js
β βββ permissions.js
βββ data/ # SQLite database files
βββ docs/ # Documentation
βββ tests/ # Test files
βββ package.json
The API uses role-based access control (RBAC) with three roles:
| Role | Permissions | Use Case |
|---|---|---|
| admin | All permissions (*) |
System administration, API key management |
| user | donations:, wallets:, stream:, stats:read, transactions: | Standard API operations |
| guest | donations:read, stats:read | Read-only public access |
For detailed permission audit and security hardening, see API Key Permissions Audit.
Create a .env file in the project root:
STELLAR_NETWORK=testnet
HORIZON_URL=https://horizon-testnet.stellar.org
PORT=3000For API key authentication, use the new database-backed system (recommended):
npm run keys:create -- --name "My Key" --role user --expires 365Or use legacy environment-based keys (deprecated):
API_KEYS=your-api-key-hereRequired at startup:
API_KEYS(legacy method, or use database-backed keys)ENCRYPTION_KEY(required only whenNODE_ENV=production)
Validated at startup (if provided):
PORTmust be an integer from 1 to 65535STELLAR_NETWORKmust be one oftestnet,mainnet,futurenetMOCK_STELLARmust betrueorfalseHORIZON_URLmust be a valid URL
The API supports zero-downtime key rotation. See:
- API Key Rotation Guide - Complete documentation
- Quick Start Guide - Common commands
Quick commands:
npm run keys:create -- --name "My Key" --role user --expires 365
npm run keys:list
npm run keys -- deprecate --id 1
npm run keys -- revoke --id 2npm testAll tests are fully isolated and can run independently in any order:
# Run tests in random order to verify isolation
npm test -- --randomize
# Run with specific seed to reproduce order
npm test -- --randomize --seed=123456For detailed information about test isolation, see Test Isolation Guide.
npm run test:coverageThis generates:
- Terminal coverage summary
- HTML report at
coverage/lcov-report/index.html - LCOV report for CI/CD integration
- JSON summary for programmatic access
npm run check-coverageValidates that coverage meets minimum thresholds:
- Branches: 30%
- Functions: 30%
- Lines: 30%
- Statements: 30%
After running coverage, open the HTML report:
# macOS
open coverage/lcov-report/index.html
# Windows
start coverage/lcov-report/index.html
# Linux
xdg-open coverage/lcov-report/index.htmlCoverage is automatically enforced in CI/CD:
- β PRs must meet minimum 30% coverage thresholds
- β Builds fail if coverage drops below thresholds
- π Coverage reports uploaded as artifacts (30-day retention)
For detailed coverage documentation, see Coverage Guide.
npm test -- tests/integration.test.jsComprehensive end-to-end tests for all donation endpoints:
npm test tests/donation-routes-integration.test.jsCoverage: 60+ test cases covering:
- All 7 donation endpoints
- Success and failure scenarios
- Validation, authentication, idempotency
- Rate limiting and error handling
- No live Stellar network required (uses MockStellarService)
For detailed information, see Donation Routes Integration Tests.
node test-recurring-donations.jsThe project includes comprehensive failure simulation for testing network errors and retry logic:
# Run failure simulation tests
npm test tests/stellar-network-failures.test.js
# Run retry logic tests
npm test tests/stellar-retry-logic.test.jsFailure Types Tested:
- Timeouts and network errors
- Service unavailability
- Transaction failures (bad sequence, insufficient fee)
- Rate limiting
- Partial responses
For detailed information, see Stellar Failure Simulation Guide.
Having issues? We've got you covered!
- Server won't start? Check environment:
npm run validate-env - Tests failing? Clear cache:
npx jest --clearCache - Port in use? Kill process:
kill -9 $(lsof -ti:3000) - Dependencies broken? Fresh install:
rm -rf node_modules package-lock.json && npm install
- Missing
.envfile βcp .env.example .env - API keys required β Add
API_KEYS=dev_key_123to.env - Use mock mode for development β
MOCK_STELLAR=true
- Full Troubleshooting Guide - Comprehensive solutions
- Quick Reference - Fast fixes for common problems
- Check GitHub Issues for known problems
- Search Discussions for community help
Enable detailed logging for troubleshooting:
DEBUG_MODE=true LOG_VERBOSE=true npm startThe API can work with both Stellar testnet and mainnet. Configure via environment variables:
- Testnet (default): For development and testing
- Mainnet: For production use
The scheduler runs automatically when the server starts and checks for due donations every 60 seconds. It can be configured in src/services/RecurringDonationScheduler.js.
- API Examples - Complete request/response examples for all endpoints
- Quick Start Guide - Getting started quickly
- Troubleshooting Guide - Solutions for common issues
- Quick Reference - Fast fixes for common problems
- Architecture Documentation - Detailed system architecture
- Versioning Strategy - SemVer rules, release flow, and breaking change policy
- Stellar Failure Simulation - Network failure testing guide
- API Flow Diagram - API request flow
- Mock Stellar Guide - Using mock Stellar service
- Pre-Deployment Checklist - Production deployment verification
- CI Pipeline Documentation - Understanding CI/CD workflows
- Test Coverage Guide - Writing and maintaining tests
New to the project? Check out our Onboarding Checklist for a step-by-step guide to getting started!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Run tests locally (
npm test) - Check coverage (
npm run test:coverage) - Ensure coverage thresholds are met (
npm run check-coverage) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Note: All CI checks must pass before merge, including:
- β All tests passing
- β Coverage thresholds met (30% minimum)
- β Linting checks passed
- β Security checks passed
See Branch Protection and Coverage Guide for details.
This project is licensed under the MIT License.
- Stellar Development Foundation - Blockchain platform
- Stellar SDK - JavaScript SDK for Stellar
For issues and questions:
- Open an issue on GitHub
- Check the documentation
- Review the architecture guide
Built with β€οΈ using Node.js and Stellar
For comprehensive documentation, see the Documentation Index.
- Pre-Deployment Checklist - Production deployment verification
- Quick Start Guide - Get started quickly
- API Examples - Complete API usage examples
- Coverage Guide - Test coverage documentation
- Mock Stellar Guide - Testing without network calls
- Versioning Strategy - SemVer rules, release flow, and breaking change policy