How mathewgeejo/cartgenie works
1. Overall shape
- This is a split frontend/backend system centered on an autonomous shopping workflow. The Python backend owns all orchestration, retrieval, memory, and tool execution; the Next.js frontend is a thin interactive client.
2. Frontend boundary
- frontend/ is a Next.js 15 app with a chat-centric UI and recommendation surfaces (chat-ui, deal-banner, product-card, price-sparkline).
- It talks to the backend through frontend/lib/api.ts and renders streamed responses rather than waiting for a single synchronous completion.
3. API gateway
- api/main.py is the FastAPI entrypoint. It exposes the public contract: JWT auth, /chat streaming, product/deal/history/alert endpoints, WebSocket streaming, and /metrics.
- This layer is the security and transport boundary: request auth, rate limiting, streaming protocol handling, and response shaping happen here, not in the agent code.
4. Core orchestration
- graphs/shopping_graph.py is the main decision engine. It uses LangGraph-style orchestration with conditional routing, subgraph fan-out, checkpoint/resume, and a human-in-the-loop checkpoint before final decisioning.
- The graph is the central control plane that decides which agent or tool runs next and when to stop.
5. Specialized agent layer
- agents/ contains focused ReAct-style agents: product search, price comparison, review analysis, negotiation, reflection, decisioning, plus a supervisor.
- These agents are not the data sources themselves; they coordinate reasoning over tool outputs and feed results back into the graph.
6. Tool and provider boundary
- tools/ wraps the concrete capabilities used by agents: product search, price comparison, price history, deal finding, spec matching, stock alerts, review analysis, and RAG retrieval.
- tools/providers/ and tools/scrapers/ isolate external commerce sources and browser automation. The repo supports a mock catalog mode, so external API/site dependencies can be swapped out without changing agent contracts.
7. RAG subsystem
- rag/ provides hybrid retrieval and conversational QA support. The structure shows ingestion, retrievers, and a conversational chain, with hybrid dense/sparse retrieval and reranking described in the README.
- This subsystem is a separate knowledge path used when the agent needs product/spec/review context beyond live tool calls.
8. Memory and personalization
- memory/ stores user profiles plus short-term, long-term, and entity memory. This is the personalization/state layer that lets the assistant remember preferences, constraints, and prior interactions across turns.
- It sits alongside the graph rather than inside the frontend, so state can influence routing and decisions server-side.
9. Background processing
- workers/ defines a Celery app and tasks for asynchronous work. This is the non-interactive execution path for jobs that should not block chat turns, such as scraping, ingestion, alerts, or maintenance tasks.
- Redis is part of the runtime surface here, both as shared infrastructure and likely as the task broker/cache boundary.
10. Shared runtime and observability
- common/ holds cross-cutting infrastructure: LLM client setup, logging, metrics, observability hooks, retries, settings, text utilities, Redis client, and shared schemas.
- This is the glue that keeps API, agents, RAG, and workers consistent in configuration and telemetry.
11. Infrastructure and deployment
- infra/docker/, docker-compose.yml, and infra/terraform/ define the deployment boundaries: local multi-service composition, containerization, Prometheus metrics scraping, and AWS-oriented infrastructure stubs.
- The README also calls out ChromaDB, Redis, Playwright browser runtime, LangSmith/OpenTelemetry hooks, and Flower/Celery support as operational dependencies.
12. End-to-end flow
- A typical request is: frontend sends a chat message → FastAPI authenticates and streams the request into the shopping graph → the graph consults memory/RAG/tools/agents → results are optionally augmented by background workers or external providers → streamed recommendations and deal summaries are returned to the UI.
- The important architectural distinction is that the UI is presentation-only, the API is the transport/security layer, and the graph/agents/tools/memory/RAG stack contains the business logic.
13. Testing boundaries
- The repo is organized for layered verification: unit tests for tools, integration tests for agents, graph tests for routing, RAG retrieval tests, end-to-end shopping-flow tests, and load tests.
- That test split mirrors the runtime boundaries and is a good guide for drawing the architecture diagram.
Main entry points: product_search.py Commerce tools · shopping_graph.py Shopping graph · supervisor.py Supervisor · main.py API entry
Components 21
Frontend
Next.js client and presentation components
- Next app · Chat-centric frontend shell and page layout
frontend/app/page.tsx - Chat UI · Streaming chat interaction surface
frontend/components/chat-ui.tsx - Deal views · Recommendation and comparison presentation components
frontend/components/product-card.tsx - API client · Frontend transport wrapper for backend calls
frontend/lib/api.ts
API
FastAPI transport and auth boundary
Core backend
Orchestration, agents, tools, memory, and RAG
- Shopping graph · Conditional routing, checkpoints, and final decision control plane
graphs/shopping_graph.py - Supervisor · Coordinates specialized agents and task delegation
agents/supervisor.py - Search agent · Product discovery and query refinement
agents/product_search_agent.py - Compare agent · Price and offer comparison reasoning
agents/price_comparison_agent.py - Review agent · Review synthesis and sentiment analysis
agents/review_analyzer_agent.py - Decision agent · Recommendation and final choice synthesis
agents/decision_agent.py - Commerce tools · Search, pricing, deals, specs, alerts, and review utilities
tools/product_search.py - Providers · External commerce sources and mock catalog abstraction
tools/providers/ecommerce_sources.py - Scraper · Playwright-based site automation for external data access
tools/scrapers/playwright_scraper.py - RAG stack · Hybrid retrieval, ingestion, and conversational QA
rag/retrievers/hybrid.py - Memory · Profiles plus short-term, long-term, and entity memory
memory/stores/short_term.py - Shared runtime · LLM clients, logging, metrics, retries, settings, Redis, schemas
common/llm.py
Ops
Workers and deployment infrastructure
- Workers · Async background jobs for scraping, ingestion, alerts, and maintenance
workers/tasks.py - Deployment · Container, compose, Prometheus, and infrastructure definitions
docker-compose.yml
Connections 27
- Next app → Chat UI: renders · Page composes the chat experience
- Next app → Deal views: renders · Page shows recommendation surfaces
- Chat UI → API client: sends chat · UI calls backend for streaming responses
- Deal views → API client: loads data · Presentation components consume API-fed product data
- API client → API entry: HTTP/stream · Frontend client talks to the FastAPI boundary
- API entry → JWT auth: authenticates · Requests pass through JWT security checks
- API entry → API state: hydrates state · API handlers load request and conversation context
- API entry → Shopping graph: dispatches chat · Validated requests enter the orchestration graph
- Shopping graph → Supervisor: routes · Graph delegates control to agent supervision
- Shopping graph → Memory: reads/writes · Graph consults personalization and conversation state
- Shopping graph → RAG stack: retrieves context · Graph can invoke retrieval for product/spec knowledge
- Supervisor → Search agent: delegates · Supervisor fans out discovery work
- Supervisor → Compare agent: delegates · Supervisor fans out comparison work
- Supervisor → Review agent: delegates · Supervisor fans out review analysis work
- Supervisor → Decision agent: delegates · Supervisor gathers final recommendation reasoning
- Search agent → Commerce tools: uses · Search agent calls product and deal tools
- Compare agent → Commerce tools: uses · Comparison agent calls pricing and spec tools
- Review agent → Commerce tools: uses · Review agent calls review analysis tools
- Decision agent → Commerce tools: uses · Decisioning can consult commerce tools
- Commerce tools → Providers: queries · Tools resolve data through provider adapters
- Commerce tools → Scraper: scrapes · Tools can rely on browser automation for live sources
- RAG stack → Shared runtime: shares runtime · Retrieval uses common settings, logging, and LLM clients
- Shopping graph → Shared runtime: shares runtime · Orchestration depends on shared infrastructure helpers
- Workers → Commerce tools: executes async · Background tasks reuse the same commerce capabilities
- Workers → Shared runtime: shares runtime · Workers use common Redis, logging, and retry plumbing
- Deployment → Workers: deploys · Infrastructure defines worker runtime and service wiring
- Deployment → API entry: deploys · Infrastructure defines API container and runtime