FastAPI + MongoDB + Redis + local LLM chat application with SPA UI. You can find final report here
- UI strategy: SPA
- Backend pattern: MCS (Model-Controller-Service)
- Python
- FastAPI
- MongoDB
- Redis
- JWT (access + refresh)
- GitHub OAuth
- llama-cpp-python
- Local model to test
- Docker / Docker Compose
- Copy env:
cp .env.example .env
- Fill required env values in
.env:JWT_SECRETGITHUB_CLIENT_IDGITHUB_CLIENT_SECRETGITHUB_REDIRECT_URI(must match GitHub OAuth app callback URL)- optionally
LLM_MODEL_PATH(default:model.gguf)
- Start project:
docker compose up --build
- Open:
- SPA:
http://localhost:8000/ - Swagger:
http://localhost:8000/docs
- SPA:
Stop and remove containers:
docker compose down
APP_NAME,ENV,DEBUG,API_V1_PREFIXMONGO_URI,MONGO_DBREDIS_URI,REFRESH_TOKEN_TTL_SECONDS(default 30 days)JWT_SECRET,JWT_ALGORITHM,ACCESS_TOKEN_EXPIRE_MINUTESGITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,GITHUB_REDIRECT_URILLM_MODEL_PATH
Auth:
POST /api/v1/auth/registerPOST /api/v1/auth/loginPOST /api/v1/auth/refreshPOST /api/v1/auth/logoutGET /api/v1/auth/meGET /api/v1/auth/github/loginGET /api/v1/auth/github/callback?code=...
Chats:
POST /api/v1/chatsGET /api/v1/chatsGET /api/v1/chats/{chat_id}/messagesPOST /api/v1/chats/{chat_id}/messagesPOST /api/v1/chats/{chat_id}/ask
422 on /auth/register or /auth/login
- Not caused by missing GitHub env vars.
- The API expects JSON:
{"login": "...", "password": "..."}withContent-Type: application/json. - Validation rules: login length 3–64, password length 8–128. Shorter values return
422with a Pydantic detail body.
401 on /auth/me or /chats
- Normal if you are not logged in or the access token expired. Use Login or Refresh; the SPA stores tokens in
localStorage.
POST /api/v1/chats//ask → 404
- The URL had an empty chat id (double slash). Create a chat and select it in the dropdown before Ask LLM.
(trapped) error reading bcrypt version / register 400
- This was a passlib + bcrypt incompatibility in older installs. The project now uses the
bcryptpackage directly (no passlib). Rebuild the image:docker compose build --no-cache apithendocker compose up.
Example .env only
JWT_SECRET=change-meis enough for local try-outs.- GitHub OAuth buttons will fail until
GITHUB_CLIENT_ID/GITHUB_CLIENT_SECRET/GITHUB_REDIRECT_URIare set; password register/login still works.