Back to Ayush's profile
17views

Build for Ambula '26

Ayush Khaitan
Build for Ambula '26

Overview

Project Overview

Ambula Care is a full-stack, mobile-friendly healthcare web platform built using Next.js App Router (React 19, TypeScript), MongoDB (Mongoose), and Vanilla CSS (custom glassmorphic theme). It enables patients to search for doctors, choose slots from a 7-day calendar, fill out health summaries, and book appointments in under 45 seconds. It also provides doctors with a secure JWT-authenticated dashboard to log in, review patient records, log consultation diagnosis notes/prescriptions, and block slots for leave.

Setup & Installation

  1. Install node packages: npm install

  2. Seed the database with mock doctors, 7 days of available slots, and doctor credentials: npx tsx src/scripts/seed.ts

  3. Run the development server: npm run dev

  4. Open the site locally at: http://localhost:3000

Test Credentials (Local & Live Site)

  • Email: doctor@ambula.com
  • Password: password123 (This account is linked to Dr. Amit Sharma)

Concurrency Lock & Double-Booking Prevention

To ensure 100% reliability under concurrent booking requests, we implemented an atomic lock mechanism at the query level instead of using heavy database transactions:

  • When a patient selects a slot, a temporary Booking is written in a 'pending' state.
  • We then run an atomic find-and-update operation on the Slot collection requiring its status to be exactly 'available': Slot.findOneAndUpdate({ _id: slotId, status: "available" }, { status: "booked", bookingId })
  • If two bookings arrive simultaneously, MongoDB processes them sequentially. The first succeeds and locks the slot, while the second query matches 0 documents and returns null.
  • The losing thread deletes its pending booking and returns a 409 Conflict to the user, advising them to select the next slot.
  • You can run the concurrency test script to verify this (sends 5 simultaneous requests for the exact same slot): npx tsx src/scripts/test-concurrency.ts

Mandatory Submission Statement

"We prevented double-booking at the backend using a single-document atomic update query (findOneAndUpdate) matching the slot ID and requiring its status to be exactly 'available'; because single-document updates are processed sequentially and atomic by design in MongoDB, this acts as a lock that guarantees exactly one request modifies the slot state while all other concurrent requests are safely rejected."