Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Backend
**/__pycache__/
**/*.pyc

# Frontend
frontend/logs
frontend/*.log
frontend/npm-debug.log*
frontend/yarn-debug.log*
frontend/yarn-error.log*
frontend/pnpm-debug.log*
frontend/lerna-debug.log*
frontend/node_modules
frontend/dist
frontend/dist-ssr
frontend/*.local

# Environment variables and secrets
**/.env
**/.env.*
**/*.pem
**/*.key

# Git
.git/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Stage 1: Build the frontend

FROM node:22-alpine AS frontend-build

WORKDIR /frontend

# Copy the files required for installing packages
COPY frontend/package.json frontend/package-lock.json ./

# Install packages
RUN npm ci

# Copy the source code
COPY frontend/ ./

# Compile the frontend
RUN npm run build


# Stage 2: Prepare the backend + docker container

FROM python:3.12-slim

WORKDIR /app

# Copy the requirements file
COPY backend/requirements.txt ./

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the source code
COPY backend/app/ ./backend/

# Copy the compiled frontend files
COPY --from=frontend-build /frontend/dist ./frontend/

# Port of the webserver
EXPOSE 8000

# Start the FastAPI application
CMD ["uvicorn", "backend.main:main", "--host", "0.0.0.0", "--port", "8000"]
96 changes: 69 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,56 @@ git clone https://github.com/RealUltra/OpenEats
cd OpenEats
```

## Virtual Environment
## Development

### Virtual Environment

Create a virtual environment:

### Linux / macOS
#### Linux / macOS

```bash
python3 -m venv backend/.venv
source backend/.venv/bin/activate
```

### Windows
#### Windows

```powershell
python -m venv backend\.venv
backend\.venv\Scripts\Activate.ps1
```

## Install Dependencies
### Install Dependencies

Install the required dependencies:

```bash
pip install -r backend/requirements.txt
```

## Sample Data
### Sample Data (Optional, First Run Only)

To use the sample data, rename `backend/sample-data` to `backend/data`.

### Linux / macOS
#### Linux / macOS

```bash
mv backend/sample-data backend/data
```

### Windows
#### Windows

```powershell
Rename-Item backend/sample-data backend/data
```

## Running the API
### Running the API

Start the application with:

```bash
uv run fastapi dev --entrypoint backend.app.main:main
fastapi dev --entrypoint backend.app.main:main
```

The application will be available at:
Expand All @@ -77,13 +79,13 @@ The application will be available at:
http://127.0.0.1:8000
```

## Running the Web UI
### Running the Web UI

### Prerequisites
#### Prerequisites

Install Node.js and npm.

### Start the development server
#### Start the development server

From the repository root, go into the frontend directory:

Expand All @@ -105,41 +107,81 @@ npm run dev

Open the URL printed by Vite (normally `http://localhost:5173/`).

### Using the UI
## Production

On the startup screen, choose **Customer** to browse restaurants or **Restaurant** to select an existing restaurant or create a new one. The restaurant view has tabs for general details and menu items.
### Prerequisites

Install Docker with Docker Compose.

### Sample Data (Optional, First Run Only)

To start with the sample restaurants, move `backend/sample-data` to `data` in the repository root before starting the application.

#### Linux / macOS

```bash
mv backend/sample-data ./data
```

#### Windows

```powershell
Move-Item backend/sample-data data
```

### Build
### Start the Application

From the `frontend` directory, create a production build with:
From the repository root, run:

```bash
npm run build
docker compose up --build -d
```

If there have been no changes since you last built the image, you may run:

```bash
docker compose up -d
```

### Open the Application

```text
http://127.0.0.1:8000/
```

### Stop the Application

```bash
docker compose down
```

## Using the UI

On the startup screen, choose **Customer** to browse restaurants or **Restaurant** to select an existing restaurant or create a new one. The restaurant view has tabs for general details and menu items.

## API Endpoints

The API provides the following endpoints:

| Method | Path | Description |
|---|---|---|
| GET | `/health` | `Checks if the API is running.` |
| GET | `/restaurants` | `Lists all the restaurants.` |
| GET | `/restaurants?{query}` | `Lists all the restaurants that match searching query: name=...&hasMenu=...&sort_by=...&sort_desc=...` |
| GET | `/restaurants/{restaurant_id}` | `Retrieves a specific restaurant by its ID.` |
| POST | `/restaurants` | `Creates a restaurant. Returns 201, 409 if the same name and address already exist, 422 for invalid input.` |
| PATCH | `/restaurants/{restaurant_id}` | `Updates only the fields sent. Returns 200, 404 for an unknown ID, 409 for a duplicate, 422 for invalid input.` |
| POST | `/restaurants/{restaurant_id}/menu-items` | `Creates a new menu item. Returns 201, 404 if the restaurant is not found, 422 for invalid input.` |
| PATCH | `/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Updates a menu item's fields. Returns 200, 404 if the item or restaurant is not found, 422 for invalid input.` |
| DELETE | `/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Deletes a specific menu item. Returns 204 on success, 404 if not found.` |
| GET | `/api/v1/health` | `Checks if the API is running.` |
| GET | `/api/v1/restaurants` | `Lists all the restaurants.` |
| GET | `/api/v1/restaurants?{query}` | `Lists all the restaurants that match searching query: name=...&hasMenu=...&sort_by=...&sort_desc=...` |
| GET | `/api/v1/restaurants/{restaurant_id}` | `Retrieves a specific restaurant by its ID.` |
| POST | `/api/v1/restaurants` | `Creates a restaurant. Returns 201, 409 if the same name and address already exist, 422 for invalid input.` |
| PATCH | `/api/v1/restaurants/{restaurant_id}` | `Updates only the fields sent. Returns 200, 404 for an unknown ID, 409 for a duplicate, 422 for invalid input.` |
| POST | `/api/v1/restaurants/{restaurant_id}/menu-items` | `Creates a new menu item. Returns 201, 404 if the restaurant is not found, 422 for invalid input.` |
| PATCH | `/api/v1/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Updates a menu item's fields. Returns 200, 404 if the item or restaurant is not found, 422 for invalid input.` |
| DELETE | `/api/v1/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Deletes a specific menu item. Returns 204 on success, 404 if not found.` |


## API Documentation

API documentation is available at:

```text
http://127.0.0.1:8000/docs
http://127.0.0.1:8000/api/v1/docs
```

## Running Tests
Expand Down
44 changes: 25 additions & 19 deletions backend/app/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from fastapi import FastAPI, HTTPException, Depends
from fastapi import FastAPI, HTTPException, Depends, APIRouter
from json import JSONDecodeError

from backend.app.core.dependencies import get_restaurant_service
from backend.app.schemas.restaurant import Restaurant
from backend.app.schemas.restaurant_query import RestaurantQuery
from backend.app.services.restaurant_service import RestaurantService
from backend.app.schemas.menu_item import MenuItem
from backend.app.schemas.menu_item_request import MenuItemCreate, MenuItemUpdate
from backend.app.schemas.restaurant_request import RestaurantCreate, RestaurantUpdate
from backend.app.core.exceptions import DuplicateRestaurantError, RestaurantNotFoundError

def create_routes(app: FastAPI):
@app.get("/health")
from ..core.dependencies import get_restaurant_service
from ..schemas.restaurant import Restaurant
from ..schemas.restaurant_query import RestaurantQuery
from ..services.restaurant_service import RestaurantService
from ..schemas.menu_item import MenuItem
from ..schemas.menu_item_request import MenuItemCreate, MenuItemUpdate
from ..schemas.restaurant_request import RestaurantCreate, RestaurantUpdate
from ..core.exceptions import DuplicateRestaurantError, RestaurantNotFoundError

def create_routes(api: FastAPI | APIRouter):
@api.get("/health")
async def health():
return {"status": "ok"}

@app.get("/restaurants", response_model=list[Restaurant])
@api.get("/restaurants", response_model=list[Restaurant])
def list_restaurants(params: RestaurantQuery = Depends()):
restaurant_service = get_restaurant_service()

Expand All @@ -34,7 +34,7 @@ def list_restaurants(params: RestaurantQuery = Depends()):
raise HTTPException(status_code=400, detail=str(e))
raise HTTPException(status_code=500, detail="Restaurant data failed to follow correct list[Restaurant] schema")

@app.post("/restaurants/{restaurant_id}/menu-items", response_model=MenuItem, status_code=201)
@api.post("/restaurants/{restaurant_id}/menu-items", response_model=MenuItem, status_code=201)
def create_menu_item(restaurant_id: str, request: MenuItemCreate):
restaurant_service = get_restaurant_service()

Expand All @@ -44,7 +44,7 @@ def create_menu_item(restaurant_id: str, request: MenuItemCreate):
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))

@app.patch("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", response_model=MenuItem)
@api.patch("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", response_model=MenuItem)
def update_menu_item(restaurant_id: str, menu_item_id: str, request: MenuItemUpdate):
restaurant_service = get_restaurant_service()

Expand All @@ -55,7 +55,7 @@ def update_menu_item(restaurant_id: str, menu_item_id: str, request: MenuItemUpd
raise HTTPException(status_code=404,detail=str(e))


@app.delete("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", status_code=204)
@api.delete("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", status_code=204)
def delete_menu_item(restaurant_id: str, menu_item_id: str):
restaurant_service = get_restaurant_service()

Expand All @@ -67,7 +67,7 @@ def delete_menu_item(restaurant_id: str, menu_item_id: str):
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))

@app.get("/restaurants/{restaurant_id}", response_model=Restaurant)
@api.get("/restaurants/{restaurant_id}", response_model=Restaurant)
def get_restaurant(restaurant_id: str):
restaurant_service = get_restaurant_service()

Expand All @@ -80,7 +80,7 @@ def get_restaurant(restaurant_id: str):
raise HTTPException(status_code=500, detail="Invalid JSON data")


@app.post(
@api.post(
"/restaurants",
response_model=Restaurant,
status_code=201,
Expand All @@ -98,7 +98,7 @@ def create_restaurant(request: RestaurantCreate):
raise HTTPException(status_code=409, detail=str(e))


@app.patch(
@api.patch(
"/restaurants/{restaurant_id}",
response_model=Restaurant,
summary="Update a restaurant's information",
Expand All @@ -119,3 +119,9 @@ def update_restaurant(restaurant_id: str, request: RestaurantUpdate):

except DuplicateRestaurantError as e:
raise HTTPException(status_code=409, detail=str(e))


@api.get("/", include_in_schema=False)
@api.get("/{path:path}", include_in_schema=False)
def api_not_found(path: str):
raise HTTPException(status_code=404, detail="Not Found")
4 changes: 2 additions & 2 deletions backend/app/core/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from backend.app.services.restaurant_service import RestaurantService
from backend.app.repositories.restaurant_repository import RestaurantRepository
from ..services.restaurant_service import RestaurantService
from ..repositories.restaurant_repository import RestaurantRepository

def get_data_dir() -> Path:
data_dir = Path(__file__).resolve().parents[2] / "data"
Expand Down
Loading
Loading