Skip to content

chayan-1906/BusGo-Node.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ BusGo Node.js Backend

Node.js TypeScript Express MongoDB AdminJS

Robust Node.js backend for BusGo bus booking application featuring Google OAuth, ticketing logic, secure JWT authentication, and AdminJS dashboard for data management.

logo

✨ Features

  • πŸ” Google OAuth 2.0 - Secure authentication with JWT tokens
  • 🎟️ Ticketing System - Complete booking and ticket management
  • πŸ—„οΈ MongoDB Integration - Mongoose ODM with optimized queries
  • πŸ§‘β€πŸ’Ό AdminJS Dashboard - Admin panel for data management
  • ⚑ Performance - Optimized queries with proper indexing
  • πŸ”„ Token Management - Access & refresh token handling
  • 🌐 CORS Enabled - Cross-origin resource sharing
  • πŸ›‘οΈ Type Safety - Full TypeScript implementation
  • 🎯 Error Handling - Standardized API responses

🌐 Live API

Production URL: https://busgo-node-js.onrender.com

πŸ“š API Documentation

Base URL

https://busgo-node-js.onrender.com/api/v1

API Endpoints

Method Endpoint Description Auth Required
POST /user/login Google OAuth authentication ❌
POST /user/refresh-token Refresh access token ❌
GET /city Get all cities ❌
GET /bus?busId={busExternalId} Get bus details by ID ❌
GET /bus/search?from={from}&to={to}&date={date}&tags={tags}&sortBy={sortBy} Search buses ❌
GET /ticket Get user tickets βœ…
POST /ticket Book new ticket βœ…
POST /seed Seed database ❌

Admin Dashboard

https://busgo-node-js.onrender.com/admin

πŸ”§ Tech Stack

Core Technologies

  • Node.js 18+ - JavaScript runtime
  • Express 5.1.0 - Web framework
  • TypeScript 4.9.5 - Type safety
  • MongoDB - Database with Mongoose ODM

Authentication & Security

  • Google Auth Library 10.1.0 - OAuth 2.0 integration
  • JSON Web Token 9.0.2 - JWT authentication
  • Express Session 1.18.1 - Session management
  • CORS 2.8.5 - Cross-origin requests

Admin & Utilities

  • AdminJS 6.8.7 - Admin dashboard
  • Colors 1.4.0 - Console logging
  • Nanoid 5.1.5 - ID generation
  • UUID 11.1.0 - Unique identifiers

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • MongoDB instance
  • Google OAuth credentials

Installation

  1. Clone repository

    git clone https://github.com/chayan-1906/BusGo-Node.js.git
    cd BusGo-Node.js
  2. Install dependencies

    npm install
  3. Environment setup

    cp .env.example .env
  4. Configure environment

    PORT=4000
    MONGO_URI=mongodb://localhost:27017/busgo
    WEB_GOOGLE_CLIENT_ID=your_google_client_id
    GOOGLE_CLIENT_SECRET=your_google_client_secret
    ACCESS_TOKEN_SECRET=your_access_token_secret
    ACCESS_TOKEN_EXPIRY=1d
    REFRESH_TOKEN_SECRET=your_refresh_token_secret
    REFRESH_TOKEN_EXPIRY=30d
    COOKIE_PASSWORD=your_cookie_password
    SEED_SECRET=your_seed_secret
    ADMIN_LOGIN_EMAIL=admin@busgo.com
    ADMIN_LOGIN_PASSWORD=your_admin_password
  5. Seed database

    npm run seed:data
  6. Start development server

    npm run dev

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ config/          # Database & app configuration
β”œβ”€β”€ controllers/     # Request handlers
β”œβ”€β”€ middleware/      # Authentication middleware
β”œβ”€β”€ models/          # Mongoose schemas
β”œβ”€β”€ routes/          # API route definitions
β”œβ”€β”€ types/           # TypeScript type definitions
β”œβ”€β”€ utils/           # Utility functions
β”œβ”€β”€ seedData.ts      # Database seeding data
β”œβ”€β”€ seedScript.ts    # Seeding script
└── server.ts        # Application entry point

πŸ“Š Database Schema

User Schema

{
  userExternalId: string    // UUID
  googleId: string         // Google OAuth ID
  email: string           // User email
  name: string            // Display name
  profilePicture: string  // Avatar URL
}

Bus Schema

{
  busExternalId: string    // UUID
  from: string            // Origin city
  to: string              // Destination city
  departureTime: Date     // Departure time
  arrivalTime: Date       // Arrival time
  duration: number        // Trip duration (minutes)
  availableSeats: number  // Available seats
  price: number           // Ticket price
  originalPrice: number   // Original price
  company: string         // Bus operator
  busTags: string[]       // Bus amenities
  rating: number          // User rating
  totalReviews: number    // Review count
  badges: string[]        // Quality badges
  seats: ISeat[][]        // Seat layout
}

Ticket Schema

{
  ticketExternalId: string  // UUID
  userId: ObjectId         // User reference
  userExternalId: string   // User UUID
  busId: ObjectId          // Bus reference
  busExternalId: string    // Bus UUID
  date: Date               // Travel date
  seatNumbers: number[]    // Selected seats
  totalFare: number        // Total amount
  status: enum             // Upcoming/Completed/Cancelled
  bookedAt: Date           // Booking timestamp
  pnr: string              // PNR number
}

πŸ”— API Usage Examples

Authentication

curl -X POST https://busgo-node-js.onrender.com/api/v1/user/login \
  -H "Content-Type: application/json" \
  -d '{"idToken": "google_id_token"}'

Search Buses

curl "https://busgo-node-js.onrender.com/api/v1/bus/search?from=Mumbai&to=Pune&date=2025-07-15&tags=A/C,Luxury&sortBy=price"

Get Bus Details

curl "https://busgo-node-js.onrender.com/api/v1/bus?busId=BUS_12345"

Book Ticket

curl -X POST https://busgo-node-js.onrender.com/api/v1/ticket \
  -H "Authorization: Bearer your_access_token" \
  -H "Content-Type: application/json" \
  -d '{"busExternalId": "BUS_12345", "seatNumbers": [1,2], "date": "2025-07-15"}'

πŸ”’ Authentication Flow

  1. Google OAuth Login - Frontend sends Google ID token
  2. Token Verification - Backend verifies with Google
  3. User Creation - New users auto-created
  4. JWT Generation - Access & refresh tokens issued
  5. Protected Routes - Bearer token required

πŸ§‘β€πŸ’Ό Admin Dashboard

Access AdminJS dashboard for data management:

  • URL: https://busgo-node-js.onrender.com/admin
  • Features: CRUD operations, user management, analytics
  • Authentication: Admin credentials required

πŸ“ˆ Performance Features

  • Database Indexing - Optimized queries
  • Connection Pooling - MongoDB connection optimization
  • Error Handling - Standardized responses
  • Logging - Colored console output

πŸ”§ Development Scripts

# Development server
npm run dev

# Seed database
npm run seed:data

# Build production
npm run build

πŸš€ Deployment

Render Deployment

  1. Connect GitHub repository
  2. Set environment variables
  3. Deploy automatically on push

πŸ§ͺ Testing

# API Testing with curl
curl -X GET https://busgo-node-js.onrender.com/api/v1/city

# Health Check
curl https://busgo-node-js.onrender.com/admin

πŸ“‹ Requirements

  • Node.js: β‰₯18.0.0
  • MongoDB: β‰₯5.0
  • Memory: 512MB RAM minimum
  • Storage: 1GB disk space

🀝 Contributing

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

πŸ› Known Issues

  • Cold starts on the Render free tier may cause delays

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

Padmanabha Das

🌟 Show Your Support

Give a ⭐️ if this project helped you!

πŸ“± Related Projects


Made with ❀️ by Padmanabha Das

⭐ Star this repo if you found it helpful!

About

Robust πŸš€ Node.js backend for a Bus Booking app with ticketing logic 🎟️, secure Google Auth πŸ”’, and clean TypeScript structure πŸ› οΈ.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors