Week 3 Day 02 Hospitality Domain Generated by Gemini Code Assist

Hospitality Service Management Schema

Designing a scalable database to support Guest Requests and Staff Fulfillment.

1. Core System Tables

These tables manage the users and the master list of all requests, serving as the backbone for both the Customer View and Service Provider View.

Table: Users

Supports authentication for Guests and Staff.

Field Name Data Type Description
user_id INT (PK) Unique Identifier
role ENUM 'GUEST', 'STAFF', 'ADMIN' - Distinguishes between Customer and Service Provider views.
name VARCHAR User Name
room_number VARCHAR Assigned Room - Crucial for delivery/service location.
language_pref VARCHAR Language Code - Supports multilingual translation features.

Table: Master_Requests

The central list used by Staff to view "Open" tasks and by Guests to track "My Requests".

Field Name Data Type Description
request_id INT (PK) Unique Request ID
guest_id INT (FK) Linked to Users - Identifies the requester.
service_type ENUM 'HOUSEKEEPING', 'DINING', 'TRANSPORT', 'FRONT_DESK', 'MAINTENANCE' - Categorizes the request for routing.
status ENUM 'PENDING', 'ASSIGNED', 'IN_PROGRESS', 'COMPLETED' - Real-time status updates for the guest.
assigned_staff_id INT (FK) Linked to Users - The Service Provider handling the task.
created_at DATETIME Timestamp - Used for SLA tracking.

2. Service-Specific Tables

These tables store the specific data required for the top 5 services, linked back to the Master Request table.

Service 1: Housekeeping (Amenities)

Field NameData TypeDescription
detail_idINT (PK)Unique ID
request_idINT (FK)Linked to Master_Requests
item_nameENUM'TOWELS', 'TOILETRIES', 'COFFEE_REFILL', 'FAN'
quantityINTNumber of items
allergy_noteVARCHARSpecific cleaning chemical allergies

Service 2: Room Service (On-Demand Dining)

Field NameData TypeDescription
order_idINT (PK)Unique ID
request_idINT (FK)Linked to Master_Requests
menu_item_idINTLinked to a Menu Catalog
special_instructionsTEXT'No onions', 'Gluten-free' etc.
delivery_timeDATETIMEScheduled Time

Service 3: Transportation

Field NameData TypeDescription
booking_idINT (PK)Unique ID
request_idINT (FK)Linked to Master_Requests
pickup_typeENUM'TAXI', 'AIRPORT_SHUTTLE', 'LIMO'
destinationVARCHARDrop-off location
pickup_timeDATETIMERequested time
flight_numberVARCHARExternal API data link for tracking delays

Service 4: Front Desk Services

Field NameData TypeDescription
fd_idINT (PK)Unique ID
request_idINT (FK)Linked to Master_Requests
request_typeENUM'LATE_CHECKOUT', 'UPGRADE', 'LUGGAGE_ASSIST'
requested_timeTIMEProposed checkout/pickup time
luggage_countINTNumber of bags
upgrade_prefVARCHARDesired Room Type

Service 5: Maintenance & General Repairs

Field NameData TypeDescription
ticket_idINT (PK)Unique ID
request_idINT (FK)Linked to Master_Requests
issue_categoryENUM'PLUMBING', 'ELECTRICAL', 'NOISE', 'CLIMATE'
descriptionTEXTUser description of issue
is_automatedBOOLEANDid a sensor trigger this or a guest?
severityENUM'LOW', 'MEDIUM', 'HIGH'

How the Views Utilize These Tables

1

Customer View (The Guest)

  • Action: When a guest logs in, the app queries Users to get their profile.
  • Requesting: When they click "Order Towels" (One-Touch Housekeeping), the app creates a row in Master_Requests (Status: PENDING) and a row in Housekeeping_Details (Item: Towels).
  • Viewing: The "My Activity" screen filters Master_Requests where guest_id = Current User, showing the status (e.g., "IN_PROGRESS") so they don't have to call the desk.
2

Service Provider View (The Staff)

  • Action: When a staff member logs in, they see a dashboard.
  • Viewing: The dashboard queries Master_Requests where status is NOT 'COMPLETED'.
  • Filtering:

    Housekeeping Staff see requests where service_type = 'HOUSEKEEPING'.

    Engineers see requests where service_type = 'MAINTENANCE'.

  • Fulfillment: When staff delivers the item, they update the status in Master_Requests to 'COMPLETED', which triggers a notification to the Guest View.

Hospitality Service Management Firebase Schema

Based on the provided source material, "creating tables" in Google Cloud Platform (GCP) Firebase (specifically Cloud Firestore, the standard NoSQL database for mobile apps) involves writing data to collections. Unlike SQL, you do not run CREATE TABLE commands. Instead, you create documents within collections.

Part 1: Node.js Initialization Script

This script initializes the collections and seeds them with sample data to represent the schema structure. It ensures the Core System Tables and Service-Specific Tables are linked correctly using the Firebase Admin SDK.

const admin = require('firebase-admin');
const serviceAccount = require('./path/to/serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const db = admin.firestore();

async function createHospitalitySchema() {
  
  // ======================================================
  // 1. CORE SYSTEM TABLES (Users & Master_Requests) [1], [2]
  // ======================================================

  // --- Table: Users [1] ---
  // Creating a Guest Profile
  const guestRef = db.collection('users').doc('guest_123');
  await guestRef.set({
    role: 'GUEST',           // Source [1]
    name: 'John Doe',
    room_number: '101',      // Source [1]
    language_pref: 'en'      // Source [1]
  });

  // Creating a Staff Profile
  const staffRef = db.collection('users').doc('staff_456');
  await staffRef.set({
    role: 'STAFF',           // Source [1]
    name: 'Alice Manager',
    department: 'HOUSEKEEPING'
  });

  console.log("Users created.");

  // --- Table: Master_Requests [2] ---
  // The central list used by Staff to view "Open" tasks
  const requestRef = db.collection('master_requests').doc('req_001');
  await requestRef.set({
    guest_id: 'guest_123',       // Linked to Users [2]
    service_type: 'HOUSEKEEPING',// Source [2]
    status: 'PENDING',           // Source [2]
    assigned_staff_id: null,     // Initially unassigned [2]
    created_at: admin.firestore.FieldValue.serverTimestamp()
  });

  console.log("Master Request created.");

  // ======================================================
  // 2. SERVICE-SPECIFIC TABLES (Top 5 Services) [3] - [4]
  // ======================================================

  // --- Service 1: Housekeeping Details [3] ---
  // Focus: Extra towels, toiletries
  await db.collection('housekeeping_details').add({
    request_id: 'req_001',       // FK to Master_Requests [3]
    item_name: 'TOWELS',         // ENUM Source [3]
    quantity: 2,
    allergy_note: 'None'         // Source [3]
  });

  // --- Service 2: Dining Orders [5] ---
  // Focus: On-demand dining, dietary restrictions
  await db.collection('dining_orders').add({
    request_id: 'req_002',       // Link to a dining master request
    menu_item_id: 55,            // Linked to Menu Catalog [5]
    special_instructions: 'Gluten-free', // Source [5]
    delivery_time: '2023-10-27T19:00:00Z' // Source [5]
  });

  // --- Service 3: Transport Bookings [6] ---
  // Focus: Airport Pickups, Flight Data
  await db.collection('transport_bookings').add({
    request_id: 'req_003',
    pickup_type: 'AIRPORT_SHUTTLE', // Source [6]
    destination: 'JFK Airport',
    flight_number: 'UA990',         // Source [6]
    pickup_time: '2023-10-28T08:00:00Z'
  });

  // --- Service 4: Front Desk Requests [4] ---
  // Focus: Late Check-Out, Upgrades
  await db.collection('front_desk_requests').add({
    request_id: 'req_004',
    request_type: 'LATE_CHECKOUT',  // Source [4]
    requested_time: '14:00',
    upgrade_pref: 'Sea View Suite'  // Source [4]
  });

  // --- Service 5: Maintenance Tickets [4], [7] ---
  // Focus: Repairs, Workflow Automation
  await db.collection('maintenance_tickets').add({
    request_id: 'req_005',
    issue_category: 'PLUMBING',     // Source [4]
    description: 'Sink is leaking', // Source [4]
    severity: 'MEDIUM',             // Source [4]
    is_automated: false             // Source [4]
  });

  console.log("Service specific tables populated.");
}

createHospitalitySchema();

Part 2: Firestore Security Rules (Schema Validation)

Since NoSQL is schema-less by default, you use Security Rules to enforce the data types and ENUM constraints defined in your source tables (e.g., ensuring status is only 'PENDING' or 'COMPLETED').

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // --- Table: Users [1] ---
    match /users/{userId} {
      allow read, write: if request.auth != null;
      // Enforce Role ENUM [1]
      allow create: if request.resource.data.role in ['GUEST', 'STAFF', 'ADMIN'];
    }

    // --- Table: Master_Requests [2] ---
    match /master_requests/{requestId} {
      allow read, write: if request.auth != null;
      
      // Enforce Data Integrity
      allow create: if 
        // Service Type ENUM [2]
        request.resource.data.service_type in ['HOUSEKEEPING', 'DINING', 'TRANSPORT', 'FRONT_DESK', 'MAINTENANCE'] &&
        // Status ENUM [2]
        request.resource.data.status in ['PENDING', 'ASSIGNED', 'IN_PROGRESS', 'COMPLETED'];
    }

    // --- Service 1: Housekeeping Details [3] ---
    match /housekeeping_details/{detailId} {
      allow read, write: if request.auth != null;
      // Enforce Item Name ENUM [3]
      allow create: if request.resource.data.item_name in ['TOWELS', 'TOILETRIES', 'COFFEE_REFILL', 'FAN'];
    }

    // --- Service 3: Transport Bookings [6] ---
    match /transport_bookings/{bookingId} {
      allow read, write: if request.auth != null;
      // Enforce Pickup Type ENUM [6]
      allow create: if request.resource.data.pickup_type in ['TAXI', 'AIRPORT_SHUTTLE', 'LIMO'];
    }

    // --- Service 4: Front Desk Requests [4] ---
    match /front_desk_requests/{fdId} {
      allow read, write: if request.auth != null;
      // Enforce Request Type ENUM [4]
      allow create: if request.resource.data.request_type in ['LATE_CHECKOUT', 'UPGRADE', 'LUGGAGE_ASSIST'];
    }

    // --- Service 5: Maintenance Tickets [4] ---
    match /maintenance_tickets/{ticketId} {
      allow read, write: if request.auth != null;
      // Enforce Issue Category and Severity ENUMs [4]
      allow create: if 
        request.resource.data.issue_category in ['PLUMBING', 'ELECTRICAL', 'NOISE', 'CLIMATE'] &&
        request.resource.data.severity in ['LOW', 'MEDIUM', 'HIGH'];
    }
    
    // Default fallback for Dining Orders and others not strictly restricted above
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}