Skip to content

localbite-davis/localbite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

53 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Localbite πŸ”

Localbite is a modern, full-stack food delivery platform connecting customers with local restaurants. Built with Next.js 16 (Frontend) and FastAPI (Backend), it features role-based access for Customers, Restaurant Owners, and Delivery Agents.


πŸ—οΈ Tech Stack

Frontend

  • Framework: Next.js 16 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • UI Components: shadcn/ui
  • Icons: Lucide React
  • State Management: React Context API
  • Form Handling: React Hook Form + Zod validation

Backend

  • Framework: FastAPI
  • Language: Python 3.10+
  • Database: PostgreSQL (via Supabase) with SQLAlchemy ORM
  • Authentication: JWT (JSON Web Tokens) with HttpOnly cookies
  • Password Hashing: Argon2 (via Passlib)
  • Validation: Pydantic schemes

πŸ“‚ Project Structure

localbite/
β”œβ”€β”€ localbite-backend/       # Python FastAPI Application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/             # API Route Handlers (endpoints)
β”‚   β”‚   β”œβ”€β”€ core/            # Config, Security, Hashing utilities
β”‚   β”‚   β”œβ”€β”€ crud/            # Database Operations (Create, Read, Update, Delete)
β”‚   β”‚   β”œβ”€β”€ models/          # SQLAlchemy Database Models
β”‚   β”‚   β”œβ”€β”€ schemas/         # Pydantic Request/Response Schemas
β”‚   β”‚   └── database.py      # Database Connection Setup
β”‚   β”œβ”€β”€ main.py              # Application Entry Point
β”‚   └── requirements.txt     # Python Dependencies
β”‚
β”œβ”€β”€ localbite-frontend/      # Next.js Application
β”‚   β”œβ”€β”€ app/                 # App Router Pages & Layouts
β”‚   β”‚   β”œβ”€β”€ dashboard/       # Role-protected Dashboards (Customer/Restaurant)
β”‚   β”‚   β”œβ”€β”€ login/           # Authentication Pages
β”‚   β”‚   └── page.tsx         # Landing Page
β”‚   β”œβ”€β”€ components/          # Reusable UI Components
β”‚   β”œβ”€β”€ context/             # React Context (Auth, Theme)
β”‚   β”œβ”€β”€ hooks/               # Custom React Hooks
β”‚   β”œβ”€β”€ lib/                 # Utilities & Mock Data
β”‚   └── public/              # Static Assets
└── README.md                # Project Documentation

✨ Features & Functionality

1. Authentication & Roles πŸ”

  • Secure Login/Signup: Supports separate flows for Customers, Restaurant Owners, and Delivery Agents.
  • JWT Auth: HttpOnly cookies for secure session management.
  • Role-Based Redirects: Automatically routes users to their specific dashboard upon login.

2. Customer Dashboard πŸ‘€

  • Restaurant Discovery: Browse and search restaurants by name or cuisine.
  • Menu Interaction: View detailed restaurant menus with categories.
  • Smart Filtering: Filter by cuisine type (Thai, Mexican, Halal, etc.).
  • Live Data: Connects to backend API for real-time restaurant and menu data.

3. Restaurant Dashboard 🍳

  • Menu Management: Add, update, and delete menu items dynamically.
  • Business Insights: View order stats and manage restaurant profile (Name, Cuisine, etc.).
  • Real-time Updates: Changes reflect immediately on the customer side.

4. Delivery Agent Dashboard πŸ›΅

  • Task Management: (In progress) View available orders for pickup.
  • Earnings Tracker: Monitor completed deliveries and earnings.

πŸš€ API Endpoints

The backend provides a comprehensive REST API. Once running, visit http://localhost:8000/docs for the interactive Swagger UI.

Key Endpoints

Method Endpoint Description
Auth /api/v1/auth/signup Register a new user
Auth /api/v1/auth/token Login & receive access token
Restaurant /api/v1/restaurants/ List all restaurants
Restaurant /api/v1/restaurants/{id} Get restaurant details
Menu /api/v1/menu/restaurant/{id} Get menu items for a restaurant
Menu /api/v1/menu/ Create new menu item (Auth required)

πŸ› οΈ Setup & Installation

Prerequisites

  • Node.js: v18+ & npm
  • Python: v3.10+
  • PostgreSQL Database: Local instance or cloud (e.g., Supabase, Neon)

1. Backend Setup

  1. Navigate to the backend directory:

    cd localbite-backend
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Environment Configuration (.env): Create a .env file in localbite-backend/ with the following variables:

    # Database Configuration
    DB_USER=your_db_user
    DB_PASSWORD=your_db_password
    DB_HOST=your_db_host.supabase.co
    DB_NAME=postgres
    
    # Security
    SECRET_KEY=your_super_secret_key_openssl_rand_hex_32
    ALGORITHM=HS256
    ACCESS_TOKEN_EXPIRE_MINUTES=30
  5. Run the server:

    uvicorn main:app --reload

    Server will start at http://localhost:8000.

2. Frontend Setup

  1. Navigate to the frontend directory:
    cd localbite-frontend

Running the Application (Backend + Redis, Recommended)

Before starting, ensure your Neon connection is configured in:

  • localbite-backend/.env (DATABASE_URL=...) or set the individual DB env vars used by the backend.

Start backend + local Redis:

./deploy_backend.sh

This starts:

Running the Frontend (Local)

cd localbite-frontend
npm install
npm run dev

Frontend:

Integration Workflow (Dispatch + Bidding)

Run the Postman/Newman integration workflow (local backend):

./run_api_tests.sh

Reports are written to:

  • localbite-backend/postman/reports/

Running the Application (Older Local Scripts)

To start both the Backend and Frontend servers in separate terminals, run:

./start_servers.sh

This will launch:

Backend + Redis (Dispatch/Bidding Testing, Alternative)

For dispatch timer and bidding workflows (which require Redis), use:

cd localbite-backend
./scripts/start_backend_with_redis.sh

API Documentation

Once the backend is running, you can access the interactive API docs at:

Base Fare Recommendation API

New endpoint:

  • POST /api/v1/fares/recommendation

Purpose:

  • Calculates base_fare (minimum bidding fare for delivery agents)
  • Calculates max_bid_limit (1.5x of base_fare)
  • Returns eta_estimate_minutes

Payload supports either:

  • distance_km from your distance API, or
  • coordinates for both user and restaurant (latitude/longitude) to compute distance with Haversine.

Example request body:

{
  "user_location": {
    "address": "500 1st St, Davis, CA",
    "latitude": 38.5449,
    "longitude": -121.7405
  },
  "restaurant_location": {
    "address": "220 G St, Davis, CA",
    "latitude": 38.5435,
    "longitude": -121.7407
  },
  "incentive_metrics": {
    "demand_index": 1.1,
    "supply_index": 0.9,
    "weather_severity": 0.1
  }
}

Delivery Agent Bidding API

New endpoint:

  • POST /api/v1/delivery-bids/

Behavior:

  • Validates bid against the order's bidding window:
    • minimum = orders.base_fare
    • maximum = 1.5 * orders.base_fare
  • Supports phased dispatch bidding:
    • student_pool: only student delivery agents can bid
    • all_agents: all active agents can bid

Example request body:

{
  "order_id": 101,
  "agent_id": "agent_123",
  "bid_amount": 6.5,
  "pool_phase": "student_pool"
}

Accept a bid (assign order + stop dispatch flow):

  • POST /api/v1/delivery-bids/{bid_id}/accept

Notes:

  • Marks selected bid as accepted
  • Rejects competing placed bids for the same order
  • Assigns orders.assigned_partner_id
  • Updates dispatch state in Redis so phase timers stop

Dispatch (Phase Timer) API

New endpoints:

  • POST /api/v1/dispatch/orders/{order_id}/start
  • GET /api/v1/dispatch/orders/{order_id}/status

Behavior:

  • Starts two-phase dispatch in background
  • Phase 1 (student_pool): student-only broadcast, waits configurable timer
  • Phase 2 (all_agents): full-pool broadcast, waits configurable timer
  • If still unassigned after Phase 2: status becomes needs_fee_increase

Example start request body:

{
  "delivery_address": "500 1st St, Davis, CA",
  "phase1_wait_seconds_min": 180,
  "phase1_wait_seconds_max": 240,
  "phase2_wait_seconds": 180,
  "poll_interval_seconds": 5
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages