FastAPI backend that powers the Syllabye app. It exposes:
- JWT-based auth (
/auth/register,/auth/login) - A LangChain-powered, streaming calendar/chat agent
- HTTP streaming endpoint:
POST /chat - WebSocket streaming endpoint:
GET /chat/ws
- HTTP streaming endpoint:
- CRUD endpoints for events (
/events) - Class/syllabus management endpoints used by the mobile app
The agent uses OpenAI via langchain-openai and a MongoDB database.
- Python 3.11 (recommended)
- An OpenAI API key
-
Clone / open this folder
cd syllabye-backend -
Create and activate a virtual environment
python -m venv venv # Windows PowerShell .\venv\Scripts\Activate.ps1
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Create a
.envfile (not committed to git) in this folder:OPENAI_API_KEY=your-openai-key-here MONGODB_URI=mongodb://user:password@host:port MONGODB_DB_NAME=syllabye SECRET_KEY=your-strong-random-secret-key
The app uses
python-dotenvto load.envon startup.
Run the FastAPI app with Uvicorn:
uvicorn app.main:app --reloadThe API will be available at http://127.0.0.1:8000.
- Interactive docs:
http://127.0.0.1:8000/docs - Health check:
GET /health
POST /auth/register– create a new userPOST /auth/login– obtain a JWT access token- All
/eventsand/chatrequests requireAuthorization: Bearer <token>
Event endpoints:
POST /events– create eventGET /events– list events (optionally by date)GET /events/{id}– get single eventPATCH /events/{id}– update event --DELETE /events/{id}– delete event
Chat endpoints:
POST /chat– streaming response over HTTP (used as a fallback by clients)GET /chat/ws– WebSocket chat with token streaming and live tool-call events
- FastAPI – web framework and dependency injection
- Uvicorn – ASGI server for running the API
- MongoDB – persistence for users, classes, events, tool logs, etc.
- LangChain / langchain-openai – LLM orchestration and tools for the calendar agent
- python-dotenv – loads environment variables from
.env - python-jose – JWT creation and verification for auth
This repo includes a simple browser-based helper page chat.html for local development. It is ignored by git and not meant for production deployment.
Usage:
- Start the backend (
uvicorn app.main:app --reload). - Open
chat.htmlin a browser (double-click orstart .\chat.html). - Enter
http://127.0.0.1:8000as the API base URL. - Log in with a valid username/password.
- Chat with the calendar agent.
The agent:
- Uses OpenAI via
ChatOpenAI. - Has short-term per-user memory (recent conversation turns).
- Manages events only for the authenticated user.
.envand other secrets are ignored by git via.gitignore.chat.htmlis a local artifact and is also ignored.