How maxim-ibraiev/project-butterfly works
Project Type and Purpose
• This is a full‑stack e‑commerce web application built with Next.js (React + SSR/SSG), TypeScript, and MongoDB.
• The “pages” folder contains UI routes (public product listing, checkout, handmade, admin pages).
• The “pages/api” folder exposes Next.js API routes for frontend → backend communication.
• The “src/api” folder implements the actual server‑side logic: database connection, controllers, models, and routing.
• Client‑side state is managed via Redux and custom hooks; styling via CSS Modules and SCSS.
Top‑Level Architectural Components
a. Browser (User Agent)
b. Next.js Frontend Server
• pages/… (React components + SSR/SSG)
• src/components, src/pages (presentation layer)
• Redux store, custom hooks (state layer)
• API client module (src/api/serverApi.ts)
c. Next.js API Layer (pages/api)
• Routes for categories, products, shoppingBag, admin/auth, admin/images, admin/product
d. Core Server Logic (src/api/src)
• Database connector (connectToDatabase.ts)
• Schemas (Mongoose‑style) for categories, products, shoppingBag
• Controllers, Models, Routers per domain (MVC pattern)
• Middleware (validation, response standardization)
• ImageCloud integration for admin image uploads
e. Database
• MongoDB (cloud or local)
f. External Services
• Cloudinary (image storage)
g. Static Assets
Relationships and Data Flows
• Browser → Next.js Frontend pages (SSR or CSR)
• Client code calls API client (serverApi.ts) → HTTP → pages/api endpoints
• pages/api endpoint delegates to corresponding src/api/src/routes/*
→ controller → model → database
→ returns JSON up through API → client
• Redux actions dispatch based on JSON responses → update UI
• Admin pages authenticate → secure admin/api/auth → JWT/session
• Image uploads in admin call the ImageCloud service via backend
Architectural Patterns and Design Principles
• Layered architecture (presentation → API layer → business logic → data access)
• MVC pattern in server logic (routers → controllers → models)
• Separation of concerns: UI components vs state vs data‑fetching services vs server logic
• SSR/SSG for SEO and performance, client‑side hydration for interactivity
• Reusable UI components (atomic design approach)
• CSS Modules for scoping, Redux for global state