A minimal backend API for an AI chat assistant built with FastAPI.
It supports user authentication, streaming chat responses, and conversation history.
- User registration and login (JWT authentication)
- Streaming chat responses (Server-Sent Events)
- Conversation history stored in a database
- Multiple conversations per user
- Mock LLM (default) with optional HuggingFace integration
- Docker support for easy setup
- FastAPI
- SQLAlchemy
- SQLite
- JWT (python-jose)
- passlib (bcrypt)
- Docker / docker-compose
app/
main.py
database.py
models.py
schemas.py
security.py
dependencies.py
routers/
auth.py
chat.py
services/
llm_service.py
Create a .env file:
copy .env.example .env # Windows
cp .env.example .env # Mac/Linux
Then run:
docker-compose up --build
Open: http://localhost:8000/docs
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -r requirements.txt
uvicorn app.main:app --reload
Open: http://localhost:8000/docs
POST /auth/register
{
"email": "test@example.com",
"password": "test123"
}
POST /auth/login
Use the returned token in Swagger:
Bearer <your_token>
POST /chat
{
"message": "What is a string in programming?"
}
- Requires authentication
- Streams response
- Stores messages
GET /chat/history
- Requires authentication
- Returns stored conversations
- No API key required
- Simulates streaming responses
- Requires
HF_TOKENin.env - Uses HuggingFace Inference API
SECRET_KEY=your_secret_key
HF_TOKEN=your_huggingface_token
LLM_PROVIDER=mock
The app works without a HuggingFace key by default.
- SQLite for simplicity
- Mock LLM to avoid external dependency
- No migrations (kept minimal)
- Limited test coverage
- API-only (no frontend)
- Designed for clarity and extensibility