How mervin-njy/malamola works
Project Type & Purpose
• Malamola is a full-stack e-commerce web application built on Next.js (App Router), React + TypeScript.
• It serves two personas: end-users (browse, search, add to cart, checkout) and admin (inventory, orders, enquiries, user management).
• Features include authentication (NextAuth with Google), product catalogue, cart & checkout, admin dashboard, and educational/social integrations.
Top-Level Components
a. Client Browser
• Static assets & React pages (app/(public)/..., app/admin/...)
• Next.js SSR/SSG and client-side React components (Navbar, CartDisplay, ProductCard, etc.)
b. Next.js Server (Node.js runtime)
• App Router endpoints map to React pages and server-side functions
• API routes under app/api/auth/[...nextauth]/route.ts for authentication
c. Business-Logic Layer
• Controller-like modules in app/components/actions and lib/db/* that orchestrate requests
• State management with Redux Toolkit (app/state/store.ts, languageSlice)
d. Data-Access Layer
• Prisma client (lib/db/prisma.ts) interacting with MongoDB via DATABASE_URL
• Data helpers in lib/db/cart.ts
e. External Services
• Google OAuth (via NextAuth adapter)
• MongoDB Atlas
Interactions & Data Flow
• User requests page → Next.js Router → SSR/SSG or CSR
• Page makes client-side calls to internal API endpoints (fetch /app/api/…) or uses Redux + React-Hook-Form + Zod for local form validation
• API routes invoke Prisma client → MongoDB
• NextAuth middleware syncs session with Google and stores user data in MongoDB
• Admin interface (protected routes) reads/writes via API or direct server component calls
Architectural Patterns & Principles
• Monolithic Next.js “app router” structure with separation of UI, API, and data.
• Layered architecture: Presentation (React components), Business (action helpers), Data (Prisma + MongoDB).
• Component-driven development: atomic UI (buttons, badges, inputs) under app/components.
• State slice per domain (language, cart, products).