RESTful API service for the EduHub After-School Lessons platform, built with Node.js, Express, and MongoDB.
- Node.js (v14+)
- MongoDB Atlas account
- npm or yarn
- Install dependencies:
npm install
- Create a
.env
file:
MONGODB_URI=your_mongodb_connection_string
PORT=3000
NODE_ENV=development
FRONTEND_URL=https://your-frontend-url.github.io
- Start the server:
npm start # Production
npm run dev # Development (with nodemon)
CST3144-Coursework-FullstackDev-BackEnd/
├── controllers/ # Business logic layer
│ ├── lessonController.js
│ └── orderController.js
├── models/ # Data access layer
│ ├── lessonModel.js
│ └── orderModel.js
├── routes/ # API endpoint definitions
│ ├── lessonRoutes.js
│ └── orderRoutes.js
├── middleware/ # Custom middleware
│ ├── errorHandler.js
│ └── validation.js
├── images/ # Static lesson images
├── index.js # Application entry point
├── package.json
└── .env.example
- Helmet.js for security headers
- CORS configured for production
- Rate limiting (100 requests/15 min)
- Input validation with express-validator
- Environment variables for sensitive data
- Compression for response optimization
- Static asset caching
- Connection pooling for MongoDB
- Error recovery with retry logic
- MongoDB transactions for order integrity
- Flexible schema supporting both
space
andspaces
fields - Aggregation pipelines for statistics
GET /api/lessons
- Get all lessons (with filters)GET /api/lessons/:id
- Get single lessonPUT /api/lessons/:id
- Update lessonGET /api/lessons/stats/overview
- Lesson statistics
POST /api/orders
- Create orderGET /api/orders
- List ordersGET /api/orders/:id
- Get order detailsGET /api/orders/stats/overview
- Order statistics
GET /api
- API documentationGET /api/health
- Health check
MONGODB_URI
- MongoDB connection string (required)PORT
- Server port (default: 3000)NODE_ENV
- Environment (development/production)FRONTEND_URL
- Frontend URL for CORS
Lesson Collection:
{
_id: ObjectId,
topic: String,
location: String,
price: Number,
space: Number, // or spaces
image: String
}
Order Collection:
{
_id: ObjectId,
name: String,
phone: String,
lessons: [{
lessonId: ObjectId,
topic: String,
location: String,
price: Number,
quantity: Number,
amount: Number
}],
totalAmount: Number,
status: String,
paymentStatus: String,
createdAt: Date,
updatedAt: Date
}
- Connect GitHub repository
- Set environment variables
- Deploy (auto-deploys on push)
npm run dev
- Health endpoint:
/api/health
- Request logging with Morgan
- Error tracking in console
- MongoDB connection status
# No tests configured yet
npm test
MIT License - Educational Project