How mejji/datamuse---ai-datavisuzaliztion works
1. Overall shape
- DataMuse is a two-tier local application: a React/Vite frontend talks to a FastAPI backend, and the backend persists semantic context in Qdrant. The app is centered on a single user-uploaded CSV dataset that then feeds chat, charting, story generation, and data mutation workflows.
2. Frontend boundary
- The frontend is a TypeScript React 19 app with Vite, Zustand for shared state, and a component-driven UI. App.tsx orchestrates the major modes: upload, explore/chat, dashboard, and story building.
- Key UI surfaces are the upload zone, Muse companion chat panel, interactive dashboard, chart/table renderers, and story editor. The frontend is primarily a presentation and interaction layer; the analytical work happens in the backend.
3. Backend boundary
- The backend is a FastAPI service organized by feature routers: upload, chat, analyze, story, and data. This is the main API boundary for the entire product.
- main.py is the application entry point and also the place where cross-cutting concerns like CORS are configured.
- Pydantic schemas under models/schemas.py define the request/response contracts between frontend and backend.
4. Dataset ingestion path
- CSV upload enters through /api/upload, where the backend profiles the file and creates the dataset context used everywhere else.
- csv_profiler.py analyzes columns and basic structure, while data_tools.py and related services help turn raw data into queryable and displayable forms.
- The resulting dataset profile is exposed back to the UI so the app can immediately show column summaries, prompts, and suggested next actions.
5. Semantic indexing and retrieval
- Uploaded data is also embedded and indexed for retrieval-augmented generation. embeddings.py handles chunking and vector creation using fastembed/ONNX, and qdrant_service.py manages Qdrant operations.
- This creates a semantic memory layer that the LLM can consult for grounded answers, rather than relying only on the current prompt or raw tabular operations.
- Qdrant runs as a separate service via Docker Compose, making it an explicit infrastructure dependency of the architecture.
6. Chat and analytical tool use
- /api/chat is the main conversational workflow. The backend combines the dataset context, vector retrieval, and tool-based operations to answer questions, generate charts, and explain results.
- data_tools.py is the functional boundary for actions like querying data, creating charts/tables, computing stats, and detecting patterns. This is the bridge between natural language and deterministic dataset operations.
- Frontend chat components render the conversation and can embed charts inline when the backend returns structured visualization output.
7. Tiered LLM router
- llm_service.py is the central intelligence layer. It routes each request to a model tier based on complexity, pins conversations to a tier/model, and handles failover when providers rate-limit or exhaust quotas.
- config.py contains the model pool and complexity classification logic. The architecture deliberately separates “trivial metadata” requests from “strong reasoning/tool use” requests, which is important for understanding why some endpoints feel faster and others are more capable.
- This router is a major system boundary: it abstracts away multiple providers while presenting one unified AI service to the rest of the backend.
8. Fixed-purpose AI endpoints
- Some backend routes are intentionally specialized. /api/analyze is for visualization suggestions and /api/story/generate is for story generation; both are forced to use the strongest tier because they need reliable structured output and longer-form reasoning.
- muse_prompts.py contains the system prompt and analytical guidance that shape the assistant’s behavior across these workflows.
- These are distinct from ordinary chat because they are output-constrained product features, not open-ended conversation.
9. Story-building subsystem
- The story flow is its own product area rather than just “chat output.” The backend exposes story angle, refinement, generation, and save routes, while the frontend provides a dedicated story builder and chapter components.
- This subsystem consumes the dataset context and generated charts/narratives to produce editable, chapter-based stories that can be revised before saving.
- It shares the same dataset and LLM infrastructure as chat, but the UX and output format are different enough to treat it as a separate architectural slice.
10. Data mutation and lineage
- /api/apply, /api/undo, /api/download/{id}, and /api/history/{id} form a mutation workflow around the dataset. The app can apply transformations, revert them, and export the mutated result.
- This creates a lightweight data versioning layer focused on user-driven analysis changes rather than full warehouse-style persistence.
- The frontend includes preview-oriented components so users can inspect the effect of a mutation before committing to it.
11. State management and data flow in the UI
- Zustand in useDataStore.ts acts as the shared client-side state for the active dataset, chat state, dashboard contents, and story artifacts.
- API access is centralized in lib/api.ts, so the UI’s data flow is largely: upload or select dataset → store profile/context → trigger chat/analyze/story requests → render charts, panels, and chapters.
- This keeps the UI reactive while the backend remains the source of truth for data processing.
12. Operational setup and deployment model
- The repository is optimized for local use: startup scripts launch Qdrant, the backend, and the frontend together, and the README explicitly recommends local deployment because of vector DB and model/API constraints.
- docker-compose.yml exists specifically for the Qdrant dependency; the rest of the stack runs as standard app servers.
- Environment variables provide the external service credentials and Qdrant connection details, which means the main runtime dependencies are configuration-driven rather than hardcoded.
13. External service boundaries
- The only major external dependencies are LLM providers (Groq, Cerebras, Gemini) and the Qdrant vector database. The backend abstracts provider-specific behavior so the frontend never talks to these services directly.
- Because the app depends on multiple AI providers and a local vector store, the backend is the integration hub and the frontend stays provider-agnostic.
14. What to show in an architecture diagram
- A good diagram should highlight: browser UI → FastAPI API → dataset processing/LLM services → Qdrant, plus the separate Qdrant container.
- Within the backend, show three main functional paths: upload/profiling, chat/analysis with model routing and tools, and story/mutation workflows.
- The most important boundary is that the frontend only renders and collects interactions; the backend owns data understanding, retrieval, model routing, and all generated outputs.
Main entry points: main.py API Entry · data_tools.py Data Tools · llm_service.py LLM Router · start.sh Local Stack
Components 19
Frontend
React/Vite browser app and UI state
- Browser UI · User-facing upload, chat, dashboard, and story experiences
frontend/src/App.tsx - UI Components · Reusable panels for charts, chat, tables, stories, and previews
frontend/src/components - Client Store · Shared dataset, chat, dashboard, and story state
frontend/src/stores/useDataStore.ts - API Client · Centralized frontend calls into the backend API
frontend/src/lib/api.ts
Backend
FastAPI API, services, and domain logic
- API Entry · Application entrypoint and cross-cutting API configuration
backend/app/main.py - Schemas · Request and response contracts shared across routes
backend/app/models/schemas.py - Upload API · CSV ingestion and dataset profile creation
backend/app/routers/upload.py - Chat API · Conversational Q&A, tool use, and grounded responses
backend/app/routers/chat.py - Analyze API · Visualization suggestions and analysis output
backend/app/routers/analyze.py - Story API · Story generation, refinement, and save flows
backend/app/routers/story.py - Data API · Mutation, history, download, and undo endpoints
backend/app/routers/data.py - CSV Profiler · Inspects uploaded columns and basic dataset structure
backend/app/services/csv_profiler.py - Data Tools · Deterministic querying, charts, stats, and transformations
backend/app/services/data_tools.py - LLM Router · Routes requests across model tiers with failover and pinning
backend/app/services/llm_service.py - Prompts · System guidance and task-specific assistant instructions
backend/app/services/muse_prompts.py - Embeddings · Chunks data and creates semantic embeddings
backend/app/services/embeddings.py - Qdrant Access · Manages semantic indexing and retrieval in Qdrant
backend/app/services/qdrant_service.py
Infrastructure
Local runtime dependencies and deployment glue
- Qdrant · External semantic memory store used by the backend
docker-compose.yml - Local Stack · Launches frontend, backend, and vector store for local use
start.sh
Connections 25
- Browser UI → API Client: calls · UI actions are translated into backend requests
- Browser UI → UI Components: renders · Top-level app composes the interactive surfaces
- UI Components → Client Store: reads/writes · Components bind to shared client state
- API Client → API Entry: HTTP API · Frontend talks only to the FastAPI backend
- API Entry → Schemas: uses · Routes exchange typed request and response payloads
- API Entry → Upload API: mounts · Upload workflow is exposed as a route group
- API Entry → Chat API: mounts · Chat workflow is exposed as a route group
- API Entry → Analyze API: mounts · Analysis workflow is exposed as a route group
- API Entry → Story API: mounts · Story workflow is exposed as a route group
- API Entry → Data API: mounts · Mutation and lineage workflow is exposed as a route group
- Upload API → CSV Profiler: profiles · Uploaded CSVs are inspected and summarized
- Upload API → Data Tools: prepares · Profiled dataset context is made queryable
- Chat API → Data Tools: uses · Chat can run deterministic dataset operations
- Chat API → LLM Router: orchestrates · Conversational responses are routed through the model tier system
- Analyze API → LLM Router: forces strong tier · Structured analysis and visualization suggestions use the strongest model tier
- Story API → LLM Router: forces strong tier · Story generation relies on the strongest model tier
- Story API → Prompts: guides · Story behavior is shaped by dedicated prompts
- LLM Router → Prompts: consumes · Model routing is influenced by prompt and complexity logic
- Data Tools → Embeddings: feeds · Data can be chunked for semantic indexing
- Embeddings → Qdrant Access: stores vectors · Embeddings are written and retrieved through the vector store client
- Qdrant Access → Qdrant: persists to · Semantic memory lives in the Qdrant service
- Data API → Data Tools: mutates · Applied transformations and history operations use dataset tooling
- Local Stack → API Entry: starts · Local startup launches the backend server
- Local Stack → Browser UI: starts · Local startup launches the frontend app
- Local Stack → Qdrant: starts · Local startup brings up the vector database