This is a backend implementation for a Linktree-like service with a built-in referral system, user authentication, and rewards.
- User registration and authentication 🔐
- JWT-based authentication 🔑
- Secure password handling (bcrypt) 🔒
- Referral system with unique codes 🔗
- Rewards for successful referrals 🎁
- Password reset with email verification 📧
- Rate limiting for sensitive endpoints 🚦
- CSRF protection 🛡️
- Caching for improved performance ⚡
- Comprehensive test suite 🧪
POST /api/register
- Register a new userPOST /api/login
- Authenticate userPOST /api/forgot-password
- Request password resetPOST /api/reset-password
- Reset password with token
GET /api/referrals
- Get list of referrals made by the userGET /api/referral-stats
- Get statistics about user's referrals
GET /api/rewards
- Get user's rewards
GET /api/csrf-token
- Get CSRF token for secure form submission
- Clone the repository 📂
- Install dependencies:
npm install
- Set up environment variables in
.env
:DATABASE_URL="postgresql://username:password@localhost:5432/linktree" JWT_SECRET="your-secret-key" EMAIL_USER="[email protected]" EMAIL_PASS="your-email-password" FRONTEND_URL="http://localhost:3001" NODE_ENV="development"
- Run database migrations:
npx prisma migrate dev
- Start the server:
npm start
Run the test suite:
npm test
- id (PK)
- email (unique)
- username (unique)
- password_hash
- referral_code (unique)
- created_at
- id (PK)
- referrer_id (FK -> Users.id)
- referred_user_id (FK -> Users.id)
- date_referred
- status (pending, successful, expired)
- id (PK)
- user_id (FK -> Users.id)
- amount
- description
- created_at
- Password hashing with bcrypt 🔒
- JWT tokens for authentication 🔑
- CSRF protection 🛡️
- Rate limiting 🚦
- Secure cookies 🍪
- Input validation ✅
- Error handling
⚠️
- Express - Web framework
- Prisma - ORM for database access
- jsonwebtoken - JWT authentication
- bcryptjs - Password hashing
- express-validator - Input validation
- express-rate-limit - Rate limiting
- nodemailer - Email sending
- jest, supertest - Testing
- node-cache - Caching
- helmet - Security headers
- cors - Cross-Origin Resource Sharing