How sumit-616/shopping-app works
Main Components
• App Entry Point: At the heart of the application, you have src/main.jsx and src/App.jsx that bootstrap and render the overall UI.
• Pages & Routing: Under src/pages, key pages like Home.jsx and Cart.jsx represent distinct application views.
• UI Components: The src/components folder contains reusable elements such as Header.jsx, CardItem.jsx, ProductCard.jsx, and even a spinner implementation (spinner.jsx and spinner.css).
• API Integration: The src/api folder (with product.js) handles calls to external or internal services for product data.
• State Management: The src/context folder, with components like CartContext.jsx, encapsulates shared state, particularly for the shopping cart. In addition, src/hooks (like useProducts.js) manage local component state and fetching logic (noting that API handling leverages a hook, possibly integrated with react-query as mentioned in the README).
• Utility Functions: Helper functions like formatPrice.js in src/utils help keep non-UI logic modular and reusable.
• Styling & Configuration: Tailwind CSS configuration (tailwind.config.js) and other configuration files (eslint.config.js, vite.config.js) set up code quality, bundling, and styling rules.
Component Interactions
• The App component (src/App.jsx) acts as the central hub, loading page components and providing global state via CartContext.
• Pages like Home and Cart render collections of UI components, triggering API calls (src/api/product.js) and using hooks (src/hooks/useProducts.js) to fetch and display data.
• UI components (found in src/components) pull in state and actions from React Context and hooks to ensure interactive UI experiences.
• Utility functions (src/utils) are used across components to format data consistently.
Architectural Patterns
• Modularization: The project cleanly separates concerns by using dedicated folders for API calls, context state, hooks for business logic, and presentational components.
• React Hooks & Context: Efficient state management is central, where stateful logic is abstracted into hooks and shared using context providers.