Skip to content

NavRaah/navRaah_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚌 navRaah Backend

Node.js Express MongoDB License: ISC

A robust backend service for navRaah, a comprehensive bus tracking and scheduling application. Built with modern Node.js technologies to provide seamless transit management capabilities.

✨ Features

  • πŸ” Secure Authentication - JWT-based auth with refresh tokens
  • 🚌 Bus Management - Complete CRUD operations for bus fleet
  • πŸ—ΊοΈ Route Planning - Dynamic route creation and management
  • πŸ“… Schedule Management - Flexible scheduling system
  • πŸ’¬ Feedback System - User feedback collection and management
  • πŸ›‘ Stop Management - Bus stop creation and tracking
  • πŸ‘₯ User-Bus Relations - Link users with specific buses
  • πŸ“§ Email Integration - Password recovery via email

πŸ—οΈ Architecture

navRaah_backend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.js           # Application entry point
β”‚   β”œβ”€β”€ controllers/        # Business logic layer
β”‚   β”‚   β”œβ”€β”€ UserController.js
β”‚   β”‚   β”œβ”€β”€ BusController.js
β”‚   β”‚   β”œβ”€β”€ RouteController.js
β”‚   β”‚   β”œβ”€β”€ FeedbackController.js
β”‚   β”‚   β”œβ”€β”€ ScheduleController.js
β”‚   β”‚   β”œβ”€β”€ UserBusController.js
β”‚   β”‚   └── StopController.js
β”‚   β”œβ”€β”€ routes/            # API route definitions
β”‚   β”œβ”€β”€ models/            # MongoDB schemas
β”‚   └── middleware/        # Authentication & validation
β”œβ”€β”€ .env                   # Environment variables
β”œβ”€β”€ package.json
└── README.md

πŸš€ Quick Start

Prerequisites

Ensure you have the following installed:

  • Node.js v18 or higher
  • MongoDB (Local installation or MongoDB Atlas)
  • npm or yarn package manager

Installation

  1. Clone the repository

    git clone https://github.com/vansh-000/navRaah_backend.git
    cd navRaah_backend
  2. Install dependencies

    npm install
  3. Environment configuration

    Create a .env file in the root directory:

    # Server Configuration
    PORT=5000
    NODE_ENV=development
    
    # Database
    MONGO_URI=mongodb://localhost:27017/navraah
    # Or for MongoDB Atlas:
    # MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/navraah
    
    # JWT Configuration
    JWT_SECRET=your_super_secure_jwt_secret_key_here
    JWT_REFRESH_SECRET=your_super_secure_refresh_secret_key_here
    JWT_EXPIRES_IN=15m
    JWT_REFRESH_EXPIRES_IN=7d
    
    # Email Configuration (for password reset)
    EMAIL_USER=your_email@example.com
    EMAIL_PASS=your_app_specific_password
    EMAIL_SERVICE=gmail
  4. Start the server

    # Development mode with auto-reload
    npm run dev
    
    # Production mode
    npm start

The server will start on http://localhost:5000 (or your specified PORT).

πŸ“š API Documentation

πŸ” Authentication Endpoints

Method Endpoint Description Auth Required
POST api/users/register Create new user account ❎
POST api/users/login User authentication ❎
POST api/users/refresh-token Refresh access token βœ…
POST api/users/logout Clear authentication tokens βœ…
POST api/users/forgot-password Send password reset email ❎
POST api/users/reset-password Reset password with token βœ…

πŸ‘€ User Management

Method Endpoint Description Auth Required
GET api/users/me Get current user profile βœ…
PUT api/users/me Update user profile βœ…
DELETE api/usersme Delete user account βœ…

🚌 Bus Management

Method Endpoint Description Auth Required
POST api/bus Add new bus βœ…
PUT api/bus/:id Update bus details βœ…
DELETE api/bus/:id Delete bus βœ…
GET api/bus Get all buses ❎
GET api/bus/:id Get bus by identifier ❎

πŸ—ΊοΈ Route Management

Method Endpoint Description Auth Required
POST /api/route Create new route βœ…
PUT /api/route/:id Update route βœ…
DELETE /api/route/:id Delete route βœ…
GET /api/route Get all routes ❎
GET /api/route/:id Get route by identifier ❎

πŸ“… Schedule Management

Method Endpoint Description Auth Required
POST api/schedule Create new schedule βœ…
PUT api/schedule/:scheduleId Update schedule βœ…
DELETE api/schedule/:scheduleId Delete schedule βœ…
GET api/schedule Get all schedules ❎
GET api/schedule/bus/:busId Get schedules by bus ❎
GET api/schedule/route/:routeId Get schedules by route ❎
GET api/schedule/:scheduleId Get schedule by ID ❎
GET api/schedule//bus/:busId/route/:routeId Get schedule by Bus and Route ❎

πŸ’¬ Feedback System

Method Endpoint Description Auth Required
POST api/feedback Submit feedback βœ…
PUT api/feedback/:feedbackId Update feedback βœ…
DELETE api/feedback/:feedbackId Delete feedback βœ…
GET api/feedback Get all feedback ❎
GET api/feedback/user/:userId Get user's feedback ❎

πŸ›‘ Stop Management

Method Endpoint Description Auth Required
POST api/stop Add new stop βœ…
PUT api/stop/:id Update stop βœ…
DELETE api/stop/:id Delete stop βœ…
GET api/stop Get all stops ❎
GET api/stop/:id Get stop by ID ❎

πŸ‘₯ User-Bus Relations

Method Endpoint Description Auth Required
POST api/userBus Link user with bus βœ…
PUT api/userBus/:userId Update user-bus relation βœ…
DELETE api/userBus/:userId Remove user-bus link βœ…
GET api/userBus Get all user-bus relations ❎
GET api/userBus/:userId Get user's linked buses ❎

πŸ› οΈ Technology Stack

Backend Framework

  • Node.js - JavaScript runtime environment
  • Express.js - Web application framework
  • Mongoose - MongoDB object modeling

Database

  • MongoDB - NoSQL document database
  • MongoDB Atlas - Cloud database service (optional)

Authentication & Security

  • JWT (jsonwebtoken) - Token-based authentication
  • bcrypt - Password hashing
  • cookie-parser - Cookie parsing middleware
  • cors - Cross-origin resource sharing

Email Service

  • Nodemailer - Email sending functionality
  • Gmail SMTP - Email service provider

Development Tools

  • Nodemon - Development server with auto-restart
  • dotenv - Environment variable management

πŸ”§ Configuration

Environment Variables

Variable Description Required Default
PORT Server port number No 5000
MONGODB_URI MongoDB connection string Yes -
REFRESH_TOKEN_SECRET Refresh token secret Yes -
REFRESH_TOKEN_EXPIRY Refresh token expiry Yes 10d
ACCESS_TOKEN_SECRET Access token secret Yes -
ACCESS_TOKEN_EXPIRY Access token expiry Yes 1d
FRONTEND_URL URL of the frontend Yes http://localhost:3000
CORS_ORIGIN CORS URL Yes -
SMTP_MAIL Email service username Yes -
SMTP_APP_PASS Email service password Yes -
SMTP_HOST Email service host Yes smtp.gmail.com
SMTP_PORT Email service port Yes 587

Database Schema

The application uses the following main collections:

  • users - User account information
  • buses - Bus fleet data
  • routes - Route definitions
  • schedules - Bus schedules
  • stops - Bus stop locations
  • feedback - User feedback
  • userbuses - User-bus relationships

πŸ“¦ Package Scripts

{
  "scripts": {
    "start": "node src/server.js",
    "dev": "nodemon src/server.js",
    "test": "jest",
    "lint": "eslint src/",
    "lint:fix": "eslint src/ --fix"
  }
}

πŸš€ Deployment

Production Deployment Steps

  1. Set environment variables

    export NODE_ENV=production
    export MONGO_URI=your_production_mongodb_uri
    export JWT_SECRET=your_production_jwt_secret
    # ... other variables
  2. Install production dependencies

    npm ci --only=production
  3. Start the application

    npm start

Docker Deployment (Optional)

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Commit your changes
    git commit -m 'Add amazing feature'
  4. Push to the branch
    git push origin feature/amazing-feature
  5. Open a Pull Request

Code Standards

  • Follow ESLint configuration
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed

πŸ“ˆ Performance & Monitoring

  • Database Indexing - Optimized queries with proper indexes
  • Request Validation - Input validation middleware
  • Error Handling - Comprehensive error handling system
  • Logging - Structured logging for debugging

πŸ› Troubleshooting

Common Issues

Connection Errors

# Check MongoDB connection
mongosh "your_connection_string"

# Verify environment variables
echo $MONGO_URI

Authentication Issues

# Check JWT token expiry
# Verify JWT_SECRET is set correctly

Email Service Errors

# Verify email credentials
# Check app-specific password for Gmail

πŸ“ž Support

πŸ‘₯ Contributors

Profile Name GitHub Role
Vansh Verma @vansh-000 Backend Admin and Developer
Sneha Kumari @Snehaaa-Kri Backend Developer
Srishti Sethi @srishtisethi28 Backend Developer

πŸ‘¨β€πŸ’» Readme Author

Vansh Verma


⭐ Star this repository if you find it helpful!

Made with ❀️ for the transit community

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors