How bala-krishnanv-ai-engineer-2028/businessmind-ai works
Purpose and Runtime
A full-stack, multi-tenant knowledge-management/RAG application: React/Vite frontend plus a TypeScript/Express backend. Users and organizations manage documents and knowledge bases, retrieve evidence, and receive grounded AI/chat responses, recommendations, and analytics. Client entry point: src/main.tsx; backend bootstraps through server/src/server.ts and server/src/app.ts.
Frontend Application Shell
React routing, app-wide providers, protected/public route boundaries, and layouts establish authenticated navigation and state. Organization, user, auth, and permission contexts drive tenant-aware UI and RBAC rendering.
Paths: src/app/App.tsx, src/app/router.tsx, src/contexts/OrganizationContext.tsx.
Client-to-API Boundary
Feature pages call typed client services rather than directly implementing backend behavior. The API client and domain services form the integration seam; current mock data suggests some UI flows may be independently demonstrable.
Paths: src/services/api.client.ts, src/services/ai.api.ts, src/services/documents.service.ts.
Core Domain and Tenant Security
The backend uses route/controller/service/repository layering. Organizations, memberships, users, roles, permissions, sessions, settings, and audit records underpin tenant isolation and authorization. Request middleware authenticates, authorizes, sanitizes, validates, rate-limits, and centralizes errors before handlers execute.
Paths: server/src/modules/organizations/organizations.service.ts, server/src/middlewares/auth.middleware.ts, server/src/middlewares/permission.middleware.ts.
Document Ingestion Pipeline
Document upload passes through storage selection, format-specific text extraction, chunking, embedding, and persisted document/version/chunk records. Storage has local and Cloudinary providers; processors support CSV, DOCX, PDF, TXT, and XLSX.
Paths: server/src/services/processing/document-processing.service.ts, server/src/services/chunking/chunking.service.ts, server/src/models/document-chunk.model.ts.
Retrieval-Augmented AI
Retrieval queries indexed document chunks, then AI services build context, evaluate evidence sufficiency, prompt an LLM, validate outputs, and map citations. Embedding and LLM factories isolate OpenAI versus mock provider implementations. This is surfaced in both dedicated retrieval and chat/AI modules.
Paths: server/src/modules/retrieval/retrieval.service.ts, server/src/services/ai/context.builder.ts, server/src/services/llm/llm.factory.ts.
Persistence, Operations, and External Services
MongoDB/Mongoose is the principal persistence runtime, including document chunks and tenant/domain models; an Atlas vector index is documented for semantic retrieval. OpenAI provides optional embeddings and LLM inference; Cloudinary is optional object storage. Express exposes health, session, and module routes, with structured configuration/logging and audit logging.
Paths: server/src/lib/mongoose.ts, server/ATLAS_VECTOR_INDEX.md, server/src/routes/index.ts.
Primary Flow
Authenticated client request → Express middleware policy boundary → module route/controller → service orchestration → repository/model persistence or provider call → standardized response. For AI answers: query → vector retrieval → evidence/context assembly → LLM generation and response validation → citations/evidence returned to the AI assistant UI.
Paths: server/src/modules/ai/ai.service.ts, server/src/repositories/document-chunk.repository.ts, src/features/ai-assistant/AIAssistantPage.tsx.
Main entry points: ai.service.ts AI answer orchestration · app.ts Express app & routes · retrieval.service.ts Semantic retrieval · document-chunk.repository.ts Document chunk repository
Components 18
React Client
- App shell & tenant state · Routing, protected views, and organization-aware UI state.
src/app/App.tsx - Organization context
src/contexts/OrganizationContext.tsx - Typed API services
src/services/api.client.ts - AI assistant UI
src/features/ai-assistant/AIAssistantPage.tsx
Express Backend
- Express app & routes · Bootstraps health, session, and module routes.
server/src/app.ts - Auth & permission policy · Authenticates requests and enforces tenant RBAC.
server/src/middlewares/auth.middleware.ts - Organization domain service · Manages organizations, memberships, and tenant settings.
server/src/modules/organizations/organizations.service.ts
Document Ingestion
- Document processing · Selects storage, extracts text, and creates document versions.
server/src/services/processing/document-processing.service.ts - Chunking & embedding
server/src/services/chunking/chunking.service.ts - Document chunk repository
server/src/repositories/document-chunk.repository.ts
RAG Services
- Semantic retrieval · Queries indexed chunks for grounded evidence.
server/src/modules/retrieval/retrieval.service.ts - Evidence context builder · Builds answer context and assesses evidence.
server/src/services/ai/context.builder.ts - AI answer orchestration · Generates validated answers with citations.
server/src/modules/ai/ai.service.ts - LLM provider factory · Selects OpenAI or mock inference implementations.
server/src/services/llm/llm.factory.ts
Other components
- MongoDB / Mongoose · Stores tenant, document, session, audit, and chunk records.
server/src/lib/mongoose.ts - Atlas vector index · Semantic index over document chunks.
server/ATLAS_VECTOR_INDEX.md - OpenAI · Optional embedding and LLM inference provider.
- Cloudinary · Optional uploaded-document storage provider.
Connections 23
- App shell & tenant state → Organization context: uses tenant state
- App shell & tenant state → Typed API services: calls
- AI assistant UI → Typed API services: submits AI queries
- Typed API services → Express app & routes: HTTP requests
- Express app & routes → Auth & permission policy: applies policy
- Auth & permission policy → Organization domain service: resolves authorization
- Express app & routes → Document processing: document endpoints
- Express app & routes → AI answer orchestration: AI endpoints
- Organization domain service → MongoDB / Mongoose: tenant records
- Document processing → Cloudinary: stores uploads
- Document processing → Chunking & embedding: extracted text
- Chunking & embedding → Document chunk repository: persists chunks
- Document chunk repository → MongoDB / Mongoose: chunk documents
- Document chunk repository → Atlas vector index: indexes embeddings
- Semantic retrieval → Document chunk repository: fetches evidence
- Semantic retrieval → Atlas vector index: vector search
- AI answer orchestration → Semantic retrieval: retrieves evidence
- Semantic retrieval → Evidence context builder: retrieved chunks
- AI answer orchestration → Evidence context builder: builds grounded prompt
- AI answer orchestration → LLM provider factory: requests generation
- LLM provider factory → OpenAI: optional inference
- Chunking & embedding → OpenAI: optional embeddings
- AI answer orchestration → AI assistant UI: answer, evidence & citations