# jivitesh-s/ctsnpn architecture

> Architecture diagram of the GitHub repository jivitesh-s/ctsnpn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jivitesh-s/ctsnpn
- Repository: https://github.com/jivitesh-s/ctsnpn

## Overview

#### Purpose and Entry Points
TechStore AI is a product-support and store-assistance system: a conversational RAG assistant backed by approved product/support knowledge, catalog lookup, reservations, and staff alerts. The backend entry point is the FastAPI app in `backend/main.py`; the browser client starts from `frontend/src/main.jsx` and mounts application/session UI in `frontend/src/App.jsx`. Deployment artifacts indicate container and process-hosting support through `Dockerfile`, `Procfile`, and `render.yaml`.

#### API Orchestration Boundary
`backend/main.py` is the HTTP boundary between the React client and backend services. README-defined public routes cover health, chat, catalog/product reads, and reservations; PIN-protected admin routes cover login, catalog upload, product mutation, and deletion. It owns request validation, routing, middleware/security/rate-limiting concerns, and delegates domain work rather than exposing storage or model internals directly.
- `backend/main.py`
- `backend/db.py`
- `backend/telegram_service.py`

#### Hybrid RAG Answering Pipeline
`backend/rag_service.py` is the conversational core: it retrieves approved support/product context, combines dense vector and lexical retrieval, reranks results, and sends grounded context to configured Groq/Gemini LLM inference. The key trust boundary is retrieval-to-generation: unsupported questions should receive a fallback rather than model-invented claims. The persisted retrieval corpus includes Chroma storage and a BM25 index, allowing runtime retrieval without rebuilding indexes.
- `backend/rag_service.py`
- `data/shop/chroma_db/chroma.sqlite3`
- `data/shop/bm25_index.pkl`

#### Knowledge Ingestion and Index Lifecycle
`backend/ingest.py` implements chunking, embedding, and index updates, including the admin-upload path described by the API. Source knowledge is split between product-specific text documents, policies/FAQ/support data, and catalog records. Offline scripts prepare, normalize, embed, inspect, and evaluate the corpus; these form a separate build/indexing stage from request-time answering.
- `backend/ingest.py`
- `data/shop/product_docs/`
- `data/shop/catalog.json`

#### Catalog and Reservation Persistence
`backend/db.py` provides the transactional application-data boundary for product catalog state and in-store reservations. The local SQLite database at `data/shop/products.db` is distinct from Chroma’s vector store: relational/catalog updates must stay consistent with search/index updates initiated through ingestion. Reservation creation triggers a staff-facing notification workflow rather than directly coupling UI clients to Telegram.
- `backend/db.py`
- `data/shop/products.db`
- `backend/telegram_service.py`

#### Customer Experience Composition
The React/Vite frontend is a single interactive assistant surface, with chat rendering and specialized response/action cards. `ShopPage` is the main experience layer; reusable components implement comparison, visual diagnostics, voice input/output, reservations, and video content. The frontend communicates over JSON and multipart API requests, preserving the backend as the authority for catalog, RAG, and reservations.
- `frontend/src/pages/ShopPage.jsx`
- `frontend/src/components/VisualDiagnosticCard.jsx`
- `frontend/src/components/ReservationModal.jsx`

#### External Services and Runtime Dependencies
The system runs Python/FastAPI/Uvicorn on the backend and React/Vite in the client. Material external integrations are Groq and Google Gemini for LLM inference and the Telegram Bot API for reservation alerts/OTP-related service behavior. ChromaDB stores dense vectors; BM25 supports lexical matching; the repository includes local generated indexes/data, so deployments require persistent writable storage when catalog ingestion or vector updates are enabled.
- `.env.example`
- `requirements.txt`
- `frontend/package.json`

Main entry points: [`backend/ingest.py`](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/ingest.py) (Ingestion service), [`backend/main.py`](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/main.py) (FastAPI application), [`frontend/src/pages/ShopPage.jsx`](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/pages/ShopPage.jsx) (ShopPage), [`backend/rag_service.py`](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/rag_service.py) (Hybrid RAG service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_frontend_entry["Vite entry<br/>React bootstrap<br/>[main.jsx]"]
  node_app_shell["Application shell<br/>session UI<br/>[App.jsx]"]
  node_shop_page["ShopPage<br/>assistant experience<br/>[ShopPage.jsx]"]
  node_diagnostic_card["Visual diagnostics<br/>response card"]
  node_reservation_modal["Reservation modal<br/>action UI"]
end

subgraph group_backend["Backend services"]
  node_api{{"FastAPI application<br/>HTTP API<br/>[main.py]"}}
  node_rag["Hybrid RAG service<br/>grounded answering<br/>[rag_service.py]"]
  node_ingest["Ingestion service<br/>index lifecycle<br/>[ingest.py]"]
  node_db["Application data service<br/>catalog and reservations<br/>[db.py]"]
  node_telegram["Telegram service<br/>staff notification"]
end

subgraph group_knowledge["Knowledge and data"]
  node_product_docs["Product documents<br/>knowledge source"]
  node_catalog_source["Catalog source<br/>knowledge source<br/>[catalog.json]"]
  node_app_db[("Products database<br/>SQLite<br/>[products.db]")]
  node_vector_store[("Chroma vector store<br/>dense retrieval index<br/>[chroma.sqlite3]")]
  node_bm25["BM25 index<br/>lexical retrieval index<br/>[bm25_index.pkl]"]
end

subgraph group_external["External services"]
  node_llm_providers{{"Groq and Gemini<br/>LLM inference"}}
  node_telegram_api{{"Telegram Bot API<br/>messaging API"}}
end

node_deployment["Container deployment<br/>runtime hosting"]

node_frontend_entry -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_shop_page
node_shop_page -->|"uses"| node_diagnostic_card
node_shop_page -->|"opens"| node_reservation_modal
node_shop_page -->|"JSON and multipart requests"| node_api
node_api -->|"chat requests"| node_rag
node_api -->|"catalog and reservations"| node_db
node_api -->|"admin uploads and catalog updates"| node_ingest
node_rag -->|"dense retrieval"| node_vector_store
node_rag -->|"lexical retrieval"| node_bm25
node_rag -->|"grounded prompts"| node_llm_providers
node_ingest -->|"chunks"| node_product_docs
node_ingest -->|"indexes"| node_catalog_source
node_ingest -->|"updates embeddings"| node_vector_store
node_ingest -->|"updates lexical index"| node_bm25
node_db -->|"reads and writes"| node_app_db
node_db -->|"reservation alert"| node_telegram
node_telegram -->|"sends notifications"| node_telegram_api
node_deployment -.->|"hosts"| node_api

click node_frontend_entry "https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/main.jsx"
click node_app_shell "https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/App.jsx"
click node_shop_page "https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/pages/ShopPage.jsx"
click node_diagnostic_card "https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/components/VisualDiagnosticCard.jsx"
click node_reservation_modal "https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/components/ReservationModal.jsx"
click node_api "https://github.com/jivitesh-s/ctsnpn/blob/main/backend/main.py"
click node_rag "https://github.com/jivitesh-s/ctsnpn/blob/main/backend/rag_service.py"
click node_ingest "https://github.com/jivitesh-s/ctsnpn/blob/main/backend/ingest.py"
click node_db "https://github.com/jivitesh-s/ctsnpn/blob/main/backend/db.py"
click node_telegram "https://github.com/jivitesh-s/ctsnpn/blob/main/backend/telegram_service.py"
click node_catalog_source "https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/catalog.json"
click node_app_db "https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/products.db"
click node_vector_store "https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/chroma_db/chroma.sqlite3"
click node_bm25 "https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/bm25_index.pkl"
click node_deployment "https://github.com/jivitesh-s/ctsnpn/blob/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_entry,node_app_shell,node_shop_page,node_diagnostic_card,node_reservation_modal toneBlue
class node_api,node_rag,node_ingest,node_db,node_telegram toneAmber
class node_product_docs,node_catalog_source,node_app_db,node_vector_store,node_bm25 toneMint
class node_llm_providers,node_telegram_api toneRose
class node_deployment toneNeutral
```

## Components

### Browser client

- [Vite entry](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/main.jsx): React bootstrap · `frontend/src/main.jsx`
- [Application shell](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/App.jsx): session UI · `frontend/src/App.jsx`
- [ShopPage](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/pages/ShopPage.jsx): assistant experience · Composes chat and product-support interactions. · `frontend/src/pages/ShopPage.jsx`
- [Visual diagnostics](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/components/VisualDiagnosticCard.jsx): response card · `frontend/src/components/VisualDiagnosticCard.jsx`
- [Reservation modal](https://github.com/jivitesh-s/ctsnpn/blob/main/frontend/src/components/ReservationModal.jsx): action UI · `frontend/src/components/ReservationModal.jsx`

### Backend services

- [FastAPI application](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/main.py): HTTP API · Public chat/catalog/reservation routes and PIN-protected admin operations. · `backend/main.py`
- [Hybrid RAG service](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/rag_service.py): grounded answering · Retrieves, reranks, and falls back when support is insufficient. · `backend/rag_service.py`
- [Ingestion service](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/ingest.py): index lifecycle · Chunks, embeds, and updates retrieval indexes after knowledge changes. · `backend/ingest.py`
- [Application data service](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/db.py): catalog and reservations · Transactional boundary for catalog state and reservations. · `backend/db.py`
- [Telegram service](https://github.com/jivitesh-s/ctsnpn/blob/main/backend/telegram_service.py): staff notification · `backend/telegram_service.py`

### Knowledge and data

- **Product documents**: knowledge source
- [Catalog source](https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/catalog.json): knowledge source · `data/shop/catalog.json`
- [Products database](https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/products.db): SQLite · Runtime catalog and reservation persistence. · `data/shop/products.db`
- [Chroma vector store](https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/chroma_db/chroma.sqlite3): dense retrieval index · `data/shop/chroma_db/chroma.sqlite3`
- [BM25 index](https://github.com/jivitesh-s/ctsnpn/blob/main/data/shop/bm25_index.pkl): lexical retrieval index · `data/shop/bm25_index.pkl`

### External services

- **Groq and Gemini**: LLM inference
- **Telegram Bot API**: messaging API

### Other components

- [Container deployment](https://github.com/jivitesh-s/ctsnpn/blob/main/Dockerfile): runtime hosting · Requires persistent writable storage when indexes are updated. · `Dockerfile`

## Connections

- Vite entry → Application shell: mounts
- Application shell → ShopPage: renders
- ShopPage → Visual diagnostics: uses
- ShopPage → Reservation modal: opens
- ShopPage → FastAPI application: JSON and multipart requests
- FastAPI application → Hybrid RAG service: chat requests
- FastAPI application → Application data service: catalog and reservations
- FastAPI application → Ingestion service: admin uploads and catalog updates
- Hybrid RAG service → Chroma vector store: dense retrieval
- Hybrid RAG service → BM25 index: lexical retrieval
- Hybrid RAG service → Groq and Gemini: grounded prompts
- Ingestion service → Product documents: chunks
- Ingestion service → Catalog source: indexes
- Ingestion service → Chroma vector store: updates embeddings
- Ingestion service → BM25 index: updates lexical index
- Application data service → Products database: reads and writes
- Application data service → Telegram service: reservation alert
- Telegram service → Telegram Bot API: sends notifications
- Container deployment → FastAPI application: hosts
