Sign inSign up

shifat18/vehicle-rental-system-app

By shifat18

•Updated 3 days ago

Production ready Vehicle Rental System REST API built with Node.js, TypeScript, and PostgreSQL.

Image
1

83

shifat18/vehicle-rental-system-app repository overview

⁠🚗 Vehicle Rental System API

Node Version TypeScript PostgreSQL Docker

A robust, production-ready backend API for managing vehicle rentals. Built with TypeScript, Express, and raw PostgreSQL queries via pg. It features role-based access control, dynamic booking duration & pricing calculations, and automatic database schema initialization.


⁠🚀 Quick Start (Running the Image)

⁠Step 1: Pull the image
docker pull shifat18/vehicle-rental-system-app:latest
⁠Step 2: Run with your database

Pass your PostgreSQL connection string (such as from Neon⁠, Supabase, AWS RDS, or a local Postgres instance):

docker run -d \
  --name vehicle_rental_app \
  -p 3001:3001 \
  -e CONNECTION_STRING="postgresql://username:password@host:port/database?sslmode=require" \
  -e JWT_SECRET="your-super-secure-jwt-secret" \
  shifat18/vehicle-rental-system-app:latest
⁠Step 3: Test the API
curl http://localhost:3001/api/v1
# Response: "Vehicle rental system running"

⁠⚙️ Environment Variables

VariableRequired?DefaultDescription
CONNECTION_STRINGYESNoneFull PostgreSQL connection URI. Works with cloud databases (Neon, Supabase) or local instances.
PORTNo3001The HTTP port the containerized server listens on.
JWT_SECRETNodev-fallback-secret-keySecret key for signing and verifying JSON Web Tokens (pass your own in production!).
NODE_ENVNoproductionNode environment (production / development).

⁠🐳 Run Everything with Docker Compose (App + Database)

If you don't have a remote database and want to run both the API and a local PostgreSQL container together with persistent storage, save this as docker-compose.yml:

version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: vehicle_rental_postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: vehicle_rental_db
    ports:
      - "5433:5432" # Exposed on 5433 to avoid collision with any host Postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d vehicle_rental_db"]
      interval: 5s
      timeout: 5s
      retries: 5

  app:
    image: shifat18/vehicle-rental-system-app:latest
    container_name: vehicle_rental_app
    restart: unless-stopped
    ports:
      - "3001:3001"
    environment:
      NODE_ENV: production
      PORT: 3001
      JWT_SECRET: your-custom-jwt-secret
      CONNECTION_STRING: postgresql://postgres:postgres@postgres:5432/vehicle_rental_db
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:

Then run:

docker compose up -d

⁠🗄️ Automatic Database Initialization

You do not need to run any manual migrations. On startup, the application checks and automatically creates:

  • USERS table (Authentication, roles: admin and customer, hashed passwords).
  • VEHICLES table (Vehicle catalog, types: car, bike, van, SUV, daily rent price, availability).
  • BOOKINGS table (Rent duration, total price calculation, status, foreign key relationships with cascade delete).

⁠🔒 Security & Architecture Highlights

  • Multi-stage build: Compiled TypeScript output with devDependencies stripped (node:20-alpine).
  • Non-root user: Runs under unprivileged user node for container security.
  • Graceful termination: Handles SIGTERM and SIGINT signals cleanly for zero-downtime orchestrations.
  • Fail-fast configuration: Validates CONNECTION_STRING on startup with human-readable error messages.

⁠📖 Key API Endpoints

MethodEndpointDescriptionAccess
POST/api/v1/auth/signupRegister new customer or adminPublic
POST/api/v1/auth/loginLogin and receive JWT bearer tokenPublic
GET/api/v1/vehiclesList vehicles (with availability filters)Public
POST/api/v1/vehiclesAdd a new vehicleAdmin only
POST/api/v1/bookingsBook a vehicle (auto-calculates total price)Customer / Admin
GET/api/v1/bookingsView bookingsRole-based
GET/api/v1Health check endpointPublic

Tag summary

Content type

Image

Digest

sha256:1af611bab…

Size

47.6 MB

Last updated

3 days ago

docker pull shifat18/vehicle-rental-system-app