Skip to content

Repository files navigation


🛠️ Technology Stack

Frontend Purpose
Next.js 14 React framework with App Router
TypeScript Type‑safe code
Tailwind CSS Utility‑first styling
Vercel v0 AI‑powered UI generation
Lucide Icons Clean icon set
Backend Purpose
Next.js API Routes Serverless functions
Neon Serverless PostgreSQL AWS Aurora‑compatible database
@neondatabase/serverless Database driver
Vercel Hosting & deployment

📊 Database Schema

-- Restaurants table
CREATE TABLE restaurants (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name VARCHAR(100) NOT NULL,
  cuisine VARCHAR(50),
  location VARCHAR(100),
  rating DECIMAL(2,1) DEFAULT 4.5
);

-- Time slots table (tracks availability)
CREATE TABLE time_slots (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  restaurant_id UUID REFERENCES restaurants(id) ON DELETE CASCADE,
  slot_time TIMESTAMP NOT NULL,
  capacity INT DEFAULT 4,
  booked_count INT DEFAULT 0
);

-- Bookings table (customer reservations)
CREATE TABLE bookings (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  slot_id UUID REFERENCES time_slots(id) ON DELETE CASCADE,
  customer_name VARCHAR(100) NOT NULL,
  customer_phone VARCHAR(20) NOT NULL,
  party_size INT NOT NULL,
  booked_at TIMESTAMP DEFAULT NOW()
);
```[reference:6]

---

## 🔒 Double‑Booking Prevention (ACID Transactions)

The booking API uses database‑level locking to prevent race conditions:

```typescript
const slotCheck = await sql`
  SELECT capacity, booked_count 
  FROM time_slots 
  WHERE id = ${slotId} 
  FOR UPDATE;  -- Locks the row
`;

if (current.booked_count >= current.capacity) {
  throw new Error('Fully booked');
}

-- Insert booking & update count atomically
```[reference:7]

Why this matters:
- ✅ No double‑booking, even with concurrent requests
- ✅ Production‑grade solution
- ✅ Demonstrates deep technical understanding[reference:8]

---

## 🚀 Getting Started

### Prerequisites

- Node.js 18+
- Neon Database account (free tier)
- Vercel account (free tier)[reference:9]

### Installation

1. **Clone the repository**
   ```bash
   git clone https://github.com/samki6576/restaurants.git