Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/viet2811/ocipe/llms.txt

Use this file to discover all available pages before exploring further.

The Ocipe backend is a Django 5.2.1 application using Django REST Framework, SimpleJWT for token authentication, and PostgreSQL as its database. It also integrates Google Gemini for AI-powered recipe autofill. This guide walks through local setup and production deployment on Render.

Requirements

  • Python 3.11 or later
  • PostgreSQL (local instance or managed cloud database)
  • pip with virtualenv, or Docker
Key packages (from requirements.txt):
PackageVersionPurpose
Django5.2.1Core web framework
djangorestframework3.16.0REST API toolkit
djangorestframework_simplejwt5.5.0JWT authentication
django-cors-headers4.7.0Cross-origin request handling
django-filter25.1Query filtering for API views
psycopg2-binary2.9.10PostgreSQL adapter
gunicorn23.0.0Production WSGI server
google-genai1.16.1Google Gemini AI integration
python-dotenv1.1.0.env file loading

Local setup

1

Clone the repository and enter the backend directory

git clone https://github.com/viet2811/ocipe.git
cd ocipe/backend
2

Create and activate a virtual environment

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

Install dependencies

pip install -r requirements.txt
4

Configure environment variables

Create a .env file in ocipe/backend/ with the required values. See Environment Variables for the full reference.
# ocipe/backend/.env
DJANGO_SECRET=your-secret-key-here
POSTGRES_DB=ocipe
POSTGRES_USER=postgres
POSTGRES_PASSWORD=yourpassword
POSTGRES_HOST=localhost
GEMINI_API_KEY=your-gemini-key
5

Apply database migrations

python manage.py migrate
6

Start the development server

python manage.py runserver
The API will be available at http://localhost:8000/api/.

Django apps

The project is split into five focused Django applications, each mounted under a dedicated API prefix:
AppURL prefixResponsibility
recipes/api/recipes/Recipe CRUD operations, ingredient management, and Google Gemini AI autofill for recipe details
users/api/user/User registration, JWT token issuance (CookieTokenObtainPairView), token refresh (CookieTokenRefreshView), and logout
fridge/api/fridge/Per-user fridge inventory — tracking what ingredients each user currently has on hand
grocery/api/grocery/Grocery list generation and history tracking for planned shopping
monitoring/api/monitoring/Health-check and monitoring endpoints used by the hosting platform

Security settings

The production settings.py enforces HTTPS and secure cross-origin cookie handling:
# settings.py (production-relevant excerpts)

DEBUG = False

SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

CORS_ALLOWED_ORIGINS = [
    "https://ocipe.vercel.app",
]
CORS_ALLOW_CREDENTIALS = True

ALLOWED_HOSTS = ["ocipe.onrender.com"]
The JWT refresh token is set as an HTTP-only cookie by CookieTokenObtainPairView in the users app:
response.set_cookie(
    key='refresh_token',
    value=refresh,
    httponly=True,
    secure=True,
    samesite="None",
    max_age=3600 * 24 * 30  # 30 days
)
SameSite=None is required because the frontend (Vercel) and backend (Render) are on different origins. Both Secure=True and SameSite=None must be set together for cross-site cookies to work in modern browsers.

Production deployment on Render

Render is the recommended hosting platform for the Ocipe backend. Follow these steps to create a new Web Service:
  1. Push your code to a GitHub repository and sign in to Render.
  2. Click New → Web Service and connect your repository. Set the Root Directory to backend.
  3. Set the Build Command:
    pip install -r requirements.txt && python manage.py migrate
    
  4. Set the Start Command:
    gunicorn ocipe.wsgi
    
  5. Add your environment variables in the Render dashboard under Environment. See Environment Variables for the complete list.
  6. Create a PostgreSQL database from Render’s dashboard and copy the connection details into your environment variables (POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST).
  7. Update ALLOWED_HOSTS in settings.py to include your Render service hostname, and update CORS_ALLOWED_ORIGINS if your frontend is deployed to a different domain than ocipe.vercel.app.
Never set DEBUG=True in production. Doing so exposes full tracebacks, internal settings, and the browsable API without authentication to anyone who can reach the server.

Build docs developers (and LLMs) love