A robust, scalable backend server built with Express 5, TypeScript, and Bun for a charity donation platform. Provides comprehensive APIs for donation management, multi-gateway payment processing, content management, real-time communication, and more.
- JWT-based authentication with access and refresh tokens
- Role-based access control (SuperAdmin, Admin, Author, Editor, Moderator, Fundraiser)
- Session management with device tracking and automatic cleanup
- Password history tracking and security policies
- Email verification and password reset flows
- Stripe — Card payments with webhook verification
- PayPal — PayPal payments with certificate-based webhook signature validation
- SSLCommerz — Mobile banking and local payment methods (Bangladesh)
- Multi-currency support with automatic exchange rate conversion
- Transaction email notifications (success/failure)
- Payment log cleanup via cron jobs
- Blog management with categories and rich content (EditorJS support)
- News system with categorization and publishing workflow
- Appeal management for donation campaigns
- Campaign and fundraiser management
- Page builder for dynamic content
- History and reports tracking
- Image library with Cloudinary integration
- Multiple donation types and categories
- Zakat calculator
- Donation cards
- Appeal categories with status management
- Donation tracking and reporting
- Others (offline) donation records
- Event creation and management
- Ticket system with registration
- Event participation tracking
- Public namespace (
/public) — Live donation feed, visitor tracking - Admin namespace (
/admin) — Admin notifications, payment status updates (auth required)
- SMTP-based email sending via Nodemailer with retry mechanism
- 10 EJS email templates (verification, password reset, transaction receipts, etc.)
- Failed email fallback with automatic retry via cron job
- Helmet.js for security headers with CSP
- Rate limiting (default, auth, payment — separate strategies)
- CORS configuration with credential support
- Request compression (gzip)
- Input validation with Zod
- Global error handling
- Graceful shutdown
- Health check endpoints (app, database, Redis, memory, process)
- Performance monitoring with configurable intervals
| Layer | Technology |
|---|---|
| Runtime | Bun |
| Framework | Express 5 |
| Language | TypeScript |
| Database | PostgreSQL + Prisma ORM |
| Cache / Pub-Sub | Redis via ioredis |
| Job Queue | BullMQ |
| Real-time | Socket.IO |
| Auth | JWT (jsonwebtoken) + bcrypt |
| File Upload | Cloudinary + Multer |
| Nodemailer + EJS templates | |
| Validation | Zod |
| Security | Helmet, CORS, express-rate-limit |
| Payments | Stripe, PayPal, SSLCommerz |
| Process Manager | PM2 (via ecosystem.config.js) |
- Bun v1.1.29+
- PostgreSQL database
- Redis server
git clone https://github.com/Asadullah246/donation-server.git
cd donationbun installCopy the example env file and fill in your values:
cp .env.example .envSee .env.example for all required variables.
# Generate Prisma client
bun run prisma:generate
# Run migrations
bunx prisma migrate dev --name init
# Seed database (optional)
bun run prisma:seedbun run devThe server will start on http://localhost:8080 (or your configured PORT).
| Script | Description |
|---|---|
bun run dev |
Start development server with hot reload |
bun run build |
Build for production |
bun run start |
Start production server |
bun run prisma:generate |
Generate Prisma client |
bun run prisma:deploy |
Deploy database migrations |
bun run prisma:dev |
Create a new migration |
bun run prisma:seed |
Seed database with initial data |
bun run format |
Format code with Prettier |
bun run format:check |
Check code formatting |
src/
├── app.ts # Express app setup, middleware, routes
├── server.ts # HTTP server bootstrap, Socket.IO init
├── config/ # App, Redis, Cloudinary, Helmet, rate-limit configs
├── modules/ # Feature modules (29 modules)
│ ├── auth/ # Authentication & sessions
│ ├── user/ # User profiles
│ ├── admin/ # Admin management
│ ├── payment/ # Payment processing (Stripe, PayPal, SSLCommerz)
│ │ ├── payment-apis/ # Public payment endpoints
│ │ ├── admin-apis/ # Admin payment endpoints
│ │ ├── webhooks/ # Payment webhook handlers
│ │ └── utils/ # Payment helpers & email services
│ ├── appeal/ # Donation appeals
│ ├── appeal-category/ # Appeal categories
│ ├── donation-type/ # Donation types & options
│ ├── campaigns/ # Campaign management
│ ├── fundraiser/ # Fundraiser pages
│ ├── zakat/ # Zakat calculator
│ ├── blog/ # Blog posts
│ ├── blog-category/ # Blog categories
│ ├── news/ # News articles
│ ├── news-category/ # News categories
│ ├── event/ # Events & tickets
│ ├── pages/ # Dynamic pages
│ ├── history/ # History records
│ ├── reports/ # Reports
│ ├── member/ # Team members
│ ├── supports/ # Contact/support tickets
│ ├── file-uploads/ # Cloudinary file uploads
│ ├── image-library/ # Image library
│ ├── config/ # System configuration
│ ├── metadata/ # Metadata
│ ├── card/ # Donation cards
│ ├── works/ # Works section
│ ├── ambassador-page/ # Ambassador page
│ ├── home-page-config/ # Homepage configuration
│ └── others-donation/ # Offline donation records
├── middlewares/ # Auth, validation, security, error handling
├── utils/ # Helpers (JWT, bcrypt, email, health check, etc.)
├── socket/ # Socket.IO namespaces & handlers
├── queue/ # BullMQ scheduler
├── cron-job/ # Cron jobs (payment log cleanup, email retry)
├── views/ # EJS email templates
├── errors/ # Custom error classes
└── validation/ # Shared validation schemas
All routes are prefixed with /api/v1.
| Route | Module |
|---|---|
/auth |
Authentication (register, login, logout, refresh, password reset) |
/users |
User profiles |
/admin |
Admin management |
/payment |
Public payment endpoints |
/payment-admin |
Admin payment management |
/appeals |
Donation appeals |
/appeal-categories |
Appeal categories |
/donation-type |
Donation types |
/campaigns |
Campaign management |
/fundraisers |
Fundraiser pages |
/zakat |
Zakat calculator |
/blogs |
Blog posts |
/blog-categories |
Blog categories |
/news |
News articles |
/news-categories |
News categories |
/events |
Events & tickets |
/pages |
Dynamic pages |
/history |
History records |
/reports |
Reports |
/members |
Team members |
/contact |
Support tickets |
/file-uploads |
File uploads (Cloudinary) |
/upload |
Image library |
/config |
System configuration |
/metadata |
System metadata |
/cards |
Donation cards |
/works |
Works section |
/ambassador-page |
Ambassador page |
/home-page |
Homepage configuration |
/other-donations |
Offline donation records |
| Endpoint | Description |
|---|---|
GET /health |
Full health check (database, Redis, services) |
GET /health/memory |
Memory usage stats |
GET /health/process |
Process monitoring (CPU, event loop) |
GET /health/redis |
Redis connection status |
# Build image
docker build -t donation .
# Run container
docker run -p 3000:3000 --env-file .env donationThe project includes a docker-compose-swarm.yaml configured with:
- 3 replicas with rolling updates
- Traefik reverse proxy integration
- Health checks
- Auto-restart and rollback policies
docker stack deploy -c docker-compose-swarm.yaml donationpm2 start ecosystem.config.js- Use strong, unique JWT secrets
- Configure production database URL
- Set up Cloudinary credentials
- Configure SMTP credentials for email
- Set up Stripe, PayPal, and/or SSLCommerz credentials
- Configure
DASHBOARD_ORIGINandCLIENT_ORIGINfor production domains - Set
NODE_ENV=production - Set
REDIS_TLS=trueif using managed Redis
- 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
See CONTRIBUTING.md for detailed guidelines.
This project is proprietary. All rights reserved.
Built with ❤️ by Asadullah