This is the code setup for Web Application which help users to interact with LLM models of various versions
This document provides a complete setup guide for running Aletheia, the LLM trust-study web application, on both Windows and macOS systems.
It covers installation, configuration, and database setup for local development environments.
[The detailed content from the uploaded PDF is preserved below which includes step-by-step installation, configuration, PostgreSQL setup, environment variables, backend/frontend initialization, migration commands, troubleshooting tips, and SQL view creation for user_summary and task_summary]
For the full detailed instructions, see the original Aletheia – Local Development Setup (Windows & macOS).pdf.
Project: Aletheia — Web application that lets users interact with multiple LLM personality versions (default, benevolent, authoritarian) and logs study interactions for trust analysis.
This file covers local setup (Windows/macOS) and Render deployment.
- Overview
- Repo Layout
- Prerequisites
- Quick Start — Windows
- Quick Start — macos
- Environment Files (Local)
- Run Locally
- Render Deployment (Production)
- Env Var Matrix (Local vs Render)
- Alembic Notes
- Troubleshooting
Aletheia is a Next.js + FastAPI + PostgreSQL application designed for an academic study of LLM trust. Each user is assigned one fixed personality via round-robin. The app logs demographics, chats, Google logo clicks, final answers, and survey responses for analysis.
llm/
frontend/ # Next.js + Tailwind
backend/ # FastAPI + PostgreSQL + Alembic
README.md
- PostgreSQL (local for development)
- Python 3.11 (backend)
- Node.js 20 LTS (frontend)
- Git
- (Optional) pgAdmin
Default local ports
- Backend (FastAPI):
http://127.0.0.1:8000 - Frontend (Next.js):
http://localhost:3000
# Clone
cd C:\dev
git clone <YOUR_REPO_URL> llm
cd llm
# --- Backend ---
cd backend
py -3.11 -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
# Create backend\.env (see below), then:
alembic upgrade head
uvicorn main:app --reload --host 127.0.0.1 --port 8000
# --- Frontend ---
cd ..\frontend
npm install
npm run dev# Clone
mkdir -p ~/dev && cd ~/dev
git clone <YOUR_REPO_URL> llm
cd llm
# --- Backend ---
cd backend
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Create backend/.env (see below), then:
alembic upgrade head
uvicorn main:app --reload --host 127.0.0.1 --port 8000
# --- Frontend ---
cd ../frontend
npm install
npm run devCreate these files before running the servers.
backend/.env
APP_ENV=local
SECRET_KEY=change_me_locally
ALLOW_ORIGINS=http://localhost:3000
DATABASE_URL=postgresql+psycopg2://aletheia_user:aletheia_pass@localhost:5432/aletheia
MODEL_ASSIGNMENT_MODE=round_robin
ENABLE_GOOGLE_CLICK_LOGGING=true
# GEMINI_API_KEY=...
# OPENAI_API_KEY=...
frontend/.env.local
NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000
NEXT_PUBLIC_GOOGLE_URL=https://www.google.com
NEXT_PUBLIC_SHOW_PERSONALITY=true
- Keep both servers running:
- Backend:
uvicorn main:app --reload --host 127.0.0.1 --port 8000 - Frontend:
npm run dev
- Backend:
- If you change frontend origin/port, update
ALLOW_ORIGINSinbackend/.envand restart the backend.
The steps below deploy Managed PostgreSQL, Backend (FastAPI), and Frontend (Next.js) to Render.
- In Render, New → PostgreSQL.
- Name it (e.g.,
aletheia-db), pick region and plan. - After creation, note the Internal Database URL (preferred) and External URL (optional).
- New → Web Service, connect GitHub repo, set Root Directory to
backend. - Runtime: Python
Build Command:pip install --upgrade pip && pip install -r requirements.txt
Start Command:uvicorn main:app --host 0.0.0.0 --port $PORT - Environment Variables:
APP_ENV=productionSECRET_KEY=<generate a long random string>ALLOW_ORIGINS=https://<frontend>.onrender.com,https://<custom-domain>DATABASE_URL=<Render Internal DB URL>- (Optional)
GEMINI_API_KEY,OPENAI_API_KEY MODEL_ASSIGNMENT_MODE=round_robinENABLE_GOOGLE_CLICK_LOGGING=true
- Run DB migrations via Render Shell:
cd /opt/render/project/src/backend alembic upgrade head - Verify API:
https://<backend>.onrender.com/docs
- New → Web Service (SSR) or Static Site (with
next export). For SSR, set Root Directory tofrontend. - Runtime: Node 20
Build Command:npm ci && npm run build
Start Command:npm start(ensurepackage.jsonhas"start": "next start -p $PORT") - Environment Variables:
NEXT_PUBLIC_API_BASE_URL=https://<backend>.onrender.comNEXT_PUBLIC_GOOGLE_URL=https://www.google.comNEXT_PUBLIC_SHOW_PERSONALITY=true
- Settings → Custom Domains → add domain for each service.
- Create the DNS records shown (typically CNAME).
- Update env vars accordingly:
- Backend
ALLOW_ORIGINSincludeshttps://<your-frontend-domain> - Frontend
NEXT_PUBLIC_API_BASE_URL=https://<your-backend-domain>
- Backend
- Enable Auto-deploy on
mainor specific branches. - Use Preview Environments to stage PRs.
- Service → Logs (build/runtime).
- Shell for one-off commands (e.g.,
alembic upgrade head). - Common issues: CORS not whitelisted, missing env vars, migration path.
- Never commit
.envfiles. - Store secrets in Render Environment.
- Prefer the Internal DB URL and keep services in the same region.
- Visit frontend → go through signup → demographics → tasks → survey.
- API docs at
/docsrespond 200. - Data writes visible in the managed Postgres.
- Personality fixed per user; chat/survey/final answer logging works.
- Google logo click logging works (if enabled).
| Variable | Local (backend/.env) | Render (Backend) |
|---|---|---|
APP_ENV |
local |
production |
SECRET_KEY |
any non-empty string | long random secret |
ALLOW_ORIGINS |
http://localhost:3000 |
https://<frontend>.onrender.com,https://<custom-domain> |
DATABASE_URL |
postgresql+psycopg2://aletheia_user:aletheia_pass@localhost:5432/aletheia |
Render Internal DB URL |
MODEL_ASSIGNMENT_MODE |
round_robin |
round_robin |
ENABLE_GOOGLE_CLICK_LOGGING |
true |
true |
GEMINI_API_KEY / OPENAI_API_KEY |
optional | if used |
| Variable | Local (frontend/.env.local) | Render (Frontend) |
|---|---|---|
NEXT_PUBLIC_API_BASE_URL |
http://127.0.0.1:8000 |
https://<backend>.onrender.com or custom domain |
NEXT_PUBLIC_GOOGLE_URL |
https://www.google.com |
same |
NEXT_PUBLIC_SHOW_PERSONALITY |
true |
true |
Create new migration after editing SQLAlchemy models:
# from backend/ with venv active
alembic revision -m "describe your change" --autogenerate
alembic upgrade head
# downgrade example
alembic downgrade -1- CORS errors: Add the exact frontend origin to
ALLOW_ORIGINS, restart backend. psycopg2on Windows: Usepsycopg2-binaryand ensure VC++ build tools installed.- Alembic path errors: Run from
backend/wherealembic.inilives. - Port conflicts: Change ports and update envs accordingly:
- Backend:
uvicorn ... --port 8001 - Frontend:
PORT=3001 npm run dev(ornext dev -p 3001)
- Backend:
Author: Akhil Kanukula
Project: Aletheia – LLM Personality & Trust Study Platform
Deployed on: Render
Tech Stack: Next.js + FastAPI + PostgreSQL + Tailwind CSS + Alembic
Version: Final Handover Document