A comprehensive Node.js/TypeScript backend service for the CS3203 project, providing RESTful APIs for a service marketplace platform.
- User Management: Registration, authentication, and profile management
- Service Providers: Provider profiles, verification, and service offerings
- Companies: Company management for service providers
- Services & Categories: Service listings with categorization
- Service Requests: Customer service booking system
- Payments: Stripe integration for secure payments
- Reviews & Ratings: Customer and service reviews
- Notifications: Real-time notifications and email services
- Admin Panel: Administrative controls and analytics
- Chatbot: AI-powered customer support
- Scheduling: Appointment and service scheduling
- File Uploads: AWS S3 integration for image/document storage
- Real-time Communication: WebSocket support for live updates
- Message Queue: RabbitMQ for asynchronous processing
- Load Testing: Comprehensive performance testing with Artillery and K6
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT with bcrypt hashing
- Payments: Stripe API
- File Storage: AWS S3
- Email Service: AWS SES
- Message Queue: RabbitMQ (AMQP)
- Geospatial: PostGIS extensions
- Testing: Jest with Supertest
- Load Testing: Artillery, K6
- Process Management: PM2
- Development: Nodemon, tsx
- Node.js (v18+ recommended)
- PostgreSQL database
- RabbitMQ server (optional, for email queue)
- AWS account (for S3 and SES)
- Stripe account (for payments)
-
Clone the repository
git clone https://github.com/CS3203-Project/backend.git cd backend -
Install dependencies
npm install # or pnpm install -
Environment Setup
cp .env.example .env # Edit .env with your configuration -
Database Setup
# Generate Prisma client npx prisma generate # Run database migrations npx prisma migrate dev # Seed the database (optional) npm run seed
Create a .env file based on .env.example:
# Database
DATABASE_URL=postgresql://user:password@host:port/database?sslmode=require
# JWT
JWT_SECRET=your_jwt_secret_here
# AWS Configuration
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
AWS_REGION=eu-north-1
AWS_S3_BUCKET_NAME=your_bucket_name
# Server
PORT=3000
FRONTEND_URL=http://localhost:5173
# Email Configuration
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USER=your_email@example.com
MAIL_PASS=your_email_password
MAIL_FROM="Zia" <no-reply@Zia.com>
# RabbitMQ
RABBITMQ_URL=amqps://user:password@host/vhost
# Stripe (for payments)
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...npm run devnpm run build
npm startnpm run pm2:start
npm run pm2:logs
npm run pm2:stopnpm test
npm run test:watch
npm run test:coveragenpm run test:integration
npm run test:integration:watchnpm run test:admin
npm run test:admin:watchnpm run test:apinpm run test:perf# Basic load test
npm run load:artillery
# Stress test
npm run load:artillery:stress
# Spike test
npm run load:artillery:spike
# User registration test
npm run load:artillery:user-reg
# Generate report
npm run load:artillery:report# Load test
npm run load:k6
# Stress test
npm run load:k6:stress
# Spike test
npm run load:k6:spike
# Soak test
npm run load:k6:soak
# User registration test
npm run load:k6:user-regbackend/
├── src/
│ ├── Admin/ # Admin panel controllers and routes
│ ├── controllers/ # API controllers
│ ├── middlewares/ # Express middlewares
│ ├── modules/ # Feature modules (chatbot, etc.)
│ ├── routes/ # API routes
│ ├── services/ # Business logic services
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ └── validators/ # Input validation schemas
├── prisma/
│ ├── schema.prisma # Database schema
│ ├── seed.ts # Database seeding
│ └── migrations/ # Database migrations
├── tests/ # Test files
├── load-tests/ # Load testing configurations
├── scripts/ # Utility scripts
├── jmeter/ # JMeter test files
└── coverage/ # Test coverage reports
POST /api/users/register- User registrationPOST /api/users/login- User loginPOST /api/users/logout- User logout
GET /api/users/profile- Get user profilePUT /api/users/profile- Update user profile
GET /api/providers- List providersGET /api/providers/:id- Get provider detailsPUT /api/providers/:id- Update provider profile
GET /api/services- List servicesPOST /api/services- Create serviceGET /api/services/:id- Get service detailsPUT /api/services/:id- Update service
GET /api/categories- List categoriesGET /api/categories/:id- Get category details
POST /api/service-requests- Create service requestGET /api/service-requests- List user requestsPUT /api/service-requests/:id- Update request
POST /api/payments/create-session- Create payment sessionPOST /api/payments/webhook- Stripe webhookGET /api/payments/:id- Get payment details
POST /api/reviews- Create reviewGET /api/reviews/:targetId- Get reviewsPUT /api/reviews/:id- Update review
GET /api/notifications- Get user notificationsPUT /api/notifications/:id/read- Mark as read
GET /api/admin/dashboard- Admin dashboardGET /api/admin/users- User managementGET /api/admin/providers- Provider management
POST /api/chatbot/message- Send message to chatbot
POST /api/schedule- Create scheduleGET /api/schedule- Get schedulesPUT /api/schedule/:id- Update schedule
The application uses PostgreSQL with PostGIS extensions for geospatial data. Key models include:
- User: User accounts and profiles
- ServiceProvider: Service provider information
- Company: Company details for providers
- Service: Service offerings
- Category: Service categories
- ServiceRequest: Customer service requests
- Payment: Payment transactions
- Review: User reviews and ratings
- Notification: System notifications
- Schedule: Appointment scheduling
- Message: User messaging system
- JWT authentication with refresh tokens
- Password hashing with bcrypt
- Rate limiting (30-minute windows)
- CORS configuration
- Input validation with Joi
- SQL injection prevention via Prisma
- XSS protection
- Secure file upload validation
- Database connection pooling
- Query optimization with indexes
- Caching strategies
- Rate limiting
- Load balancing ready
- Comprehensive monitoring and logging
# Database operations
npm run seed # Seed database
npx prisma studio # Open Prisma Studio
npx prisma migrate dev # Run migrations
npx prisma generate # Generate Prisma client
# Code quality
npm run build # Build TypeScript
npm run test:coverage # Run tests with coverage
# Load testing
npm run load:artillery:report # Generate Artillery report-
Build the application
npm run build
-
Set production environment variables
-
Run database migrations
npx prisma migrate deploy
-
Start with PM2
npm run pm2:start
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
This project is licensed under the ISC License.
For support, please contact the development team or create an issue in the repository.