This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a React + TypeScript + Vite web application for browsing grocery products, comparing prices, and viewing price trends. The application displays products organized by categories, shows price history charts, and provides product search functionality.
npm run devThe dev server runs with --host flag to allow external connections. Vite is configured to allow the host dfmoller-acer-aspire.springbok-cod.ts.net.
npm run buildThis runs TypeScript compilation (tsc -b) followed by Vite build.
npm run lintOr to lint specific directories:
npx eslint ./src/npm run previewPlaywright is installed (@playwright/test in devDependencies), but no test configuration or test files exist yet in the repository.
The application uses Redux Toolkit Query (RTK Query) for API calls and caching. This is a critical architectural decision:
- RTK Query API Definition:
src/redux/api.tsxdefines the API slice usingcreateApiwith a base URL of/api - Configured Endpoints:
getStoreById,getGrocerById,getGrocerByStoreIdgetCategories,getCategoryByIdgetProductById
- Auto-generated Hooks: The API exports hooks like
useGetProductByIdQuery,useGetCategoriesQuerythat handle loading states, caching, and refetching - Store Setup:
src/redux/store.tsxconfigures the Redux store with RTK Query middleware for caching, invalidation, and polling - Provider: The app is wrapped with
ApiProviderinsrc/main.tsx
Important for Caching: To benefit from RTK Query caching, always use useNavigate() or <Link> from react-router-dom for navigation. Other navigation methods may cause full page reloads and bypass the cache.
There are two different patterns for API calls in this codebase:
- RTK Query (Preferred): Used in
src/redux/api.tsxfor frequently-accessed resources that benefit from caching (stores, grocers, categories, products) - Direct Fetch API: Used in
src/api/fetchapi.tsxfor specialized endpoints like:getCategoryPopulatedById- categories with product associationsgetCategoryProducts- paginated products in a categorygetProductDetailedImage,getProductThumbnailImage- product imagesgetProductLatestPrices,getProductPriceHistory- price data with flexible query parameterssearchProducts- product search with pagination
The direct fetch pattern is used where RTK Query caching doesn't provide obvious benefits (e.g., one-off queries with many parameters) or for simpler implementation.
Routes defined in src/App.tsx:
/- Landing view/deals- Deals view/search- Search view/products/:productId- Product detail view (standalone)/categories/:categoryId- Subcategory selection view/categories/:categoryId/:subCategoryId- Product list view/categories/:categoryId/:subCategoryId/:productId- Product detail view (with category context)
Note: The ProductView component (src/views/ProductView.tsx) handles two different routing patterns:
- Via categories:
/categories/:categoryId/:subCategoryId/:productId- includes breadcrumb navigation through category hierarchy - Direct/search:
/products/:productId- used when accessing from search or direct links
- Material-UI (MUI v7): All components use
@mui/materialwith@emotion/reactand@emotion/styledfor styling - Layout Pattern: Many views use a flex layout with
CategoryDraweron the left and scrollable content on the right - Responsive Grid: Uses MUI's Grid component with size props (not the older xs/sm/md pattern)
- Header (
src/components/Header.tsx): App-wide navigation bar - CategoryDrawer (
src/components/CategoryDrawer.tsx): Side navigation for browsing categories - ProductCard (
src/components/ProductCard.tsx): Reusable product display component - BreadCrumbs (
src/components/BreadCrumbs.tsx): Navigation breadcrumb trail - GrocerPill (
src/components/GrocerPill.tsx): Display grocer badge/label
- Recharts library is used for price trend visualization
- ProductView shows an AreaChart with customizable time ranges (24h, 7d, 30d, 90d, 1y)
- Price data is fetched from the API in descending order (newest first) and reversed for chronological display
All API types are defined in src/api/fetchapi.tsx:
Grocer,Store- grocery store entitiesCategory- hierarchical category structure withparent_idandchildrenCategoryPopulated- category with associated productsCategoryProductAssociation- links products to categories with similarity scoresProduct- product entityProductsPaginated- paginated product list responseProductImage- product image metadataPrice- price record with timestampPriceHistoryParams- query parameters for price history API
The backend API is expected to be available at /api (proxied in development). When adding new endpoints:
- For frequently-accessed resources that benefit from caching, add to RTK Query API in
src/redux/api.tsx - For specialized queries with complex parameters or one-off usage, add direct fetch functions to
src/api/fetchapi.tsx - Always define TypeScript interfaces for request/response types
- Ensure proper error handling in components using the APIs
- Line Length: Maximum 120 characters per line
- Comments: Add comments when they provide meaningful value. Briefly state what is being done, but focus on the why. All comments must end with a period.
- Docstrings: Add docstrings to functions when the function name itself does not fully indicate what it does or how it should be used.
- Indentation: Use 2 spaces consistently
- React Components: Prefer functional components with hooks
- No Emojis: Never use emojis in comments or documentation
From code comments:
- App.tsx:28-29: Consider consolidating category views - if category has subcategories show subcategories, if it has products show products directly
- ProductView.tsx:60: Add proper error handling for API calls (currently errors are not displayed to users)