How 9582anupam/bitebox works
Project type and purpose
• Frontend: React single-page app (SPA) with React Router, Context API, Material-UI/Tailwind CSS.
• Backend: Node.js + Express monolith exposing a RESTful API with JWT-based auth.
• Database: MongoDB for persisting users, products, orders.
File structure
• Top-level “Frontend” and “Backend” directories indicate a clear separation of concerns.
• Frontend:
• public/index.html + src folder (App.js, routes, components, services, context, utils)
• Organized into “common” UI components and “pages” (auth, home, category, product, cart)
• Axios service layer (userAuthenticatedAxiosInstance), React Context (UserContext)
• Backend:
• app.js/index.js bootstrapping Express server
• controllers (product, user), models (Mongoose schemas), routes (v1/products, v1/users)
• helper utilities (JWT token generation, chatbot calls), middleware (auth)
• db/index.js for MongoDB connection
• Deployment config: vercel.json suggests Frontend on Vercel, Backend likely on Heroku/AWS or Vercel Serverless.
Key insights from the README
• RESTful API with protected (JWT) and unprotected routes
• Features: authentication, product browsing, shopping cart, order placement, location‐based delivery
• Tech stack already confirms major components and external dependencies (MongoDB, JWT, Axios).
Main components
a. Client (Browser/Mobile)
• React SPA loaded from CDN/Vercel
• UI components, routing, context, axios HTTP client
b. API Layer (Backend)
• Express.js server instance
• Route handlers → controllers → business logic + helper utilities
• JWT auth middleware protecting endpoints
c. Data Layer
• MongoDB (Atlas or Self-hosted) with collections: users, products, orders
d. External Services
• (Optional) Third-party Map/Geolocation API for delivery tracking
• Chatbot service integration (via helper/chatbotCall.js)
• Email/SMS service for order notifications (if added)
e. Deployment/Hosting
• Frontend: Vercel (vercel.json)
• Backend: Node host (Heroku/AWS Lambda/Container)
• MongoDB Atlas or local instance
Relationships and interactions
• The React SPA issues HTTP requests (GET products, POST /login, POST /orders) to the Express server.
• Express routes invoke controllers, which in turn talk to Mongoose models and MongoDB.
• Auth middleware checks JWT from client on protected routes (e.g., order placement).
• Helper generateAccessAndRefreshToken issues tokens; refresh token endpoint issues new access tokens.
• For product pages, controllers may call chatbotCall utility to fetch recommendations or AI chat.
• Responses flow back to SPA for rendering.
• Optionally, backend sends notifications to external email/SMS gateway.
Architectural patterns and design principles
• Layered architecture: Presentation (React), API (Express controllers), Data Access (Mongoose models).
• Single-page app + RESTful API separation.
• JWT stateless authentication.
• Utility/helper modules encapsulate cross-cutting concerns (token gen, chatbot).
• Environment-based configuration via .env (backend) and REACT_APP_* (frontend).