CyberLearn is a full-stack web app with a SvelteKit frontend and Flask API backend.
frontend/— SvelteKit + Bun + Tailwind UIbackend/— Flask API serverdatabase/schema.sql— SQLite schemadatabase/seed.py— seed/reset script for local datavercel.json— backend Vercel routing (/api/*->backend/vercel.py).env.example— shared env template (backend + frontend API config hints)
- Python 3.11+
- Bun 1.1+
cp .env.example .envpython3 -m venv .venv
source .venv/bin/activate
pip install -r backend/requirements.txt
python3 database/seed.py
python3 backend/run.pyBackend runs at http://127.0.0.1:5000.
In a new terminal:
cd frontend
bun install
bun run devFrontend runs at http://127.0.0.1:5173.
Frontend requests use PUBLIC_API_BASE.
- Default:
PUBLIC_API_BASE=/api - In local dev, Vite proxies
/apitoBACKEND_DEV_ORIGIN(defaulthttp://127.0.0.1:5000) - To change proxy target locally, set
BACKEND_DEV_ORIGINbeforebun run dev - To call a remote backend directly, set
PUBLIC_API_BASEto a full URL (for examplehttps://my-api.vercel.app/api)
For frontend-only env files, place values in frontend/.env.local.
python3 database/seed.py:
- creates database file if missing
- applies schema from
database/schema.sql - clears existing rows
- inserts sample users, tracks, modules, quizzes, and message history tables
Run it whenever you want a clean known dataset.
All API routes are under /api:
GET /api/dashboardGET /api/tracksGET /api/tracks/<track_id>/modulesGET /api/quizzes/<quiz_id>POST /api/quizzes/<quiz_id>/submitGET /api/progressPOST /api/progressPOST /api/analyze-messageGET /api/message-history?limit=20
Backend-only env vars:
GEMINI_API_KEY(required for analysis endpoint)GEMINI_MODEL(default:gemini-1.5-flash)
Behavior:
- Gemini is called only by backend code (
backend/app/services/gemini_service.py) - frontend never receives or stores Gemini credentials
- model output is normalized into strict response fields:
verdictriskLevelredFlagsexplanationtips
Set backend CORS_ORIGINS to a comma-separated list of exact allowed frontend origins, for example:
CORS_ORIGINS=https://cyberlearn-frontend.vercel.app,http://localhost:5173Notes:
- CORS is not open by default
- wildcard
*is ignored by config parser - only listed origins receive CORS headers for
/api/*
Use one repo with two Vercel projects:
-
Backend project
- Root Directory:
/(repo root) - Uses
vercel.jsonand deploys Flask frombackend/vercel.py - Set env vars:
DATABASE_PATHDEFAULT_USER_IDGEMINI_API_KEYGEMINI_MODELCORS_ORIGINS(include frontend production URL)
- Root Directory:
-
Frontend project
- Root Directory:
frontend - Framework preset: SvelteKit (auto-detected)
- Set env vars:
PUBLIC_API_BASE=https://<your-backend-domain>/api
- Root Directory:
This setup keeps API and UI deployments independent while allowing frontend to target backend explicitly in production.
cd frontend
bun run check
bun run lint
bun run test
bun run build