How digvijaynarayanpandey/swiggy-clone-food works
Main Components
• User Interface (UI) Layer:
• Core layout files: index.html and index.css.
• React components located under src/components such as Header, Body, About, Cart, Contact, RestaurantCard, and others.
• Additional visual elements like Shimmer components for loading states.
• State Management:
• Redux Toolkit integration with appStore.js and cartSlice.js in src/utilis.
• In addition, UserContext.js may provide context-level state.
• API Integration:
• Although not explicitly defined as a separate module, the interaction with Swiggy’s Live API is a core backend service that feeds data to the UI.
• Utility and Helper Functions:
• Various hooks and utility functions like useRestaurantMenu.js, useOnlineStatus.js, and constants.js.
• Testing:
• Jest test files in the __tests__ folders verify component behavior and logic.
• Bundler and Build Tools:
• Configuration files such as babel.config.js, parcelrc, tailwind.config.js, and postcssrc indicate build processes and styling approaches (Tailwind CSS).
Relationships and Interactions
a. Data Flow:
• Request Initiation: When the application loads (index.js), API calls are made to the Swiggy Live API for restaurant data.
• Data Processing: Utility functions (like useRestaurantMenu) and Redux slices process and store the fetched data.
• UI Update: React components subscribe to the Redux store or context to render current data like restaurant lists, cart contents, and filters.
b. Component Hierarchy:
• Parent Components (e.g., Header, Body) wrap child components (e.g., RestaurantCard, RestaurantMenuCard) to display different UI sections.
• Error and Loading states are handled through dedicated components like Error.js and Shimmer.js.
c. Testing Workflow:
• Components and crucial functions are isolated in tests to ensure both UI and state management work as expected.
Notable Architectural Patterns and Principles
• Component-based Architecture: The React component tree represents a clear hierarchy; every part of the UI is broken down into reusable components.
• Unidirectional Data Flow: Through Redux and Context API, data flows from API calls to store and then through components.
• Separation of Concerns: The project separates presentation (components), business logic (utilities and Redux slices), configuration (build files), and testing (Jest tests).