Skip to content

ntkwan/csc13114-busio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

321 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Busio - Bus Ticket Booking Platform

Live Demo

Full-stack bus ticket booking platform with microservices architecture

Features β€’ Tech Stack β€’ Architecture β€’ Getting Started


πŸ“‹ Overview

A complete bus ticket booking solution built with microservices architecture. The platform includes customer-facing features for searching and booking tickets, alongside a comprehensive admin dashboard for fleet management, analytics, and operations.

Tech Highlights: 11 microservices β€’ Next.js 16 β€’ NestJS β€’ PostgreSQL β€’ Redis β€’ PayOS Integration


✨ Key Features

🎫 Customer Features

  • Smart Trip Search - Filter by price, time, amenities with real-time availability
  • Interactive Seat Selection - Visual picker with multi-floor support for double-decker buses
  • Payment Integration - PayOS for QR payments, bank transfers, and credit cards
  • E-Tickets - QR-coded tickets with PDF export
  • Booking Management - View history, request cancellations, track status
  • 360Β° Bus Preview - Panoramic interior views
  • Reviews & Ratings - Post-trip feedback system
  • Email Notifications - Booking confirmations and updates
  • Internationalization - Vietnamese and English support
  • Dark Mode - Theme persistence across sessions

🏒 Admin Dashboard

  • Fleet Management - Manage buses with custom seat layouts and amenities
  • Trip Scheduling - Create recurring trips with dynamic pricing
  • Seat Layout Editor - Drag-and-drop designer with multi-floor support
  • Analytics - Revenue tracking, booking trends, route performance
  • Customer Management - User profiles and payment history
  • Refund Processing - Handle cancellation requests
  • Reviews Management - Monitor and respond to feedback
  • Company Settings - Branding, policies, and configurations
  • Driver Assignment - Manage driver schedules
  • Knowledge Base - Help articles with markdown editor

πŸ” Security & Auth

  • Multi-Provider Auth - Email/password and Google OAuth via Firebase
  • JWT Sessions - Access + Refresh token pattern with auto-refresh
  • RBAC - Role-based access control (User, Admin, Business)
  • Route Protection - Client and server-side guards
  • Payment Security - PayOS webhook verification and signature validation

πŸ›  Technology Stack

Frontend

Next.js React TypeScript Tailwind CSS Redux Toolkit

  • Framework: Next.js 16 (App Router, React Server Components)
  • State Management: Redux Toolkit + Redux Persist
  • Data Fetching: RTK Query with auto-retry and caching
  • Styling: Tailwind CSS 4 with custom design tokens
  • UI Libraries: Recharts, Lottie, Pannellum, React Day Picker, React Markdown, SweetAlert2
  • Internationalization: i18next
  • Testing: Jest + React Testing Library

Backend

NestJS TypeORM PostgreSQL Redis Nginx

  • Framework: NestJS 11 (Microservices architecture)
  • ORM: TypeORM with PostgreSQL
  • Caching: Redis for sessions and rate limiting
  • API Gateway: Nginx reverse proxy
  • Authentication: Firebase Admin SDK
  • Image Storage: Cloudinary
  • Payments: PayOS integration
  • Email: Nodemailer

DevOps & Tooling

Docker GitHub Actions ESLint Prettier

  • Containerization: Docker + Docker Compose
  • CI/CD: GitHub Actions (12 automated workflows)
  • Package Manager: pnpm with workspace support
  • Code Quality: ESLint + Prettier + Husky + lint-staged
  • Commit Standards: Commitlint (Conventional Commits)
  • Deployment: Portainer (Frontend), Digital Ocean (Backend)

οΏ½ Architecture

Microservices Overview

graph TB
    Client[Next.js Client]
    Gateway[Nginx API Gateway :8080]

    Auth[Auth Service :3001]
    User[User Service :3002]
    Trip[Trip Service :3003]
    Vehicle[Vehicle Service :3004]
    Reservation[Reservation Service :3005]
    Payment[Payment Service :3006]
    Ticket[Ticket Service :3007]
    Location[Location Service :3008]
    Noti[Notification Service :3009]
    AI[AI Service :3010]

    DB[(PostgreSQL)]
    Cache[(Redis)]
    Firebase[Firebase Auth]
    PayOS[PayOS Gateway]
    Cloudinary[Cloudinary]

    Client -->|HTTP/HTTPS| Gateway
    Gateway --> Auth
    Gateway --> User
    Gateway --> Trip
    Gateway --> Vehicle
    Gateway --> Reservation
    Gateway --> Payment
    Gateway --> Ticket
    Gateway --> Location
    Gateway --> Noti
    Gateway --> AI

    Auth --> DB
    User --> DB
    Trip --> DB
    Vehicle --> DB
    Reservation --> DB
    Payment --> DB
    Ticket --> DB
    Location --> DB

    Auth --> Cache
    Auth --> Firebase
    Payment --> PayOS
    Vehicle --> Cloudinary

    style Client fill:#61dafb
    style Gateway fill:#009639
    style DB fill:#336791
    style Cache fill:#dc382d
    style Firebase fill:#ffca28
    style PayOS fill:#0080ff
    style Cloudinary fill:#3448c5
Loading

Service Responsibilities

Service Port Responsibility
bso-auth-svc 8081 Authentication, JWT, Google OAuth
bso-user-svc 8080 User profiles and preferences
bso-trip-svc 3002 Trip scheduling and search
bso-vehicle-svc 3001 Fleet management, seat layouts
bso-reservation-svc 3003 Bookings, seat locking, analytics
bso-payment-svc 8083 PayOS integration, refunds
bso-ticket-svc 3004 E-tickets, QR codes, cancellations
bso-location-svc 3000 Locations and routes
bso-noti-svc 9000 Email notifications
bso-ai-svc 7000 AI chatbot support

Data Flow Example: Booking a Ticket

sequenceDiagram
    participant C as Client
    participant G as API Gateway
    participant A as Auth Service
    participant T as Trip Service
    participant R as Reservation Service
    participant P as Payment Service
    participant TK as Ticket Service
    participant N as Notification Service

    C->>G: Search trips (date, route)
    G->>T: GET /trips/search
    T-->>C: Available trips

    C->>G: Select seats
    G->>A: Validate auth token
    A-->>G: User authenticated
    G->>R: POST /reservations/create
    R->>R: Lock seats (15 min)
    R-->>C: Reservation created

    C->>G: Initiate payment
    G->>P: POST /payments/payos/create
    P->>PayOS: Create payment link
    PayOS-->>C: QR code / payment URL

    C->>PayOS: Complete payment
    PayOS->>P: Payment webhook
    P->>R: Confirm reservation
    R->>TK: Generate e-ticket
    TK->>N: Send confirmation email
    N-->>C: Email with ticket PDF
Loading

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 9+
  • Docker & Docker Compose
  • PostgreSQL 15+
  • Redis 7+

1. Clone the Repository

git clone https://github.com/ntkwan/csc13114-busio.git
cd csc13114-busio

2. Install Dependencies

# Install root dependencies
npm install

# Install client dependencies
cd client
pnpm install

# Install backend dependencies (each service)
cd ../server/bso-auth-svc
npm install
# Repeat for other services...

3. Environment Configuration

Frontend (.env.local in client/)

NEXT_PUBLIC_BACKEND_URL=http://localhost:8080
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id
NEXT_PUBLIC_GEOAPIFY_API_KEY=your_geoapify_key

Backend (.env in each service)

PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_NAME=busio_db

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=

JWT_SECRET=your_super_secret_key
JWT_EXPIRES_IN=15m
JWT_REFRESH_SECRET=your_refresh_secret
JWT_REFRESH_EXPIRES_IN=7d

FIREBASE_SERVICE_ACCOUNT_PATH=./bso-service-account-key.json
FIREBASE_API_KEY=your_firebase_api_key
FIREBASE_TOKEN_VALIDATION_URL=

SENDGRID_API_KEY=your_sendgrid_key

PAYOS_CLIENT_ID=your_payos_client_id
PAYOS_API_KEY=your_payos_api_key
PAYOS_CHECKSUM_KEY=your_checksum_key

CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# Inter-service URLs
SVC_USER_URL=http://bso-user-svc:8080
SVC_RESERVATION_URL=http://bso-reservation-svc:3003
SVC_TRIP_URL=http://bso-trip-svc:3002
SVC_NOTIFICATION_URL=http://bso-noti-svc:9000

4. Database Setup

# Using Docker Compose
cd server
docker-compose up -d postgres redis

# Run migrations (TypeORM)
cd bso-auth-svc
pnpm migration:run

5. Run the Application

Development Mode:

# Terminal 1: Start backend services
cd server/bso-api-gateway
docker-compose up

# Terminal 2: Start auth service
cd server/bso-auth-svc
pnpm start:dev

# Terminal 3: Start other services (repeat for each)
cd server/bso-user-svc
pnpm start:dev

# Terminal 4: Start frontend
cd client
pnpm dev

Production Mode (Docker):

# Build and run all services
docker-compose up --build -d

Access the application:

6. Default Credentials

Admin Account:
Email: [email protected]
Password: 12345678

⛓️ GitOps & CI/CD

The project leverages GitHub Actions for CI and ArgoCD for GitOps-based CD:

Continuous Integration

  • βœ… Code Quality: ESLint and Prettier enforcement
  • βœ… Security: Commit linting and build validation
  • βœ… Artifacts: Automated Docker image builds pushed to Docker Hub

GitOps Deployment (ArgoCD)

  • πŸš€ Automated Sync: Infrastructure updates triggered by GitHub Actions
  • πŸš€ Branch-based Environments: Helm chart values managed in an infrastructure branch
  • πŸš€ Rollbacks: Easy version management and rollbacks via Git history

Manual Deployment (Ansible)

For initial server setup and manual deployments, specialized playbooks are available in client/playbook:

  • πŸ›  Server Setup: Automated Docker installation and configuration
  • πŸ›  Service Deployment: Ansible playbooks for client and gateway services
  • πŸ›  Inventory Management: Centralized server management via inventory.ini

Image Tagging Strategy: Images are tagged with the short Git SHA (e.g., latest-a3f5c2b) for precise version tracking and auditability.


🌐 Live Demo

Live Demo

πŸ”— URL: http://152.42.195.211:3000


🎯 Technical Highlights

Architecture

  • 11 independent microservices with clear separation of concerns
  • Nginx API Gateway with rate limiting
  • Normalized PostgreSQL schema (20+ tables)
  • Redis caching for sessions and frequently accessed data

Security

  • JWT with refresh token rotation
  • Role-based access control (RBAC)
  • Input validation via class-validator DTOs
  • CORS and XSS protection

Frontend

  • Next.js App Router with React Server Components
  • Code splitting and lazy loading
  • Responsive design with dark mode
  • Internationalization (vi/en)

DevOps

  • Docker containerization
  • GitHub Actions CI/CD + ArgoCD GitOps
  • Ansible playbooks for server automation
  • ESLint + Prettier + Husky

πŸ“š Project Structure

csc13114-busio/
β”œβ”€β”€ client/                      # Next.js frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # App Router pages
β”‚   β”‚   β”‚   β”œβ”€β”€ (main)/         # Main layout (user routes)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx    # Home page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ search-results/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ schedule/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ticket-lookup/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ cancel-ticket/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ settings/
β”‚   β”‚   β”‚   β”‚   └── policy/
β”‚   β”‚   β”‚   └── admin/          # Admin dashboard
β”‚   β”‚   β”œβ”€β”€ components/         # Reusable components
β”‚   β”‚   β”œβ”€β”€ features/           # Redux slices
β”‚   β”‚   β”œβ”€β”€ store/              # Redux store config
β”‚   β”‚   β”œβ”€β”€ services/           # RTK Query APIs
β”‚   β”‚   └── utils/              # Helper functions
β”‚   β”œβ”€β”€ public/                 # Static assets
β”‚   └── package.json
β”‚
β”œβ”€β”€ server/                     # NestJS backend
β”‚   β”œβ”€β”€ bso-api-gateway/        # Nginx reverse proxy
β”‚   β”œβ”€β”€ bso-auth-svc/           # Authentication service
β”‚   β”œβ”€β”€ bso-user-svc/           # User management
β”‚   β”œβ”€β”€ bso-trip-svc/           # Trip scheduling
β”‚   β”œβ”€β”€ bso-vehicle-svc/        # Fleet management
β”‚   β”œβ”€β”€ bso-reservation-svc/    # Booking system
β”‚   β”œβ”€β”€ bso-payment-svc/        # Payment processing
β”‚   β”œβ”€β”€ bso-ticket-svc/         # E-ticket generation
β”‚   β”œβ”€β”€ bso-location-svc/       # Location management
β”‚   β”œβ”€β”€ bso-noti-svc/           # Notification service
β”‚   β”œβ”€β”€ bso-ai-svc/             # AI chatbot
β”‚   └── docker-compose.yml
β”‚
β”œβ”€β”€ .github/workflows/          # CI/CD pipelines
β”œβ”€β”€ .husky/                     # Git hooks
└── README.md

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •