- Overview
- Deployment
- Features
- Project Structure
- Getting Started
- Project Roadmap
- Contributing
- License
- Acknowledgments
The RMS-API project is a robust solution for managing real-time data interactions within web applications. It leverages Firebase for seamless backend integration and Firestore for optimized data querying. Key features include consistent environment setups across development stages and detailed API documentation. This API is ideal for developers needing efficient, scalable solutions for dynamic web environments.
This project uses a multi-environment approach for Firebase Functions with separate development and production functions.
The project deploys two distinct functions to the same Firebase project:
api-dev: Development function (less resources, development database)api: Production function (more resources, production database)
Pushes to specific branches automatically trigger deployments:
- Push to
developbranch → Deploysapi-devfunction - Push to
releasebranch → Deploysapifunction
For local deployment, use the convenience scripts:
# Deploy development function
./scripts/deploy-dev.sh
# Deploy production function
./scripts/deploy-prod.shYou can also deploy directly with npm commands:
# Install dependencies
cd functions
npm install
# Deploy development function
npm run deploy:dev
# Deploy production function
npm run deploy:prodTo run the functions locally with Firebase emulators:
# Run all functions
npm run serve
# Run only development function
npm run serve:dev
# Run only production function
npm run serve:prodEnvironment variables are set at runtime for each function. You can modify them in .env for local development:
# Common environment variables
API_KEY=your-api-key
STRIPE_SECRET_KEY=your-stripe-key
CLIENT_AUTH_API_KEY=your-firebase-client-key
# The other variables like NODE_ENV and FUNCTION_NAME
# are automatically set based on which function is runningBoth functions use the same Firebase project but different Firestore databases:
api-devuses thedevelopdatabaseapiuses the default database
To check function logs:
# All functions
npm run logs
# Development function only
npm run logs:dev
# Production function only
npm run logs:prod| Feature | Summary | |
|---|---|---|
| ⚙️ | Architecture |
|
| 🔩 | Code Quality |
|
| 📄 | Documentation |
|
| 🔌 | Integrations |
|
| 🧩 | Modularity |
|
| 🧪 | Testing |
|
| ⚡️ | Performance |
|
| 🛡️ | Security |
|
| 📦 | Dependencies |
|
└── RMS-API/
├── .github
│ ├── ISSUE_TEMPLATE
│ └── workflows
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── firebase.json
├── firestore.indexes.json
├── firestore.rules
├── functions
│ ├── .gitignore
│ ├── app
│ ├── app.js
│ ├── generate-swagger.js
│ ├── index.js
│ ├── package-lock.json
│ ├── package.json
│ ├── scripts
│ └── swagger.yaml
├── package-lock.json
└── package.jsonRMS-API/
__root__
firebase.json - Configures Firebase services including Firestore rules and indexes, and function deployment settings for the project
- It specifies local emulator settings for development, including ports for authentication, functions, and Firestore, enhancing testing efficiency
- The configuration ensures a streamlined environment setup and operational consistency across development and production environments, centralizing project management within Firebase.firestore.indexes.json - Manages Firestore database configurations by defining indexes and field-specific rules within the codebase
- The `firestore.indexes.json` serves as a blueprint for database structure optimization and query efficiency, ensuring that data retrieval operations are streamlined and adhere to specified constraints and enhancements
- This setup is crucial for maintaining performance and scalability of the database interactions.package-lock.json - The `package-lock.json` file in the RMS-API project serves as a critical component for managing the project's dependencies, ensuring consistent installations and compatibility across different development environments
- This file specifically locks down the versions of dependencies such as `swagger-jsdoc` and `swagger-ui-express`, which are essential for documenting the API endpoints within the RMS-API
- Additionally, it includes dependencies like `@apidevtools/json-schema-ref-parser` to handle JSON schema parsing, crucial for validating and working with JSON schemas in the API.In the broader architecture of the RMS-API, this file ensures that all developers working on the project use the same versions of packages, thereby avoiding discrepancies that can arise from version mismatches
- This is particularly important in maintaining the stability and reliability of the API across different setups and when deploying to production environments
- The dependencies listed are integral for API documentation and schema validation, which are fundamental aspects of the API's functionality and its interaction with other services or clients.firestore.rules - Firestore.rules establishes temporary, unrestricted access permissions for all operations within the Firestore database
- It is designed to facilitate initial development phases by allowing broad data manipulation until a specified expiration date
- Post-expiration, it mandates the implementation of more secure, tailored access rules to protect the database from unauthorized access.package.json - Manages the integration of Swagger documentation tools within the project by specifying dependencies crucial for creating and displaying API documentation
- The inclusion of swagger-jsdoc and swagger-ui-express facilitates the automatic generation and elegant presentation of API endpoints, enhancing the development and consumption of the project's RESTful services.
.github
workflows
api-documentation.yaml - Check & deploy API documentation automates the generation and deployment of API documentation upon code changes
- It triggers on pushes and pull requests to main and develop branches, generating Swagger YAML files and either deploying them or checking API differences using Bump.sh.deploy-firebase-functions.yml - Deploys Firebase Functions automatically upon code pushes to the main or develop branches
- The GitHub Actions workflow includes steps for setting up the environment, installing necessary tools and dependencies, and deploying functions using Firebase CLI, ensuring a streamlined update process for server-side logic in response to repository changes.
functions
app.js - App.js serves as the central hub for routing in the application, integrating various modules for handling specific domain-related routes such as authentication, tables, reservations, and user management
- It configures middleware for CORS, metrics, and error handling, ensuring efficient route management and initial setup for application counters.package-lock.json - The package-lock.jsonfile located in thefunctionsdirectory plays a crucial role in managing and ensuring the consistency of the dependencies used within this specific part of the project
- This file is automatically generated and updated when dependencies are installed or modified through npm (Node Package Manager)
- It serves to lock the versions of the dependencies listed, ensuring that every installation or deployment of the project uses the exact same versions, thereby avoiding discrepancies and potential bugs caused by version mismatches.In the context of the entire codebase, this file ensures that the server-side functions, likely used for handling backend processes such as API requests, database interactions, and third-party service integrations, remain stable and consistent across different development and production environments
- The dependencies listed, such asexpressfor server operations,axiosfor HTTP requests, andfirebasefor database interactions, indicate that this part of the project is focused on backend services which are crucial for the application's functionality.This file is essential for maintaining the integrity and reliability of the application's backend logic, particularly in a collaborative development environment or when deploying to different servers or platforms.
index.js - Functions/index.js serves as the entry point for handling HTTP requests within the project, routing them through an Express application
- It utilizes Firebase Functions to manage these requests, ensuring that the application's web services are scalable and efficiently integrated with cloud capabilities, thereby supporting the broader architecture's functionality and responsiveness.package.json - Manages the deployment and local emulation of cloud-based functions for a Firebase project, facilitating serverless backend operations
- It includes scripts for serving, deploying, and logging functions, and specifies dependencies necessary for email services, API interactions, authentication, and monitoring
- The setup targets Node.js environment version 20, ensuring compatibility and performance optimization.generate-swagger.js - Generates a Swagger YAML documentation file for the Restaurant Management System API, detailing endpoints, authentication methods, and other service definitions
- This documentation supports API clarity and integration efforts across the development team, ensuring consistent and accessible API references.swagger.yaml - Defines and documents the API endpoints for user authentication within the system, including user registration, login, and token refresh operations
- It specifies the required data structures, expected responses, and error handling for these processes, facilitating clear communication between the server and client applications.scripts
setup-dev.sh - Facilitates the setup of a development environment for a restaurant management system by registering a user, updating user privileges, logging in the user, and configuring restaurant tables and opening hours through various API endpoints
- It automates initial data seeding and configuration tasks to streamline developer onboarding and testing.setup-prod.sh - Facilitates the setup of a production environment for a restaurant management system by registering user credentials, logging in to retrieve authentication tokens, and using these tokens to add restaurant tables and opening hours via API calls
- This script ensures essential components are initialized for system functionality.start_dev.sh - Initiates the development environment setup by navigating to the functions directory and executing the setup-dev.sh script
- This script is crucial for preparing the necessary configurations and dependencies specific to development tasks, ensuring that all components within the project's architecture are correctly aligned for development activities.app
middlewares
privilages.middleware.js - Provides middleware functions to enforce user access control within the application
- It includes mechanisms to verify if a user holds specific privileges, such as being an owner or an employee, using Firebase authentication and user privilege data stored in Firestore
- These checks are essential for securing routes that require elevated permissions.auth.middleware.js - Auth.middleware.js serves as a security layer within the application, responsible for verifying Firebase ID tokens
- It ensures that incoming requests to the server are authenticated by checking and decoding tokens provided in the request headers, thereby granting or denying access based on the token's validity.config
auth.config.js - Manages authentication URLs for Firebase services, adapting to different environments by checking if the Firebase emulator is active
- It configures endpoints for user sign-in and token refresh processes, ensuring seamless authentication operations whether in development or production settings
- This setup supports both standard and custom token-based authentications.prometheus.config.js - Prometheus.config.js configures middleware for capturing and exposing metrics from the RMS-API, a REST API project
- It enhances monitoring by tracking HTTP method, path, status code, and system health
- Custom labels identify the project within the metrics
- This setup aids in performance analysis and operational oversight by integrating with Prometheus, a monitoring tool.firebase.config.js - Initializes the Firebase Admin SDK to enable server-side interactions with Firebase services
- It sets up the application instance and Firestore database access, which are crucial for backend operations such as authentication, data storage, and retrieval
- These configurations are essential for integrating Firebase functionalities across the entire application architecture.controllers
reservation.controller.js - ReservationController manages reservation operations within a restaurant reservation system, handling tasks such as creating, canceling, confirming, completing, rescheduling, and retrieving reservations
- It integrates user and table validation, manages reservation overlaps, and communicates with users through email notifications regarding reservation statuses.window.controller.js - WindowController manages interactions with window data within the application, facilitating operations such as retrieving, creating, updating, and deleting windows
- It utilizes services and validators to ensure data integrity and handle requests, providing structured responses based on the outcome of these operations.door.controller.js - DoorController serves as the interface for managing door entities within the application, handling operations such as retrieving, creating, updating, and deleting doors
- It utilizes service layer interactions and validation mechanisms to ensure data integrity and provide appropriate responses to client requests.auth.controller.js - AuthController manages user authentication and authorization processes within the application
- It handles user operations such as registration, login, token refresh, and account management, including creating roles like employees and owners, deleting accounts, and integrating Google sign-in
- This controller ensures secure user access and identity management across the system.user.controller.js - UserController serves as a central component for user management within the application, facilitating operations such as retrieving individual or groups of users, updating user privileges, and handling user verification
- It interacts with the UserService to perform these functions and utilizes structured responses for consistency in communication with clients.table.controller.js - TableController manages interactions with table data, facilitating operations such as retrieving, creating, updating, deleting, and toggling the activation status of tables
- It handles request validation, interacts with the TableService for data manipulation, and formats responses to ensure consistent communication with clients.floorPlan.controller.js - FloorPlanController serves as a central component in the application's architecture, orchestrating the aggregation of data related to floor plans
- It interacts with services dedicated to managing doors, walls, windows, and tables, compiling these elements into a comprehensive floor plan structure, which is then delivered to the client upon request.wall.controller.js - WallController serves as the interface for managing wall entities within the application, facilitating operations such as retrieving, creating, updating, and deleting walls
- It interacts with the WallService to execute business logic and utilizes utility functions and validators to handle responses and data integrity.openingHours.controller.js - OpeningHoursController manages interactions with opening hours data, facilitating operations such as retrieval, creation, updating, and deletion of opening hours records
- It utilizes services and models to handle business logic and data validation, ensuring responses are correctly formatted and errors are handled efficiently.validators
reservation.validators.js - Validates reservation-related data within the application, ensuring compliance with required formats and constraints
- Functions check the validity of date-time strings, reservation request completeness, and the integrity of input types such as integers for table IDs and number of people, enhancing data reliability for reservation management.openingHours.validators.js - Validates the opening hours input from a request by ensuring all required fields are present and correctly formatted
- It checks that the day, start time, and end time are specified, and verifies that the start time is earlier than the end time
- Errors are returned if any validations fail, facilitating reliable scheduling data management within the application.window.validators.js - Validates parameters for creating and updating window and wall entities within an application
- It ensures all required fields are present and correctly formatted as integers, including coordinates and dimensions
- Errors are returned for any validation failures, facilitating robust data handling and integrity in the system's architecture.wall.validators.js - Validates user input for creating and updating wall coordinates within the application
- The functions ensure all required fields are present and that each coordinate value is an integer
- This validation process helps maintain data integrity and prevents errors during wall creation and modification operations in the system.auth.validators.js - Validates user input for registration, login, and refresh token requests within the authentication process
- It ensures all necessary fields are provided and checks email format validity
- These validations are crucial for maintaining data integrity and security across user interactions in the system, facilitating reliable user management and authentication workflows.door.validators.js - Validates the creation and updating of door entities within the application by ensuring all required fields (x, y, width, height, rotation) are present and correctly formatted as integers
- These functions serve as a crucial checkpoint in the data integrity process, preventing errors in door data management.table.validators.js - Validates parameters for creating a table within an application, ensuring all required fields such as seat count, window proximity, and spatial coordinates are correctly formatted and present
- Errors are returned for any invalid or missing data, facilitating reliable data entry and integrity in table management operations.models
reservation.model.js - Defines and manages reservation data within the application, encapsulating the creation and conversion of reservation instances to and from Firestore-compatible formats
- It includes a class for reservation objects with methods for Firestore integration and an enumeration of possible reservation statuses, facilitating consistent state management across the system.user.model.js - Defines and manages the User model, encapsulating attributes such as unique identifier, name, email, phone number, and privileges
- It includes methods to serialize and deserialize User instances for compatibility with Firestore, ensuring smooth data transactions and state management within the application's backend architecture.openingHours.model.js - Defines and manages the structure for storing opening hours in a system, encapsulating days of the week and specific start and end times
- It includes functionality to serialize and deserialize these details to and from a Firestore database format, ensuring data integrity and ease of data manipulation within the application's backend architecture.wall.model.js - Wall.model.js defines a Wall class essential for representing and managing wall entities within the application's model layer
- It facilitates the conversion of wall data between the application's internal representation and Firestore database format, ensuring seamless data persistence and retrieval operations integral to the system's architecture.door.model.js - Door model in functions/app/models/door.model.jsserves as a data structure for door entities, encapsulating properties like position, size, and orientation
- It includes methods for serializing to and from Firestore, ensuring data integrity and facilitating easy storage and retrieval within the application's database architecture.table.model.js - Defines the Table class, encapsulating properties such as ID, seat count, window proximity, activity status, and spatial coordinates
- It includes methods to convert table instances for compatibility with Firestore and to instantiate from Firestore data, facilitating data management and integration within the application's model layer.window.model.js - Window.model.js defines a Window class essential for managing window entities within the application
- It facilitates the creation, manipulation, and storage of window attributes such as position, size, and rotation
- The class also includes methods for serialization and deserialization to interface seamlessly with Firestore, ensuring data integrity and ease of data handling across the system.routes
user.router.js - User.router.js establishes routes for managing user data within the application
- It includes endpoints for retrieving individual or all user details, listing privileged users, and modifying user privileges
- Authentication and authorization are enforced through middleware to ensure secure access based on user roles.floorPlan.router.js - Defines routing for floor plan retrieval within the application, interfacing with the FloorPlanController to serve floor plan details via an HTTP GET request
- It supports the architecture by enabling the extraction of structured information about tables, doors, walls, and windows, crucial for client-side rendering or further processing within the system.door.router.js - Manages door-related operations within the application, interfacing with the DoorController to handle CRUD operations on doors
- It ensures security through middleware that verifies user tokens and ownership, supporting operations like listing, retrieving, creating, updating, and deleting doors, with comprehensive API documentation provided via Swagger.window.router.js - Window.router.js establishes the routing logic for window-related operations within the application, interfacing with the WindowController
- It handles API endpoints for creating, retrieving, updating, and deleting window records, ensuring access control through authentication and ownership verification middleware
- This integration facilitates secure and efficient window management in the system.table.router.js - Manages table-related operations within a web application, interfacing through RESTful endpoints to handle tasks such as retrieving, creating, updating, deleting, and toggling the activation status of tables
- It integrates security and ownership checks to ensure authorized access and modifications to table data.openingHours.router.js - Manages the API endpoints for opening hours within the application, facilitating operations such as retrieving, creating, updating, and deleting opening hours
- It integrates authentication and ownership checks to ensure secure and authorized access to these functionalities.wall.router.js - Wall.router.js serves as a routing layer within the application, directing HTTP requests related to "walls" to appropriate controller actions
- It handles operations such as retrieving, creating, updating, and deleting walls, ensuring access control through middleware that verifies user identity and ownership.auth.router.js - Auth.router.js establishes the authentication routes for user operations within the application, interfacing with AuthController to handle actions like user registration, login, token refresh, and account management
- It integrates middleware for security and privilege checks, supporting both standard and Google-based authentication methods.reservation.router.js - Manages reservation-related operations within the application, interfacing with the ReservationController to handle tasks such as creating, canceling, confirming, completing, rescheduling, and retrieving reservations
- It ensures user authentication and authorization through middleware checks, supporting both individual and bulk reservation management actions.utils
response.utils.js - Creates and structures response objects for the application, handling the encapsulation of status codes, messages, and optional data payloads
- This utility is pivotal for standardizing API responses across the system, ensuring consistency and clarity in communication between the server and clients
- It supports maintainability and scalability by centralizing response formatting logic.counter.utils.js - Counter.utils.js serves as a utility module within the application's architecture, primarily responsible for initializing various counter documents in a Firestore database
- It ensures that counters for tables, opening hours, walls, windows, and doors are set to zero if they do not already exist, facilitating consistent data tracking across the application.services
window.service.js - WindowService in functions/app/services/window.service.jsmanages window entities within a Firebase database
- It supports operations such as retrieving, creating, updating, and deleting windows, leveraging Firestore for data handling
- This service is crucial for manipulating window data across the application, ensuring data integrity and consistency.user.service.js - UserService, located within the services layer of the application, manages user-related operations
- It facilitates user authentication, data retrieval, and privilege management by interfacing with Firebase
- Key functionalities include verifying user identities, fetching user details or lists from the database, and updating user privileges
- This component is essential for maintaining secure and efficient user data interactions within the system.table.service.js - TableService in the application manages interactions with the database concerning table entities
- It facilitates operations such as retrieving, creating, updating, and deleting tables, as well as fetching tables based on minimum seat requirements
- This service utilizes Firebase for data storage and transactions, ensuring data integrity and consistency across operations.reservation.service.js - ReservationService in reservation.service.jsmanages reservation data interactions within a restaurant booking system
- It facilitates checking for reservation overlaps, creating, updating, rescheduling, and retrieving reservations by various parameters such as user ID, time range, and status, ensuring efficient and conflict-free scheduling and management of table bookings.email.service.js - EmailService in functions/app/services/email.service.jsmanages the dispatch of reservation status emails to users
- It supports sending emails for pending, confirmed, and cancelled reservations, leveraging template IDs and personalized content to ensure users receive accurate and timely updates about their bookings.door.service.js - DoorService in the application's services layer manages door-related operations within a Firebase database
- It provides functionalities to retrieve, create, update, and delete door entries, as well as fetch all doors
- This service utilizes the Door model for data handling and interacts directly with the database for CRUD operations.wall.service.js - WallService in the application's service layer manages wall data interactions with the Firebase database
- It provides functionalities to create, retrieve, update, and delete wall records
- This service ensures data consistency and handles operations like fetching all walls or a specific wall by ID, updating wall dimensions, and maintaining a counter for wall IDs.auth.service.js - AuthService facilitates user management within the application by handling tasks such as user creation, login, token refresh, and account deletion across different user roles (customer, employee, owner) using Firebase Authentication and Firestore
- It supports operations like password resets and integrates Google sign-in for streamlined access management.openingHours.service.js - OpeningHoursService manages the lifecycle of opening hours data within the application
- It provides functionalities to create, retrieve, update, and delete opening hours information, interfacing with a Firebase database
- This service ensures data consistency and integrity through transactions, particularly when creating new entries.
Before getting started with RMS-API, ensure your runtime environment meets the following requirements:
- Programming Language: JavaScript
- Package Manager: Npm
Install RMS-API using one of the following methods:
Build from source:
- Clone the RMS-API repository:
❯ git clone https://github.com/Unemployed-CS-Majors/RMS-API- Navigate to the project directory:
❯ cd RMS-API- Install the project dependencies:
❯ npm installRun RMS-API using the following command:
Using npm
❯ npm startRun the test suite using the following command:
Using npm
❯ npm test-
Task 1:Implement feature one. -
Task 2: Implement feature two. -
Task 3: Implement feature three.
- 💬 Join the Discussions: Share your insights, provide feedback, or ask questions.
- 🐛 Report Issues: Submit bugs found or log feature requests for the
RMS-APIproject. - 💡 Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/Unemployed-CS-Majors/RMS-API
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.' - Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.
- List any resources, contributors, inspiration, etc. here.