How straycat405/personal-llm works
Purpose and Entry Points
BTLLM is a local-first document-assistant chatbot: React UI plus Spring Boot API, local Ollama inference, PostgreSQL/pgVector retrieval, and optional cloud model providers. Backend starts at backend/src/main/java/com/bigteam/btllm/BtllmApplication.java; browser bootstrap is frontend/src/main.tsx and frontend/src/App.tsx. Docker deployment is orchestrated by docker-compose.yml.
Client Application
The React 18/TypeScript SPA provides authentication, chat, model selection, document ingestion, and knowledge-base management. frontend/src/pages/ChatPage.tsx is the primary user workflow; API clients separate REST concerns under frontend/src/api/chatRoom.ts and frontend/src/api/etl.ts. Client-side state is partitioned among auth, chat, and knowledge stores, notably frontend/src/stores/chatStore.ts.
Identity and API Boundary
Spring Security protects HTTP APIs with JWT authentication. Signup/login flow enters backend/src/main/java/com/bigteam/btllm/user/controller/AuthController.java, is handled by backend/src/main/java/com/bigteam/btllm/user/service/UserService.java, and tokens are verified by backend/src/main/java/com/bigteam/btllm/common/jwt/JwtAuthFilter.java. backend/src/main/java/com/bigteam/btllm/config/SecurityConfig.java defines the security boundary; ETL progress SSE is intentionally public and controlled through opaque job IDs.
Conversational Execution
REST chat-room management is split from streaming generation: backend/src/main/java/com/bigteam/btllm/chat/controller/ChatRoomController.java manages persisted rooms/history, while backend/src/main/java/com/bigteam/btllm/chat/controller/ChatWebSocketHandler.java receives and streams chat events over WebSocket. backend/src/main/java/com/bigteam/btllm/config/ChatClientFactory.java assembles Spring AI clients/providers and advisor behavior. backend/src/main/java/com/bigteam/btllm/chat/advisor/TokenTrackingAdvisor.java records actual model usage. backend/src/main/java/com/bigteam/btllm/chat/service/OllamaGenerationQueue.java serializes/bounds local GPU generation to protect the 8GB-VRAM Ollama runtime.
Agent Tools, Memory, and Persistence
The model chooses tools rather than executing RAG on every prompt. backend/src/main/java/com/bigteam/btllm/chat/tools/LlmTools.java exposes web crawling, prior-history search, knowledge-base search, and token usage to Spring AI tool calling. backend/src/main/java/com/bigteam/btllm/chat/service/ThinkingRouter.java controls thinking behavior. Durable conversation state is represented by backend/src/main/java/com/bigteam/btllm/chat/entity/ChatRoom.java and backend/src/main/java/com/bigteam/btllm/chat/entity/ChatHistory.java, backed by PostgreSQL/JPA.
RAG Ingestion and Retrieval
ETL requests enter backend/src/main/java/com/bigteam/btllm/rag/controller/EtlController.java; backend/src/main/java/com/bigteam/btllm/rag/service/EtlPipelineService.java asynchronously fetches/parses URLs and supported files, chunks text, adds a document summary, and writes embeddings to pgVector. backend/src/main/java/com/bigteam/btllm/rag/service/EtlProgressTracker.java holds job status and drives SSE progress. Query retrieval can be reranked through backend/src/main/java/com/bigteam/btllm/rag/service/HybridReranker.java; settings live in backend/src/main/java/com/bigteam/btllm/rag/config/RagSearchSettings.java.
Runtime and Operations
Core runtime is Java 17/Spring Boot 3.5/Spring AI with PostgreSQL 17 + pgVector and local Ollama (qwen3:8b, bge-m3); OpenAI, Anthropic, and Google are optional external providers. backend/src/main/resources/application.yaml is the backend runtime configuration. Compose also provisions Prometheus, Grafana, Loki, and Promtail; their configurations are under monitoring/prometheus/prometheus.yml, monitoring/grafana/provisioning, and monitoring/loki/loki-config.yml. CI validates backend, frontend build, and Docker image through .github/workflows/ci.yml.
Main entry points: docker-compose.yml Compose deployment · ChatPage.tsx Chat workflow · chatRoom.ts Chat & ETL clients · SecurityConfig.java JWT security boundary
Components 20
Client SPA
- React document assistant · Authentication, chat, model, and knowledge-base workflows.
frontend/src/App.tsx - Chat workflow
frontend/src/pages/ChatPage.tsx - Chat state
frontend/src/stores/chatStore.ts - Chat & ETL clients
frontend/src/api/chatRoom.ts
Spring Boot API
- BTLLM application
backend/src/main/java/com/bigteam/btllm/BtllmApplication.java - JWT security boundary · ETL progress SSE is public and protected by opaque job IDs.
backend/src/main/java/com/bigteam/btllm/config/SecurityConfig.java - Authentication
backend/src/main/java/com/bigteam/btllm/user/controller/AuthController.java - Chat rooms & history API
backend/src/main/java/com/bigteam/btllm/chat/controller/ChatRoomController.java - Streaming chat
backend/src/main/java/com/bigteam/btllm/chat/controller/ChatWebSocketHandler.java - AI client & agent routing · Builds providers, advisors, thinking behavior, and model tool calling.
backend/src/main/java/com/bigteam/btllm/config/ChatClientFactory.java - Agent tools · Provides web, history, knowledge search, and token-usage tools.
backend/src/main/java/com/bigteam/btllm/chat/tools/LlmTools.java - Document ingestion API
backend/src/main/java/com/bigteam/btllm/rag/controller/EtlController.java - Async ETL pipeline · Fetches, parses, chunks, summarizes, embeds, and indexes documents.
backend/src/main/java/com/bigteam/btllm/rag/service/EtlPipelineService.java
AI & Data Runtime
- PostgreSQL + pgVector · Stores users, conversations, knowledge data, and vector embeddings.
- Local Ollama · Hosts qwen3:8b generation and bge-m3 embeddings.
- GPU generation queue · Serializes local generation for the 8GB-VRAM runtime.
backend/src/main/java/com/bigteam/btllm/chat/service/OllamaGenerationQueue.java - Optional cloud models · OpenAI, Anthropic, and Google providers.
Deployment & Observability
- Metrics, logs & dashboards
monitoring/prometheus/prometheus.yml - Compose deployment · Provisions application, data, AI, and observability runtimes.
docker-compose.yml - CI validation · Validates backend, frontend build, and Docker image.
.github/workflows/ci.yml
Connections 28
- React document assistant → Chat workflow: renders
- Chat workflow → Chat state: reads and updates
- Chat workflow → Chat & ETL clients: uses
- Chat & ETL clients → Authentication: login / signup
- Chat & ETL clients → Chat rooms & history API: room REST
- Chat workflow → Streaming chat: chat WebSocket
- Chat & ETL clients → Document ingestion API: ingestion + progress
- BTLLM application → JWT security boundary: configures
- JWT security boundary → Authentication: protects
- JWT security boundary → Chat rooms & history API: protects
- JWT security boundary → Streaming chat: protects
- Authentication → PostgreSQL + pgVector: users
- Chat rooms & history API → PostgreSQL + pgVector: rooms and history
- Streaming chat → AI client & agent routing: streams prompts
- AI client & agent routing → Agent tools: invokes selected tools
- Agent tools → PostgreSQL + pgVector: history and knowledge search
- AI client & agent routing → GPU generation queue: local generation
- GPU generation queue → Local Ollama: serialized requests
- AI client & agent routing → Optional cloud models: optional provider calls
- Document ingestion API → Async ETL pipeline: starts async job
- Async ETL pipeline → Local Ollama: creates embeddings
- Async ETL pipeline → PostgreSQL + pgVector: writes vectors and documents
- Compose deployment → BTLLM application: runs
- Compose deployment → PostgreSQL + pgVector: provisions
- Compose deployment → Local Ollama: provisions
- Compose deployment → Metrics, logs & dashboards: provisions
- Metrics, logs & dashboards → BTLLM application: observes
- CI validation → Compose deployment: validates image