Overview
Reseñas Gastronómicas uses Firebase Firestore as its backend database for storing reviews. This guide walks you through the complete Firebase setup process, from creating a project to configuring security rules.Prerequisites
Before starting, ensure you have:- A Google account for accessing Firebase Console
- Basic understanding of NoSQL databases (helpful but not required)
- Access to your project’s source code
Firebase Project Setup
Create a Firebase Project
Navigate to the Firebase Console and create a new project.
- Click Add Project
- Enter a project name (e.g., “resenas-gastronomicas”)
- Optionally disable Google Analytics if not needed
- Click Create Project
Register Your Web App
After creating the project, register your web application:
- In the Firebase Console, click the Web icon (
</>) to add a web app - Enter an app nickname (e.g., “Reseñas Web App”)
- Do not enable Firebase Hosting (unless you plan to use it)
- Click Register App
Enable Firestore Database
Set up Cloud Firestore for data storage:
- In the Firebase Console sidebar, click Firestore Database
- Click Create Database
- Choose Start in test mode (we’ll configure security rules later)
- Select a Firestore location (choose the region closest to your users)
- Click Enable
Code Configuration
Create Firebase Config File
Create a configuration file to store your Firebase credentials:Create file: Replace the placeholder values with your actual Firebase configuration.
src/js/data/firebase-config.jsVerify Firebase Initialization
The application initializes Firebase in This code:
src/js/app.js:1-6:- Imports your configuration
- Initializes the Firebase app
- Creates a Firestore database instance
Firestore Data Structure
Collection: reviews
All reviews are stored in a single collection named reviews. Each document represents one review:
Document Schema
Firebase Operations
The application performs four main Firestore operations:1. Reading Reviews
- Orders reviews by timestamp (newest first)
- Handles errors gracefully
- Returns empty array on failure
2. Adding Reviews
- Adds server timestamp for accurate ordering
- Returns the created document with ID
- Throws errors for handling in UI
3. Updating Reviews
- Adds
updatedAttimestamp - Uses document ID for precise updates
- Preserves original
timestampandcreatedAt
4. Deleting Reviews
- Permanently deletes the document
- Returns success boolean
- Errors are caught and handled by UI
Real-Time Sync
The application uses Firestore’s real-time listeners for automatic UI updates:Benefits of Real-Time Sync
Instant Updates
Changes appear immediately across all devices viewing the app
No Polling
No need to manually refresh - updates push automatically
Multi-User Support
Multiple users can add/edit reviews simultaneously
Offline Support
Firestore caches data for offline viewing (with additional config)
Security Rules
By default, the database is in test mode which allows unrestricted access. For production, implement proper security rules.Development Rules (Current)
Recommended Production Rules
For a public review application with no authentication:For better security, implement Firebase Authentication and restrict updates/deletes to authenticated users only.
Applying Security Rules
Error Handling
The application includes fallback data when Firebase is unavailable:Environment Variables
For production deployments, use environment variables instead of hardcoded config:Using dotenv
The project includes dotenv support:Setup
- Create
.envfile in project root:
- Update build process to inject variables
-
Add
.envto.gitignore
Monitoring and Usage
Firebase Console Dashboard
Monitor your database in real-time:- Firestore > Data: View and manually edit documents
- Usage: Track reads, writes, and deletes
- Indexes: Manage composite indexes for complex queries
- Errors: View error logs from security rules
Usage Limits (Free Tier)
Reads
50,000 reads per day
Writes
20,000 writes per day
Deletes
20,000 deletes per day
Storage
1 GB stored data
Troubleshooting
Connection Errors
Problem: “Error obteniendo reseñas” in console Solutions:- Verify Firebase config values are correct
- Check that Firestore is enabled in Firebase Console
- Ensure Firebase SDK scripts are loaded before app.js
- Check browser console for specific Firebase errors
Permission Denied Errors
Problem: “Missing or insufficient permissions” Solutions:- Check Firestore security rules
- Verify test mode is enabled (for development)
- Ensure rules haven’t expired
- Check Firebase Console for rule errors
Data Not Syncing
Problem: New reviews don’t appear automatically Solutions:- Verify real-time listener is set up (datastore.js:26)
- Check browser console for listener errors
- Ensure
reviewsUpdatedevent is being dispatched - Refresh the page to force a new listener
Next Steps
Add Reviews
Start adding reviews to your configured Firebase database
Customize App
Personalize the look and feel of your review system