Architecture Overview
AI Studio is built on a robust service layer architecture that manages all core business logic for a restaurant management system. The application uses Firebase as the backend database with a local caching strategy for optimal performance.Service Layer Structure
The API is organized into several specialized service modules:- Product & Category Services - Menu item and category management
- Order Service - Order processing and lifecycle management
- Reservation Service - Table reservation system with availability checking
- Table Service - Table management and occupancy tracking
- Customer Services - Customer and customer category management
- Gemini AI Service - AI-powered chat assistant and audio transcription
Core Design Patterns
Cache-First Architecture
All services implement a dual-layer caching strategy:- In-Memory Cache - Fast synchronous access via
getXFromCache()functions - LocalStorage Cache - Persistent client-side storage
- Firebase Sync - Cloud database as source of truth
Optimistic Updates
Services update local caches immediately for responsive UI, then sync with Firebase:Firebase Integration
All services use Firebase Firestore with these collections:| Collection | Purpose | Document ID Format |
|---|---|---|
Products | Menu items | PROD-{timestamp}-{random} |
Categories | Product categories | CAT-{timestamp}-{random} |
Orders | Customer orders | ORD-{timestamp}-{random} |
Reservations | Table reservations | RES-{timestamp}-{random} |
Tables | Restaurant tables | TBL-{timestamp}-{random} or custom |
Customers | Customer records | CUST-{timestamp}-{random} |
CustomerCategories | Customer categories | CUSTCAT-{timestamp}-{random} |
ReservationSettings | Reservation configuration | main (singleton) |
Common Patterns
Error Handling
All async operations follow this pattern:Data Cleaning
All services removeundefined values before Firebase writes:
Batch Operations
Bulk operations use Firebase batch writes for atomicity:TypeScript Types
All services are fully typed using interfaces defined intypes.ts. See individual service pages for detailed type definitions.
Authentication & Security
The services layer assumes Firebase authentication and security rules are configured. All operations respect Firebase security rules.Next Steps
Explore specific service APIs:Products API
Product and category management
Orders API
Order processing and tracking
Reservations API
Table reservation system
Tables API
Table management and status
Customers API
Customer management
Gemini AI API
AI assistant and transcription
