How achintxv/citemind works
CiteMind is a document-grounded chat application. Users upload PDFs or text files, which are validated, extracted, chunked, embedded, and stored for semantic retrieval. In chat, the server loads conversation history, checks the question, retrieves relevant chunks, generates a grounded answer, validates its output, and persists the result with citations. The UI also supports browsing and deleting documents and conversations. The sampled sources show the core ingestion and RAG calls; some API routing and model-provider details are supported only by the source index, so uncertain integrations are omitted or marked dashed.
Main entry points: document.service.js Document ingestion · rag.service.js RAG answer flow · api-client.js Browser API client · ChatInterface.jsx Chat interface
Components 34
User interface
- Chat interface
src/components/ChatInterface.jsx - Message views
src/components/MessageList.jsx - Message input
src/components/MessageInput.jsx - Chat sidebar
src/components/Sidebar.jsx - Documents page
src/app/documents/page.jsx - Document list
src/components/DocumentList.jsx - Document uploader
src/components/DocumentUploader.jsx - Source citations
src/components/SourceCitation.jsx
API routes
- Chat endpoint
src/app/api/chat/route.js - Conversation endpoints
src/app/api/chat/conversations/route.js - Conversation detail
src/app/api/chat/conversations/[id]/route.js - Document endpoints
src/app/api/documents/route.js - Document detail
src/app/api/documents/[id]/route.js - Upload endpoint
src/app/api/documents/upload/route.js
Document and chat services
- RAG answer flow
src/services/rag.service.js - Conversation service
src/services/conversation.service.js - Document ingestion
src/services/document.service.js - Text extraction
src/ingestion/extract.js - Text chunking
src/ingestion/chunk.js - Embedding service
src/services/embedding.service.js - Vector retrieval
src/services/retrieval.service.js - Gemini model service
src/services/gemini.service.js
Guardrails and shared infrastructure
- Browser API client
src/lib/api-client.js - Input validation
src/guardrails/input.guard.js - Injection detection
src/guardrails/injection.guard.js - Retrieval checks
src/guardrails/retrieval.guard.js - Output validation
src/guardrails/output.guard.js - Prompt construction
src/utils/prompt.js - Runtime configuration
src/lib/env.js - Response handling
src/utils/response.js
Other components
- User
- PostgreSQL and pgvector
- Uploaded file storage
- External model provider
Connections 46
- User → Chat interface: asks questions
- User → Documents page: manages documents
- Chat interface → Message input: renders
src/components/ChatInterface.jsx - Chat interface → Message views: renders
src/components/ChatInterface.jsx - Chat interface → Chat sidebar: renders
src/components/ChatInterface.jsx - Message views → Source citations: renders
src/components/MessageList.jsx - Documents page → Document list: renders
src/app/documents/page.jsx - Documents page → Document uploader: renders
src/app/documents/page.jsx - Chat interface → Browser API client: calls
src/components/ChatInterface.jsx - Documents page → Browser API client: calls
src/app/documents/page.jsx - Document uploader → Browser API client: calls
src/components/DocumentUploader.jsx - Browser API client → Chat endpoint: posts chat
- Browser API client → Conversation endpoints: requests conversations
- Browser API client → Conversation detail: requests conversation
- Browser API client → Document endpoints: requests documents
- Browser API client → Upload endpoint: uploads files
- Chat endpoint → RAG answer flow: answers via
src/app/api/chat/route.js - Conversation endpoints → Conversation service: delegates to
src/app/api/chat/conversations/route.js - Conversation detail → Conversation service: delegates to
src/app/api/chat/conversations/[id]/route.js - Document endpoints → Document ingestion: delegates to
src/app/api/documents/route.js - Document detail → Document ingestion: delegates to
src/app/api/documents/[id]/route.js - Upload endpoint → Document ingestion: ingests through
src/app/api/documents/upload/route.js - Chat endpoint → Input validation: validates input
src/app/api/chat/route.js - Upload endpoint → Input validation: checks upload
src/app/api/documents/upload/route.js - RAG answer flow → Conversation service: persists turns
src/services/rag.service.js - RAG answer flow → Vector retrieval: searches chunks
src/services/rag.service.js - RAG answer flow → Injection detection: checks question
src/services/rag.service.js - RAG answer flow → Retrieval checks: checks context
src/services/rag.service.js - RAG answer flow → Prompt construction: builds prompt
src/services/rag.service.js - RAG answer flow → Gemini model service: generates answer
src/services/rag.service.js - RAG answer flow → Output validation: validates answer
src/services/rag.service.js - Document ingestion → Input validation: validates file
src/services/document.service.js - Document ingestion → Text extraction: extracts text
src/services/document.service.js - Document ingestion → Text chunking: chunks text
src/services/document.service.js - Document ingestion → Embedding service: embeds chunks
src/services/document.service.js - Document ingestion → Vector retrieval: stores chunks
src/services/document.service.js - Document ingestion → PostgreSQL and pgvector: writes metadata
src/services/document.service.js - Document ingestion → Uploaded file storage: stores original
src/services/document.service.js - Vector retrieval → Embedding service: embeds query
src/services/retrieval.service.js - Vector retrieval → Retrieval checks: filters results
src/services/retrieval.service.js - Vector retrieval → PostgreSQL and pgvector: queries vectors
src/services/retrieval.service.js - Embedding service → Gemini model service: requests embeddings
src/services/embedding.service.js - Prompt construction → Injection detection: flags text
src/utils/prompt.js - Gemini model service → Runtime configuration: reads settings
src/services/gemini.service.js - Chat endpoint → Response handling: formats response
src/app/api/chat/route.js - Gemini model service → External model provider: calls provider