Overview
The Playground project uses Firebase Realtime Database with a structured schema organized into several top-level collections. The database uses a denormalized structure optimized for read performance.Database Schema
Root Structure
Detailed Schemas
celdas (Schedule Cells)
Stores schedule assignments for each agent, organized by agent → day → year → month:Turnos (Shifts)
Defines shift types with their properties:Historial (History)
Tracks all changes made to schedules:- Only significant changes are logged (not empty → empty)
- Batch operations create a single history entry
- Each entry records the user who made the change
Plantillas (Templates)
Message templates for customer service:Preferencias (User Preferences)
User-specific settings:procedimientos (Procedures)
Internal documentation and procedures:agentes (Agents)
Stores agent passwords (referenced but values stored securely):Data Organization Principles
1. Denormalization
Data is duplicated to optimize reads:2. Hierarchical Structure
Data is organized by access patterns:3. Flat Lists for Iteration
Collections that need iteration are kept flat:Key Patterns
Auto-generated Keys
For history entries:Named Keys
For most collections:Multi-level Keys
For nested data:Data Types
Strings
Numbers
Booleans
Objects
HTML
Query Patterns
Single Item Read
Collection Read
Filtered Read (Local)
Batch Read
Security Considerations
Firebase Rules
The database should have rules like:Data Validation
Always validate data before writing:Best Practices
- Keep paths consistent: Use the same structure throughout
- Use descriptive keys:
Andrés_Felipe_Yepes_Tascónnotuser1 - Denormalize for reads: Duplicate data when it improves performance
- Avoid deep nesting: Limit to 3-4 levels maximum
- Use arrays sparingly: Objects with keys are more flexible
- Store timestamps: Always include creation/modification times
- Plan for growth: Structure data to scale
Related Files
- All
source/script*.jsfiles contain data access patterns source/FirebaseWrapper.js- Database operation wrappersource/scriptHorariosStop.js- Main schedule data operations
