A comprehensive RESTful API built with Ruby on Rails for restaurant operations management, including order processing, table management, menu items, invoicing, and staff coordination.
- Overview
- Features
- Tech Stack
- Database Schema
- API Endpoints
- Authentication and Authorization
- Real-time Features
- Setup and Installation
- Docker Support
- Deployment
- Testing
The Restaurant Management API is a backend service designed to support the operations of a restaurant, from taking orders and processing them in the kitchen to managing tables and generating invoices. The system provides a real-time communication layer for instant updates between waiters, kitchen staff, and management.
- User Management: Role-based access for staff (waiters, cooks, administrators)
- Table Management: Track table status (available, occupied) and capacity
- Menu Management: Product catalog with categories, descriptions, and prices
- Order Processing: Complete order lifecycle from creation to fulfillment
- Create orders with multiple items
- Process orders in the kitchen
- Dispatch individual items as they are prepared
- Mark orders as completed
- Invoicing: Generate and manage invoices for completed orders
- Client Management: Store customer information for loyalty programs and invoicing
- Real-time Updates: WebSocket integration for instant communication between staff
- Audit Logging: Track system events and changes for operational analysis
- Ruby: 3.2.2
- Rails: 7.1.2
- Database: PostgreSQL
- Authentication: Devise with JWT tokens
- Authorization: CanCanCan for role-based access control
- WebSockets: Action Cable with Faye for real-time communication
- API Serialization: Panko Serializer for fast JSON rendering
- Background Processing: Redis for caching and job queues
- Testing: RSpec for test suite
- Containerization: Docker support for easy deployment
The system is built around these primary entities:
- Users: Staff members with roles (waiter, cook, admin)
- Tables: Restaurant tables with status and capacity information
- Products: Menu items with prices and categories
- Orders: Customer orders linked to tables and waiters
- Items: Individual items within an order with preparation status
- Clients: Customer records for loyalty and invoicing
- Invoices: Financial records of completed orders
- Events: Audit trail of system activities
- Authentication via Devise/JWT
GET /tables- List all tablesGET /tables/:id- Show table detailsPUT /tables/:id- Update table informationPOST /tables/:id/occupy- Mark table as occupiedPOST /tables/:id/release- Mark table as available
GET /products- List all menu itemsGET /products/:id- Show product detailsPOST /products- Create new productPUT /products/:id- Update productDELETE /products/:id- Remove product
GET /orders- List ordersGET /orders/:id- Show order detailsPOST /orders- Create new orderPUT /orders/:id- Update orderPUT /orders/:id/in_process- Mark order as in preparationPUT /orders/:id/dispatch_order- Mark order as completePATCH /orders/:id/dispatch_item/:item_id- Mark specific item as prepared
GET /items- List order itemsPOST /items- Add item to orderPUT /items/:id- Update order itemDELETE /items/:id- Remove item from order
GET /clients- List clientsPOST /clients- Create clientGET /clients/:id- Show client detailsPUT /clients/:id- Update clientDELETE /clients/:id- Remove client
GET /invoices- List invoicesGET /invoices/:id- Show invoice detailsPOST /invoices- Generate new invoice
GET /audits- Access system event logs
The API uses JWT (JSON Web Token) authentication via Devise and Devise-JWT. Authorization is implemented using CanCanCan with the following roles:
- Admin: Full access to all features
- Waiter: Manage tables, create/update orders, add clients
- Cook: Update order and item status
The application uses Action Cable and Faye WebSockets to provide real-time updates:
- Order status changes are instantly communicated to staff
- New orders appear immediately in the kitchen interface
- Table status updates are broadcast in real time
- Ruby 3.2.2
- PostgreSQL
- Redis
# Clone the repository
git clone https://github.com/scaminom/restaurant-api.git
cd restaurant-api
# Install dependencies
bundle install
# Setup database
rails db:create
rails db:migrate
rails db:seed # Optional: add sample data
# Start the server
rails serverThe application includes Docker configuration for easy deployment:
# Build the Docker image
docker build -t restaurant-api .
# Run the container
docker run -p 3000:3000 restaurant-apiThe repository includes configuration for deployment on Render:
# render.yaml
services:
- type: web
name: restaurant-api
env: ruby
buildCommand: bundle install && bundle exec rake assets:precompile
startCommand: bundle exec puma -C config/puma.rb
envVars:
- key: RAILS_MASTER_KEY
sync: falseThe application uses RSpec for testing:
# Run all tests
bundle exec rspec
# Run specific test file
bundle exec rspec spec/models/order_spec.rb