A full‑stack chat application with Google OAuth, conversation history, system prompts, and OpenAI model selection. The backend is built with FastAPI and MongoDB; the frontend is a Next.js app.
- Chat with streaming responses (SSE)
- Conversation history with titles and timestamps
- Per‑user system prompt management
- OpenAI model selection
- CORS and security headers configured for dev/prod
- Google OAuth login with secure HttpOnly cookies and PKCE
- Backend: FastAPI, Uvicorn, Pydantic, python-jose, Google OAuth, MongoDB (PyMongo)
- AI: LangChain, langchain-openai, langgraph, langchain-community
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS 4
backend/
: FastAPI app, services, repositories, schemasfrontend/
: Next.js app, UI, hooks, and services
- Node.js 20+
- Python 3.10+
- MongoDB (local or hosted)
- Google OAuth 2.0 Client (Web) credentials
- OpenAI API key
Create .env
files in both backend/
and frontend/
(or a shared root .env if you prefer) with the following.
Backend .env
(at backend/.env
):
ENVIRONMENT
= development | productionBASE_URL
= http://localhost:8000FRONTEND_URL
= http://localhost:3000ALLOWED_ORIGINS
= http://localhost:3000OPENAI_API_KEY
= your_openai_api_keyGOOGLE_CLIENT_ID
= your_google_client_idGOOGLE_CLIENT_SECRET
= your_google_client_secretJWT_SECRET
= random_long_secretMONGO_URI
= mongodb://localhost:27017 (or your Atlas URI)MONGO_DB_NAME
= chatstack
Frontend .env.local
(at frontend/.env.local
):
NEXT_PUBLIC_API_URL
= http://localhost:8000
Notes:
- In production, set
ENVIRONMENT=production
. Cookies will besecure
withSameSite=None
. UpdateALLOWED_ORIGINS
to include your web origin(s). - Ensure
BASE_URL
andFRONTEND_URL
match your actual deployed URLs.
Backend:
- Create a Python virtualenv (recommended)
- Install dependencies
- Run FastAPI server
Commands:
# from repo root
cd backend
python -m venv venv
# Windows PowerShell
./venv/Scripts/Activate.ps1
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Frontend:
- Install dependencies
- Run Next.js dev server
Commands:
# from repo root
cd frontend
npm install
npm run dev
App URLs (dev):
- Frontend: http://localhost:3000
- API: http://localhost:8000/api
Frontend:
npm run dev
→ Next dev servernpm run build
→ Next buildnpm start
→ Next start
Backend:
uvicorn main:app --reload
→ Dev server
MIT