Skip to content

mehara-rothila/SportsBookSL_back

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SportsBookSL Backend

Sports Facility Booking Platform API - Sri Lanka

🌐 Live Site: https://spiritx.mehara.io/

πŸ“‹ Overview

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.

✨ Features

  • 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

πŸ› οΈ Tech Stack

  • 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

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites

  • Node.js (v14.0.0 or later)
  • MongoDB (local or Atlas)
  • npm or yarn

Installation

  1. Clone the repository:

    git clone https://github.com/mehara-rothila/SportsBookSL_back.git
    cd SportsBookSL_back
  2. Install dependencies:

    npm install
    # or
    yarn install
  3. Create a .env file 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>"
    

Running the Server

npm start
# or
yarn start

For development with hot reload:

npm run dev
# or
yarn dev

The server will run on the port specified in your .env file (default: 5001) and will be accessible at http://localhost:5001.

🌦️ AI-Powered Weather Assistant

The backend provides robust support for SportsBookSL's cutting-edge AI-powered weather assistant:

  • Comprehensive Weather API Integration: The weatherController.js manages 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.

πŸ“ API Documentation

Authentication Endpoints

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

Facility Endpoints

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)

Booking Endpoints

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

Trainer Endpoints

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)

Donation Endpoints

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

Financial Aid Endpoints

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)

Weather Endpoints

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

πŸ” Environment Variables

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 Members

Team Name: Xforce

  • Mehara Rothila - Team Leader
  • Aditha Buwaneka
  • Dinith Edirisinghe
  • Piyumi Imasha

πŸ“„ License

This project is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors