Local-first mental health companion for low mood, anxiety, depressive symptoms, and sleep-related difficulties, with contextual memory that helps the assistant understand your situation over time, guided self-help tools, and personalized recommendations shaped by the journals, assessments, and activity data tracked in the app, grounded in clinical research and informed by a local CBT knowledge base.
- Local-first chat with Ollama
- RAG over CBT knowledge files
- Session memory with summaries
- Journals, assessments, and SOS tools
- RU/EN interface and TTS
CBT Assistant combines conversational support, structured self-reflection tools, and retrieval over local CBT materials in one app. It is built for users who want a private, local workflow instead of a cloud chatbot, and for developers who want a small, inspectable codebase around FastAPI, SQLite, and Ollama. The backend serves the API and static frontend, stores session history in SQLite, and uses local LLM plus embedding models through Ollama.
Many mental health assistants are either generic chat wrappers or depend on remote APIs for every interaction. That creates two problems: weak domain grounding and low privacy for sensitive conversations. This project closes that gap by combining a local model, a local CBT knowledge base, structured journals and assessments, and lightweight memory. The stack is intentionally designed so a smaller local model can perform well without fine-tuning, relying instead on retrieval, structured user data, and context persistence to reduce hallucinations and keep behavior more grounded. The result is a single-user assistant that keeps the stack understandable and the data on the user's machine.
- Chat endpoints for regular and streaming responses.
- RAG search across Markdown knowledge files in
knowledge_base/. - Background conversation summarization for longer sessions.
- Mood tracking, thought records, sleep logs, and activity planning.
- Built-in assessments for PHQ-9, GAD-7, and Rosenberg self-esteem.
- SOS tools such as breathing and grounding support flows.
- Text-to-speech with Edge voices and browser-side voice input support.
- Static frontend built with plain HTML, CSS, and JavaScript.
Components:
frontend/renders the web UI and client-side interaction flows.backend/server.pyexposes the API, static files, WebSocket chat, sync routes, reporting, and TTS.src/llm/ollama_client.pywraps Ollama chat and streaming calls.src/rag/knowledge_base.pyloads Markdown content, builds embeddings, and runs semantic search.src/utils/db.pymanages SQLite persistence for sessions, journals, tests, activities, and summaries.src/memory/summarizer.pycreates rolling session summaries after message thresholds.
Flow:
Browser UI -> FastAPI backend -> prompt assembly + SQLite context + tool calls -> Ollama chat/embeddings -> streamed or standard response back to the browser
- Python 3.10+
- FastAPI
- Ollama
- SQLite
- httpx
- edge-tts
- pytest
- Vanilla HTML/CSS/JS
- Clone the repository and enter the project folder.
git clone https://github.com/KazKozDev/cbt-assistant.git
cd cbt-assistant- Create a virtual environment and install dependencies.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Start Ollama and pull the required models.
ollama serve
ollama pull qwen3:8b
ollama pull qwen3-embedding:4b- Run the backend.
source .venv/bin/activate
python backend/server.py-
Open
http://localhost:8000. -
On macOS, you can also use
./start_cbt_assistant.commandafter the virtual environment is prepared.
Example run:
OLLAMA_BASE_URL=http://localhost:11434 \
OLLAMA_MODEL=qwen3:8b \
python backend/server.pyTypical scenarios:
- Ask for CBT-style guidance and let the assistant pull relevant context from the local knowledge base before answering.
- Track mood, thought records, sleep, and activities over time in the same session store.
- Use assessments and SOS tools from the browser UI without sending data to a hosted LLM service.
backend/ FastAPI app and routes
frontend/ Static UI assets
src/llm/ Ollama integration
src/rag/ Knowledge base loading and search
src/memory/ Session summarization
src/utils/ SQLite storage and helpers
knowledge_base/ CBT source material for retrieval
config/ Model and prompt settings
tests/ Pytest suite
pytestThe repository includes tests for database behavior, prompt generation, RAG search, memory logic, API endpoints, and selected interaction flows.
Issues and pull requests are welcome. For substantial changes, open an issue first to align on scope before implementation.
Areas where contributions would be especially useful
- Expand and refine the local CBT knowledge base with better-structured clinical materials.
- Add more tests for real user flows, including chat, memory, sync, and recommendation behavior.
- Improve the frontend UX, accessibility, responsiveness, and language polish.
- Extend journaling, assessments, and reporting workflows with clearer insights and history views.
- Improve contextual memory and recommendation quality so responses better reflect long-term user state.
- Strengthen safety behavior and guardrails for sensitive or crisis-adjacent conversations.
- Improve onboarding and local setup with better scripts, checks, and troubleshooting paths.
- Improve documentation with clearer setup notes, examples, and architectural explanations.
- Stage: working local application
- Current version:
1.0.1
MIT - see LICENSE
If you like this project, please give it a star ⭐
For questions, feedback, or support, reach out to:

