Skip to content

A multi-tenant backend for food delivery platforms, built with Laravel 12 and PostgreSQL, designed to quickly support restaurant chains, customers, drivers, and complex business needs.

Notifications You must be signed in to change notification settings

iamgerwin/FoodTech-Backend

Repository files navigation

Laravel Logo

Build Status Total Downloads Latest Stable Version License

FoodTech Backend

This project is a multi-tenant food delivery backend built with Laravel 12, PostgreSQL, Filament, Stancl Tenancy, and Spatie Permission. It is designed for rapid development of food delivery platforms supporting restaurant chains, customers, drivers, and advanced business logic.

Features

  • Multi-tenancy (Stancl Tenancy)
  • Role & permission management (Spatie Laravel Permission)
  • Modern admin panel (Filament)
  • Modular and scalable database structure for:
    • User & tenant management
    • Restaurants, branches, menus, orders
    • Delivery, reviews, promotions, payments, notifications, and logging

Database Structure

Entity Relationship Diagram (ERD)

You can view the initial ERD for this project here: Project ERD on dbdiagram.io

See /database/migrations/ for the full schema. Main modules and tables:

Multi-Tenancy & Users

  • tenants
  • users
  • password_reset_tokens
  • sessions

Permissions & Roles

  • permissions
  • roles
  • model_has_permissions
  • model_has_roles
  • role_has_permissions

Business Entities

  • food_chains
  • restaurants
  • restaurant_branches

Menu System

  • menu_categories
  • menu_items
  • menu_item_variants
  • branch_menu_item_overrides
  • branch_menu_item_variant_overrides
  • menu_add_ons
  • menu_add_on_menu_item
  • categories

Customers

  • customer_profiles
  • customer_addresses
  • customers

Orders & Delivery

  • orders
  • order_items
  • order_item_variants
  • deliveries
  • drivers

Promotions & Payments

  • coupons
  • coupon_usages
  • payment_transactions

Notifications & Activity

  • notifications
  • activity_log

Reviews & Misc

  • reviews

Order State Machine (Business Flow)

Below is a visualization of the allowed order state transitions as implemented in app/Domain/Order/OrderState.php:

Open Mermaid Diagram in New Tab

stateDiagram-v2
    [*] --> initiated
    initiated --> received_by_restaurant
    received_by_restaurant --> preparing
    preparing --> finding_driver
    finding_driver --> prepared
    prepared --> handed_to_driver
    handed_to_driver --> in_transit
    in_transit --> waiting_for_customer
    waiting_for_customer --> received_by_customer
    received_by_customer --> confirmed_and_feedback
    received_by_customer --> refund_requested
    received_by_customer --> complaint_received
    refund_requested --> refund_approved
    refund_requested --> refund_declined
    complaint_received --> refund_approved
    complaint_received --> refund_declined
    refund_approved --> driver_returning
    driver_returning --> restaurant_repreparing
    restaurant_repreparing --> restaurant_driver_exchange
    restaurant_driver_exchange --> driver_intransit_nth
    driver_intransit_nth --> customer_fulfilled
    confirmed_and_feedback --> customer_fulfilled
    refund_declined --> customer_fulfilled
Loading

Driver Proximity Search Logic (app/Jobs/SearchForNearbyDrivers.php)

This job is responsible for finding available drivers within a given radius from a location. It supports both a direct search and a progressive search that expands the search radius until a driver is found or a maximum radius is reached.

How It Works

  • Direct Search:
    • Find all available drivers within the specified radius using the Haversine formula.
    • For SQLite (test) environments, the calculation is performed in PHP; for production, it's done in SQL.
  • Progressive Search:
    • Start with a default radius (e.g., 5km).
    • If no drivers are found, increase the radius by a step (e.g., +5km) every X minutes, up to a maximum (e.g., 20km).
    • Stop searching as soon as one or more drivers are found or the maximum radius is reached.

Flowchart

flowchart TD
    Start([Start])
    Params{Input: lat, lng, radius, max_radius, step, interval}
    DirectSearch[Direct Search for Drivers within radius]
    FoundDrivers{Drivers Found?}
    ReturnDrivers[Return Drivers]
    ExpandRadius[Increase radius by step; Wait interval]
    MaxRadius{Radius > Max?}
    ReturnEmpty[Return empty; no drivers found]

    Start --> Params --> DirectSearch --> FoundDrivers
    FoundDrivers -- Yes --> ReturnDrivers
    FoundDrivers -- No --> MaxRadius
    MaxRadius -- No --> ExpandRadius --> DirectSearch
    MaxRadius -- Yes --> ReturnEmpty
Loading

Setup Instructions

  1. Clone & Install
    git clone <repo-url>
    cd foodtech-backend
    composer install
    cp .env.example .env
    # Configure your DB connection in .env
    php artisan key:generate
  2. Install JS dependencies (if needed)
    npm install && npm run build
  3. Run Migrations
    php artisan migrate
  4. Install Packages

Package Configuration

  • Stancl Tenancy: See config/tenancy.php for tenant setup. Models use tenant_id for scoping.
  • Spatie Permission: See config/permission.php for guard and model settings. Roles/permissions are ready for seeding.
  • Filament: Admin panel is ready for resource generation for all major models.

Next Steps

  • Generate Filament Resources for admin CRUD UI
  • Create Model Factories & Seeders for demo/test data
  • Configure tenant-aware routes and middleware
  • Set up authentication scaffolding (Breeze, Jetstream, or Fortify)

For more, see the /app/Models/ directory and the migrations for details on relationships and architecture.

Credits

FoodTech Backend is developed and maintained by John Gerwin De las Alas.

This project is built for the community as a foundation for modern, scalable, multi-tenant food delivery platforms. Contributions, suggestions, and forks are welcome!

License

This software is released as CopyFree software by John Gerwin De las Alas.

You are free to use, modify, distribute, and build upon this project for any purpose, commercial or non-commercial, without restriction.

Attribution is appreciated but not required.


For questions, improvements, or to get in touch, please contact John Gerwin De las Alas.

About

A multi-tenant backend for food delivery platforms, built with Laravel 12 and PostgreSQL, designed to quickly support restaurant chains, customers, drivers, and complex business needs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages