Skip to content

About

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Donation Server

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.

Features

Authentication & Authorization

  • 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

Payment Processing

  • 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

Content Management

  • 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

Donation & Fundraising

  • Multiple donation types and categories
  • Zakat calculator
  • Donation cards
  • Appeal categories with status management
  • Donation tracking and reporting
  • Others (offline) donation records

Event Management

  • Event creation and management
  • Ticket system with registration
  • Event participation tracking

Real-time Features (Socket.IO)

  • Public namespace (/public) — Live donation feed, visitor tracking
  • Admin namespace (/admin) — Admin notifications, payment status updates (auth required)

Email System

  • 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

Security & Performance

  • 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

Tech Stack

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
Email Nodemailer + EJS templates
Validation Zod
Security Helmet, CORS, express-rate-limit
Payments Stripe, PayPal, SSLCommerz
Process Manager PM2 (via ecosystem.config.js)

Prerequisites

  • Bun v1.1.29+
  • PostgreSQL database
  • Redis server

Quick Start

1. Clone the Repository

git clone https://github.com/Asadullah246/donation-server.git
cd donation

2. Install Dependencies

bun install

3. Environment Setup

Copy the example env file and fill in your values:

cp .env.example .env

See .env.example for all required variables.

4. Database Setup

# Generate Prisma client
bun run prisma:generate

# Run migrations
bunx prisma migrate dev --name init

# Seed database (optional)
bun run prisma:seed

5. Start Development Server

bun run dev

The server will start on http://localhost:8080 (or your configured PORT).

Available Scripts

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

Project Structure

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

API Routes

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

Health Check Endpoints

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

Deployment

Docker

# Build image
docker build -t donation .

# Run container
docker run -p 3000:3000 --env-file .env donation

Docker Swarm (Production)

The 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 donation

PM2

pm2 start ecosystem.config.js

Production Checklist

  • 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_ORIGIN and CLIENT_ORIGIN for production domains
  • Set NODE_ENV=production
  • Set REDIS_TLS=true if using managed Redis

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.

License

This project is proprietary. All rights reserved.


Built with ❤️ by Asadullah

About

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages