How amm10090/amazon-frontend works
Project type and purpose
• This is a full-stack, server-rendered React application built with Next.js 15 (App Router).
• It aggregates Amazon discount product data, presents it via a user-facing storefront, and provides an admin dashboard (CMS) for content and user management.
• Key features: real-time data updates (SWR), personalized favorites, secure authentication (NextAuth.js + MongoDB), performance monitoring (Sentry, Hotjar), and rich animations (Framer Motion, Three.js).
File structure
• Top-level “app/” directory implements both UI pages (SSR/SSG/RSC) and API routes under “app/api/…/route.ts”.
• “app/auth/” houses authentication pages and server actions.
• “app/dashboard/” contains the admin CMS and blog management interfaces.
• “components/” holds reusable UI pieces, organized by domain (ui, layout, cms, dashboard, etc.).
• “lib/” contains API clients, server utilities, service layers, and database setup.
• “store/” is the Zustand state management layer.
• Config files: next.config.js, tsconfig.json, tailwind.config.mjs, plus environment templates.
• Supporting docs in “docs/” detail API usage, caching, and component guidelines.
Main components and boundaries
• Browser / Client:
• Next.js pages and client components
• SWR + Axios for data fetching
• React Three Fiber / Framer Motion on the client
• Next.js Server:
• App Router handling SSR/SSG/RSC
• API route handlers (REST endpoints under app/api)
• NextAuth.js server actions for login/session
• Database:
• MongoDB via Mongoose adapter
• Collections for users, products, categories, favorites, email templates
• External Services:
• Amazon Product APIs (data ingestion)
• Email provider / R2 storage for image uploads
• Sentry (error monitoring) / Hotjar (analytics)
• Third-party auth providers (Google, Facebook, etc.)
• Admin CMS:
• Dashboard UI communicates with the same API endpoints
• Rich text editor and file uploader components
Relationships and data flow
• User requests a page → Next.js server renders RSC/SSR → initial HTML + JS bundle sent.
• On client hydration, SWR/ Axios calls API routes for dynamic data (products, categories, user favorites).
• API route handlers verify session (NextAuth), interact with MongoDB, return JSON.
• Client components read/write global state via Zustand and local storage for guest favorites.
• Admin dashboard issues authenticated API calls to create/edit content.
• Background data ingestion jobs (could be external or triggered via API routes) fetch Amazon deals and populate the DB.
• Monitoring & analytics events flow from client/server to Sentry/Hotjar.
Key architectural patterns and principles
• Separation of concerns:
• UI vs. API vs. data services
• Components organized by domain
• Server Components (RSC) vs. Client Components
• Stateless API routes for CRUD operations
• Global state management via Zustand for cross-component state
• Caching & revalidation with SWR to achieve near real-time updates
• Secure authentication flow with NextAuth middleware
Essential elements
• Component labels (e.g., “Next.js Server”, “SWR fetch”, “Zustand Store”).
• Notes on key libraries (e.g., Framer Motion, Three.js, HeroUI) where they live in the stack.
• Clear separation of public storefront vs. admin dashboard modules.