How farhanhafeez985/echochat works
Purpose and entry points
This is a full-stack knowledge-chat application: users authenticate, ingest documents into a retrieval index, and chat with an LLM augmented by retrieved source material. The backend service entry point is backend/app/main.py; its orchestration layer is backend/app/agent.py. The Next.js frontend starts at frontend/app/layout.tsx and exposes the main chat route at frontend/app/page.tsx.
Backend API, configuration, and persistence
The backend is a Python application with centralized runtime configuration in backend/app/config.py and database setup in backend/app/database.py. API serialization is separated in backend/app/serializers.py. These form the boundary between HTTP-facing application code and persistent/authenticated domain state.
Authentication and user boundary
Authentication is a dedicated backend subsystem: domain models and request/response schemas live in backend/app/auth/models.py and backend/app/auth/schemas.py; credential/token handling is in backend/app/auth/security.py. Request-level identity enforcement is mediated through backend/app/auth/dependencies.py, while business operations are concentrated in backend/app/auth/service.py. The frontend consumes this boundary through frontend/hooks/useAuth.ts and frontend/lib/auth.ts.
Document ingestion pipeline
Knowledge documents pass through extraction, chunking, and ingestion stages: backend/app/documents/extractor.py, backend/app/documents/chunker.py, and backend/app/documents/ingestion.py. Ingestion converts source content into retrieval-ready chunks and hands them to the RAG storage/indexing layer. The knowledge-management UI is rooted at frontend/app/knowledge/page.tsx, with item-level navigation under frontend/app/knowledge/[id]/page.tsx.
RAG indexing and retrieval
The RAG subsystem owns embedding generation, vector-store access, retrieval, reranking, and context assembly. Core paths are backend/app/rag/embeddings.py, backend/app/rag/qdrant.py, backend/app/rag/retriever.py, backend/app/rag/reranker.py, and backend/app/rag/context.py. backend/app/rag/repository.py provides a repository boundary around indexed data, while backend/app/rag/models.py defines retrieval-domain data. Qdrant is the material external vector database; backend/app/rag/fake_retriever.py suggests an alternate non-production retrieval implementation.
LLM agent and conversational state
backend/app/agent.py coordinates user input, retrieval context, prompts, tool use, and model calls. LLM-provider integration is isolated in backend/app/llm/llm_client.py, and callable agent capabilities are defined in backend/app/llm/tools.py. Prompt construction is centralized in backend/app/prompts.py; conversational/session memory is represented by backend/app/memory.py. The key control flow is: authenticated user message → agent → retrieve/rerank/context → LLM call and optional tools → answer with source references.
Frontend interaction layer
The frontend is a TypeScript/Next.js application with chat state and transport logic in frontend/hooks/useChat.ts and frontend/lib/api.ts. frontend/components/ChatContainer.tsx composes message display and input, while frontend/components/SourceReferences.tsx renders retrieval provenance returned by the backend. Voice interaction is a distinct client capability via frontend/hooks/useVoice.ts and frontend/components/VoiceCallModal.tsx. Account and application navigation are surfaced through frontend/app/login/page.tsx, frontend/app/signup/page.tsx, frontend/app/profile/page.tsx, and frontend/app/settings/page.tsx.
Main entry points: main.py Backend API · agent.py Chat agent · ChatContainer.tsx Chat UI · layout.tsx App shell & routes
Components 19
Next.js Frontend
- App shell & routes · Chat, knowledge, account, and navigation routes.
frontend/app/layout.tsx - Chat UI
frontend/components/ChatContainer.tsx - Chat state & API
frontend/hooks/useChat.ts - Auth client
frontend/hooks/useAuth.ts - Knowledge UI
frontend/app/knowledge/page.tsx - Source references
frontend/components/SourceReferences.tsx - Voice interaction
frontend/hooks/useVoice.ts
Backend Application
- Backend API
backend/app/main.py - Serialization & database · HTTP serialization and persistent domain setup.
backend/app/serializers.py - Chat agent · Coordinates retrieval, prompting, tools, and responses.
backend/app/agent.py - Conversation memory
backend/app/memory.py - Prompt builder
backend/app/prompts.py - LLM client & tools
backend/app/llm/llm_client.py
Authentication
- Auth service & identity · Validates credentials and enforces request identity.
backend/app/auth/service.py
Knowledge Retrieval
- Document ingestion · Extracts and chunks documents for indexing.
backend/app/documents/ingestion.py - Retrieve & rerank · Finds and ranks relevant indexed chunks.
backend/app/rag/retriever.py - Context assembly
backend/app/rag/context.py - RAG repository · Boundary around embeddings and indexed data.
backend/app/rag/repository.py - Qdrant vector store
backend/app/rag/qdrant.py
Connections 23
- App shell & routes → Chat UI: renders
- Chat UI → Chat state & API: messages
- Chat state & API → Backend API: chat API
- App shell & routes → Knowledge UI: routes to
- Knowledge UI → Backend API: document API
- App shell & routes → Auth client: auth flows
- Auth client → Backend API: authenticate
- Chat UI → Source references: shows provenance
- Voice interaction → Chat UI: voice input
- Backend API → Auth service & identity: enforces identity
- Backend API → Serialization & database: serializes & persists
- Backend API → Chat agent: authenticated message
- Backend API → Document ingestion: uploads documents
- Document ingestion → RAG repository: indexes chunks
- RAG repository → Qdrant vector store: stores vectors
- Chat agent → Conversation memory: reads & updates
- Chat agent → Retrieve & rerank: queries
- Retrieve & rerank → RAG repository: searches
- Retrieve & rerank → Context assembly: ranked chunks
- Chat agent → Prompt builder: builds prompt
- Context assembly → Prompt builder: source context
- Chat agent → LLM client & tools: model call & tools
- Chat agent → Backend API: answer & sources