How m-asadjaved/medsonline4u works
Project Type and Purpose
• This is a full-stack Next.js e-commerce application with two primary “domains”:
a. Public storefront (“home”) where customers browse products, add to cart, checkout, contact, etc.
b. Admin panel (“admin”) where site administrators manage products, orders, and images.
• The app also provides a set of built-in REST-style API routes (src/app/api/...) for data operations.
Key Architectural Components
a. Presentation Layer (Frontend)
• Next.js React pages and layout files under src/app/(home) and src/app/(admin).
• Shared UI primitives in src/components/ui, high-level components in src/components.
• Cart context provider (src/context/CartContext.js) and custom React hooks (src/hooks/use-mobile.js).
b. API Layer (Backend endpoints)
• Next.js API routes in src/app/api, organized by domain (products, orders, auth, contact, admin/images).
• Each route implements CRUD or action logic under /route.js.
c. Business Logic & Data Access
• Utility and data-access modules in src/lib:
• mysql.js for MySQL connection and queries
• redis.js for caching/session management
• limiter.js / ip.js for rate-limiting and security
• users.js for authentication logic
d. Data Stores & External Services
• MySQL database as primary persistent store (products, orders, users).
• Redis for caching cart sessions or rate-limit counters.
• Cloud storage (S3 or Vercel’s built-in asset storage) for admin image uploads.
• Email/contact service or leads store for contact form submissions.
e. Hosting/Deployment
• Deployed on Vercel, leveraging serverless functions for API routes, automatic SSR/SSG.
Relationships and Data Flows
a. Browser → Next.js Frontend
• Users navigate public pages (SSR/SSG) or admin pages (protected via auth).
• UI components fetch data client-side via fetch/XHR to API routes.
b. Frontend ↔ API Layer
• REST calls to endpoints like /api/products, /api/orders/new, /api/admin/products/save.
• Auth route /api/auth issues tokens/cookies.
c. API Layer → Data Stores
• API logic invokes src/lib/mysql.js for SQL queries.
• Caching or session data via src/lib/redis.js.
• Image uploads handled by admin API routes writing to cloud storage.
d. Admin Panel → Image Storage & Admin APIs
• ImageManagerClient uploads images via /api/admin/images/upload, lists via /list, deletes via /delete.
Architectural Patterns and Principles
• Separation of Concerns: clear split between UI components, API endpoints, and data-access layers.
• Modular React Components & composition via src/components/ui.
• Domain-driven API route organization (products, orders, auth, shipping, contact).
• Serverless Functions pattern: each Next.js API route is its own micro-endpoint.
• Context API for global state (shopping cart).
• Rate limiting and security at edge (lib/limiter, ip).