Sports Facility Booking Platform API - Sri Lanka
π Live Site: https://spiritx.mehara.io/
The backend for SportsBookSL, a comprehensive sports facility booking platform for Sri Lanka. This server provides APIs for user authentication, facility bookings, trainer management, financial aid applications, donations, and more.
- Comprehensive REST API: Full API support for all platform features
- Authentication System: JWT-based secure authentication
- File Upload: Support for uploading profile pictures, facility images, and documents
- Email Notifications: Automated email notifications for various events
- Database Integration: MongoDB integration with Mongoose ODM
- Weather API Integration: External weather data integration with AI analysis
- Error Handling: Robust error handling and reporting
- Middleware: Custom middleware for authentication, error handling, and file uploads
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- File Storage: Local file system (with cloud storage options available)
- Email Service: Brevo SMTP
SportsBookSL-back/
βββ config/ # Configuration files
β βββ db.js # Database connection
βββ controllers/ # Request handlers
β βββ adminController.js
β βββ athleteController.js
β βββ authController.js
β βββ bookingController.js
β βββ categoryController.js
β βββ donationController.js
β βββ facilityController.js
β βββ financialAidController.js
β βββ notificationController.js
β βββ reviewController.js
β βββ testimonialController.js
β βββ trainerApplicationController.js
β βββ trainerController.js
β βββ userController.js
β βββ utilityController.js
β βββ weatherController.js
βββ middleware/ # Express middleware
β βββ authMiddleware.js # Authentication middleware
β βββ errorMiddleware.js # Error handling middleware
β βββ uploadMiddleware.js # File upload middleware
β βββ urlTransformMiddleware.js # URL transformation middleware
βββ models/ # Mongoose data models
β βββ Athlete.js
β βββ Booking.js
β βββ Category.js
β βββ Donation.js
β βββ Facility.js
β βββ FinancialAidApplication.js
β βββ Notification.js
β βββ Review.js
β βββ Testimonial.js
β βββ Trainer.js
β βββ TrainerApplication.js
β βββ User.js
βββ public/ # Public assets and uploads
β βββ uploads/ # Uploaded files
β βββ athletes/
β βββ avatars/
β βββ categories/
β βββ facilities/
β βββ financial_aid_docs/
β βββ testimonials/
β βββ trainers/
βββ routes/ # API routes
β βββ api/ # API route definitions
β β βββ admin.js
β β βββ athletes.js
β β βββ auth.js
β β βββ bookings.js
β β βββ categories.js
β β βββ donations.js
β β βββ facilities.js
β β βββ financialAid.js
β β βββ notifications.js
β β βββ reviews.js
β β βββ testimonials.js
β β βββ trainerApplications.js
β β βββ trainers.js
β β βββ users.js
β β βββ utils.js
β β βββ weather.js
β βββ index.js # Route aggregation
βββ utils/ # Utility functions
β βββ createNotification.js
β βββ sendEmail.js
βββ .env # Environment variables
βββ package.json # Project dependencies
βββ server.js # Main server entry point
- Node.js (v14.0.0 or later)
- MongoDB (local or Atlas)
- npm or yarn
-
Clone the repository:
git clone https://github.com/mehara-rothila/SportsBookSL_back.git cd SportsBookSL_back -
Install dependencies:
npm install # or yarn install -
Create a
.envfile in the root directory with the following variables:NODE_ENV=development PORT=5001 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key JWT_EXPIRE=30d SMTP_USER=your_smtp_username SMTP_PASSWORD=your_smtp_password EMAIL_FROM="Your Name <your_email@example.com>"
npm start
# or
yarn startFor development with hot reload:
npm run dev
# or
yarn devThe server will run on the port specified in your .env file (default: 5001) and will be accessible at http://localhost:5001.
The backend provides robust support for SportsBookSL's cutting-edge AI-powered weather assistant:
-
Comprehensive Weather API Integration: The
weatherController.jsmanages integration with OpenWeather API, retrieving detailed weather data including temperature, precipitation, wind conditions, humidity, and UV index -
Advanced Data Processing Pipeline: Raw weather data undergoes sophisticated processing before being analyzed by Google's Gemini AI:
- Data normalization and formatting
- Time-series analysis for weather patterns
- Location-specific parameter adjustments
- Sport-specific condition evaluation
-
Intelligent Recommendation Engine:
- Evaluates weather suitability scores for different sports
- Considers facility-specific factors (covered areas, drainage systems, lighting)
- Generates time-slot recommendations based on weather forecast
- Identifies and ranks alternative indoor facilities when outdoor conditions are unfavorable
-
REST API Endpoints for Weather Services:
- Current weather conditions by facility location
- Multi-day forecasts with hourly breakdowns
- Sport-specific suitability analyses
- Alternative facility recommendations
- Natural language weather summaries
This system works seamlessly with the frontend's Gemini AI integration to deliver intelligent, context-aware weather guidance to users making sports facility bookings.
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/auth/register |
POST | Register a new user | No |
/api/auth/login |
POST | User login | No |
/api/auth/me |
GET | Get current user profile | Yes |
/api/auth/forgotpassword |
POST | Request password reset | No |
/api/auth/resetpassword |
PUT | Reset password with OTP | No |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/facilities |
GET | Get all facilities | No |
/api/facilities/featured |
GET | Get featured facilities | No |
/api/facilities/:id |
GET | Get a single facility | No |
/api/facilities |
POST | Create a new facility | Yes (Admin) |
/api/facilities/:id |
PUT | Update a facility | Yes (Admin) |
/api/facilities/:id |
DELETE | Delete a facility | Yes (Admin) |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/bookings |
GET | Get user's bookings | Yes |
/api/bookings |
POST | Create a new booking | Yes |
/api/bookings/:id |
GET | Get booking details | Yes |
/api/bookings/:id/status |
PUT | Update booking status | Yes (Admin) |
/api/bookings/:id |
DELETE | Cancel a booking | Yes |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/trainers |
GET | Get all trainers | No |
/api/trainers/:id |
GET | Get a single trainer | No |
/api/trainers |
POST | Create a new trainer | Yes (Admin) |
/api/trainers/:id |
PUT | Update a trainer | Yes (Admin) |
/api/trainers/:id |
DELETE | Delete a trainer | Yes (Admin) |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/donations |
GET | Get all donations | No |
/api/donations |
POST | Create a new donation | Yes |
/api/donations/:id |
GET | Get donation details | No |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/financialAid |
POST | Apply for financial aid | Yes |
/api/financialAid |
GET | Get user's applications | Yes |
/api/financialAid/:id/status |
PUT | Update application status | Yes (Admin) |
| Endpoint | Method | Description | Authentication Required |
|---|---|---|---|
/api/weather/current/:facilityId |
GET | Get current weather for a facility | No |
/api/weather/forecast/:facilityId |
GET | Get weather forecast for a facility | No |
/api/weather/recommendation/:facilityId |
GET | Get booking recommendation | No |
| Variable | Description | Example |
|---|---|---|
| NODE_ENV | Environment mode | development |
| PORT | Server port | 5001 |
| MONGO_URI | MongoDB connection string | [Your MongoDB Connection String] |
| JWT_SECRET | Secret key for JWT | [Your JWT Secret Key] |
| JWT_EXPIRE | JWT token expiration | 30d |
| SMTP_USER | SMTP username | [Your SMTP Username] |
| SMTP_PASSWORD | SMTP password | [Your SMTP Password] |
| EMAIL_FROM | Sender email address | "Your Name your_email@example.com" |
Team Name: Xforce
- Mehara Rothila - Team Leader
- Aditha Buwaneka
- Dinith Edirisinghe
- Piyumi Imasha
This project is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.