How pateldev01/araamifrontend works
Project Type and Purpose
• This is a full‑stack, e‑commerce web application built with Next.js (React) using server‑side rendering (SSR), static‑site generation (SSG) and client‑side state management.
• The “pages” directory defines the routing and SSR/SSG functions, “server.js” provides a custom Node/Express server for middleware and advanced routing, and “src/components” contains hundreds of reusable UI components.
File‑Structure Analysis
• Top‑level highlights:
• Middleware/ – custom Express middleware for authentication, maintenance mode, multi‑vendor routing
• pages/ – Next.js page components and dynamic routes (SSR/SSG)
• public/ – static assets served via CDN (images, fonts, manifest, Service Worker)
• src/components/ – UI building blocks grouped by feature/domain (Auth, Cart, Blogs, Home, etc.)
• src/contexts, src/store – client‑side state (React Context & Zustand stores)
• utils/ – API wrapper, auth utilities, formatters, settings
• server.js, next.config.js – custom server entry point and build configuration
README Insights
• Confirms Next.js usage with custom server support.
• No built‑in backend code under pages/api, implying external APIs or microservices handle data persistence.
• Emphasis on image dimensions hints at static‑asset optimization and CDN usage.
a. Client Layer (Browser/Mobile)
– Renders SSR/SSG HTML, hydrates to React
– Interacts via HTTP/HTTPS with the Next.js server and external APIs
b. CDN / Static File Delivery
– Serves files under /public/assets, SW, images, fonts
c. Next.js Custom Server (Node.js + Express)
– Entry: server.js → attaches middleware (isAuth, isMaintenance, isMultivendor)
– Routing: delegates to Next’s page router or API routes if defined
– SSR/SSG: invokes getServerSideProps / getStaticProps in pages/*
d. Business Logic Layer
– pages/* (React pages) orchestrate data fetching via utils/apiRequest
– src/components/* render UI; grouped by feature (Auth, Cart, Home, Blogs, Profile, etc.)
e. Client‑Side State Management
– React Contexts (src/contexts) for global behaviors (login state)
– Zustand stores (src/store) for cart, wishlist, compare, site settings
f. Data & External Services
– External Commerce APIs: product catalog, user auth, orders
– Third‑party services: Payment gateway, Email/Verification service, CDN for images
g. Utility Layer
– utils/ modules for formatting, auth token handling, API requests, language, and settings
Component Interactions & Data Flow
• Browser → Next.js server: initial request for a page (SSR/SSG)
• Next.js server → External API: fetch data via utils/apiRequest inside getServerSideProps
• Next.js server → CDN: fetch static assets (images, fonts, SW) for page rendering
• Browser → External API: after hydration, client‑side code (components + store) issues XHR/fetch to APIs
• Client‑side store/contexts manage state (cart, user session) and broadcast updates to components
Architectural Patterns & Design Principles
• Separation of concerns: Routing (pages/), UI (components/), State (contexts + store), Data (utils/)
• SSR/SSG for SEO and performance, with SW for offline support (public/sw.js + workbox)
• Atomic UI: very granular, feature‑based component directories
• Middleware pipeline in custom server for auth and environment gating