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
- API Endpoints
- Database Schema
- Development
- Testing
- 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
- Mock Mode: Development mode with simulated Stellar operations
- 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
βββββββββββββββ
β 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 devPOST /donations- Create a new donationGET /donations- List all donationsGET /donations/recent?limit=10- 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
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
β β βββ stats.js
β βββ services/ # Business logic services
β β βββ StellarService.js
β β βββ MockStellarService.js
β β βββ RecurringDonationScheduler.js
β βββ scripts/ # Database scripts
β β βββ initDB.js
β βββ utils/ # Utility functions
β βββ database.js
βββ data/ # SQLite database files
βββ docs/ # Documentation
βββ tests/ # Test files
βββ package.json
Create a .env file in the project root:
STELLAR_NETWORK=testnet
HORIZON_URL=https://horizon-testnet.stellar.org
PORT=3000
API_KEYS=your-api-key-hereRequired at startup:
API_KEYS(must include at least one comma-separated key)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
Run tests:
npm testRun specific test file:
npm test -- tests/integration.test.jsnode test-recurring-donations.js- Architecture Documentation - Detailed system architecture
- API Flow Diagram - API request flow
- Mock Stellar Guide - Using mock Stellar service
- Quick Start Guide - Getting started quickly
The 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.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
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