Minimal FastAPI backend for the Piazza AI browser extension. This is a starter template that can be extended with additional features as needed.
This backend currently provides:
- Basic FastAPI application with CORS support for browser extensions
- One example endpoint (
/api/v1/health) to demonstrate the structure - Environment-based configuration using Pydantic Settings
- Supabase integration ready with database configuration
- Minimal dependencies - FastAPI, Uvicorn, Pydantic, and psycopg2
cd backend
touch .envEdit the .env file with your specific values:
APP_NAME="Piazza AI Plugin"
ENVIRONMENT=development
DEBUG=true
VERSION=1.0.0
HOST=0.0.0.0
PORT=8000
API_PREFIX=/api/v1
ALLOWED_ORIGINS=["http://localhost:3000", "chrome-extension://*", "https://piazza.com"]
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres
To get your actual Supabase keys, run:
cd ../supabase
supabase statusCopy the values from the output:
- Database URL →
DATABASE_URL
Calendar features use OAuth 2.0 (a Client ID and Client secret for a Web application client). You need to set up Google Cloud Console for the calendar features to work.
-
In Google Cloud Console, select or create a project.
-
APIs & Services → Library → enable Google Calendar API.
-
APIs & Services → OAuth consent screen → configure the app type, scopes, and test users if the app is in testing.
-
APIs & Services → Credentials → Create credentials → OAuth client ID → type Web application.
-
Under Authorized redirect URIs, add the callback URL your backend uses. With the default local setup (
API_PREFIX=/api/v1inmain.pyand the calendar router mounted at/calendar), the redirect URI is:http://localhost:8000/api/v1/calendar/callbackThis must match exactly what is in your
.envand in the OAuth client. Mismatches produceredirect_uri_mismatchfrom Google. -
Copy the Client ID and Client secret from the new client (or from the downloaded JSON).
Add the following variables to backend/.env (names must match app/api/endpoints/calendar.py):
GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
GOOGLE_CLIENT_PROJECT_ID="your-gcp-project-id"
GOOGLE_CLIENT_CLIENT_SECRET="your-client-secret"
GOOGLE_CLIENT_AUTH_URI="https://accounts.google.com/o/oauth2/auth"
GOOGLE_CLIENT_TOKEN_URI="https://oauth2.googleapis.com/token"
GOOGLE_CLIENT_AUTH_PROVIDER_X509_CERT_URL="https://www.googleapis.com/oauth2/v1/certs"
GOOGLE_CLIENT_REDIRECT_URIS=["http://localhost:8000/api/v1/calendar/callback"]Notes:
GOOGLE_CLIENT_REDIRECT_URISis parsed as JSON; keep it valid JSON on one line.- For production, add your deployed callback URL to both Google Cloud Authorized redirect URIs and this JSON array, and keep the same URI in your deployed backend configuration.
- Restart the backend after changing OAuth-related environment variables.
When using the Smart Resource Aggregator feature, configure the following environment variables (see app/core/config.py for details):
YOUTUBE_API_KEY– API key for YouTube Data API v3.STACKEXCHANGE_API_KEY– API key for Stack Exchange (optional depending on usage).STACKEXCHANGE_SITE– Stack Exchange site to query (default:stackoverflow).
cd backend
pip install -r requirements.txtcp .env.example .env
# Edit .env with your values (see Environment Configuration above)python main.pyThe server will start at http://localhost:8000
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/api/v1/health
- Root: http://localhost:8000/
backend/
├── app/
│ ├── api/
│ │ ├── routes.py # Main API router with example endpoint
│ │ └── endpoints/ # Individual endpoint modules (empty for now)
│ ├── core/
│ │ ├── database.py # Database setup (placeholder)
│ └── models/ # Database models (placeholder)
├── tests/ # Test files (minimal setup)
├── main.py # FastAPI application entry point
├── requirements.txt # Minimal dependencies
└── .env.example # Environment variables template
# Add new dependencies to requirements.txt
echo "new-package==1.0.0" >> requirements.txt
pip install -r requirements.txt# Install dev dependencies
pip install -r requirements-dev.txt
# Format code
black .
# Lint code
ruff check .
# Type checking
mypy .# Run tests
pytest
# Add new tests in tests/ directory
# Example: tests/test_api.pyThe backend is configured to accept requests from browser extensions:
# CORS is already configured in main.py for:
allow_origins=[
"http://localhost:3000", # Local development
"chrome-extension://*", # Chrome extensions
]Copy .env.example to .env and customize:
# Basic settings
ENVIRONMENT=development
DEBUG=true
HOST=0.0.0.0
PORT=8000
# Add database URL when needed
# DATABASE_URL=postgresql://user:password@localhost:5432/databaseFor Google Calendar OAuth, set the GOOGLE_CLIENT_* variables documented in Google Calendar API and OAuth credentials (step 4 under Environment Configuration).
python main.py# Set production environment
export ENVIRONMENT=production
# Run with multiple workers
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4