How hasan-py/hayroo works
1. This is a split-client/server marketplace application with a React SPA in client/ and an Express API in server/. The frontend is organized by user role and feature area, while the backend is organized by domain model and HTTP route.
2. The client is the presentation layer. client/src/App.js and the components/ tree route users into three main experiences: public shop, authenticated user dashboard, and admin dashboard. The app is likely a single-page app with client-side routing and protected-route wrappers for auth gating.
3. The shop experience is the customer-facing surface. Under components/shop/ you have home browsing, product detail pages, wishlist, cart modal, checkout, login/signup, order success messaging, and a user dashboard. This is the primary flow for discovering products, adding to cart, authenticating, and completing orders.
4. The admin experience is a separate subsystem under components/admin/. It contains dashboards, CRUD screens for categories/products/orders, and admin-specific layout/partials. This area is clearly distinct from the shop and is intended for inventory and order management rather than customer shopping.
5. A strong architectural pattern in the client is feature-local state and API wrappers. Many folders contain *Context.js files plus FetchApi.js/fetchApi.js helpers. That suggests state is managed per feature area, with components consuming context-provided data and invoking backend calls through feature-scoped API helpers.
6. The frontend is broken into reusable UI shells and partials: headers/navbars, sidebars, footers, modals, sliders, and layout components. These shared pieces keep the shop/admin flows visually and structurally separate while still reusing the same React runtime and asset pipeline.
7. The server is a classic layered REST API. server/app.js wires the Express application together, routes/ defines endpoints, controller/ holds business logic, models/ defines persistence entities, and middleware/auth.js enforces authorization. This boundary is important: routes are thin, controllers implement behavior, and models represent stored domain data.
8. The core backend domains are users, products, categories, orders, and customize, with a dedicated auth module and braintree payment module. These map directly to the frontend feature groups and define the main data flow of the application.
9. Data storage is MongoDB-based, not SQL-based, despite the course text in the README mentioning other technologies. The backend config includes db.js, keys.js, and environment-driven connection settings, and the deployment notes explicitly point to MongoDB Atlas for production.
10. Authentication and authorization are central boundaries. The client has ProtectedRoute, AdminProtectedRoute, and CartProtectedRoute, while the server has auth middleware plus auth/user controllers. Together they separate public browsing from logged-in actions, user-only actions, and admin-only actions.
11. Checkout/payment is handled as its own flow. The README and backend braintree.js route/controller indicate Braintree is used for payment tokenization and transaction processing, with orders created as part of that flow. This is the main external service that materially affects the architecture.
12. The order lifecycle crosses almost every layer: a user browses products, adds items to cart, checks out, the frontend calls order/payment endpoints, the server validates/authenticates, payment is processed through Braintree, and an order record is persisted. User dashboards and admin order screens then read that same order data.
13. There is also an image/file handling concern implied by uploadFolderCreateScript.js and the product/category CRUD flows. Product management likely depends on server-side upload/storage conventions so the admin can attach media to catalog items.
14. For deployment, the repo is designed to run as two processes locally: npm run start:dev in server/ and npm start in client/. Production guidance in the README points to deploying the backend on Render and the frontend separately, with environment variables supplying DB and Braintree credentials.
15. If you draw the architecture, the cleanest boundaries are: browser/UI at the edge, React feature modules in the middle, Express REST API behind them, MongoDB as the system of record, and Braintree as the external payment dependency. The major internal seams are shop vs admin, and auth-protected vs public flows.
Main entry points: auth.js HTTP routes · shop/index.js Shop flow · admin/index.js Admin flow · App.js App shell
Components 20
Client
React SPA and feature modules
- App shell · Top-level SPA entry with client-side routing and role-based entry points
client/src/App.js - Shop flow · Public shopping experience for browsing, carting, login, and checkout
client/src/components/shop/index.js - Admin flow · Admin-side experience for catalog, orders, and dashboard management
client/src/components/admin/index.js - Access gates · Protected route wrappers for user, admin, and cart-restricted actions
client/src/components/shop/auth/ProtectedRoute.js - Browse home · Homepage browsing, category navigation, product tiles, and merchandising
client/src/components/shop/home/index.js - Product detail · Single-product view, reviews, and detail subcomponents
client/src/components/shop/productDetails/index.js - Checkout · Cart review and checkout flow for completing purchases
client/src/components/shop/order/CheckoutPage.js - User dashboard · Authenticated customer area for profile settings and order history
client/src/components/shop/dashboardUser/index.js - Admin dashboard · High-level admin overview and sales widgets
client/src/components/admin/dashboardAdmin/index.js - Catalog admin · Category and product management screens and modals
client/src/components/admin/products/index.js - Order admin · Order listing, filtering, and update screens for fulfillment
client/src/components/admin/orders/index.js - Shared UI · Reusable navigation, footer, sidebar, modal, and layout pieces
client/src/components/shop/partials/index.js
Server
Express API, controllers, models, and config
- Express app · Server application wiring and middleware setup
server/app.js - HTTP routes · Endpoint definitions for auth, users, products, categories, orders, customize, and payments
server/routes/auth.js - Controllers · Domain logic for auth, users, products, categories, orders, customize, and Braintree
server/controller/products.js - Models · Mongo-backed persistence models for the main domains
server/models/products.js - Auth middleware · Server-side authentication and authorization checks
server/middleware/auth.js - Config & upload · Database connection, secrets, and upload-folder setup
server/config/db.js
External
Managed data and payment dependencies
- MongoDB · Primary system of record for users, products, categories, orders, and customization
- Braintree · External payment provider for tokenization and transactions
Connections 29
- App shell → Access gates: guards · App routes are wrapped by role-based protection
- App shell → Shop flow: routes to · Unauthenticated users enter the shop experience
- App shell → Admin flow: routes to · Admins enter the management experience
- App shell → User dashboard: routes to · Signed-in users can reach account pages
- Shop flow → Browse home: includes · Primary customer browsing surface
- Shop flow → Product detail: includes · Product pages are part of shopping flow
- Shop flow → Checkout: includes · Cart and checkout complete the purchase flow
- Shop flow → Shared UI: reuses · Shared shells and partials support the shop
- Admin flow → Admin dashboard: includes · Admin overview dashboard
- Admin flow → Catalog admin: includes · Catalog CRUD area
- Admin flow → Order admin: includes · Order management area
- Admin flow → Shared UI: reuses · Admin layout and nav are built from shared pieces
- User dashboard → Shared UI: reuses · Customer account pages reuse common UI structure
- Checkout → HTTP routes: calls · Checkout posts order and payment requests to the API
- Browse home → HTTP routes: calls · Browsing and category/product listing consume API data
- Product detail → HTTP routes: calls · Product details and reviews fetch from the API
- Catalog admin → HTTP routes: calls · Admin CRUD screens drive backend mutations
- Order admin → HTTP routes: calls · Order admin reads and updates order data
- User dashboard → HTTP routes: calls · User dashboard reads profile and orders
- Express app → HTTP routes: mounts · Express app wires route modules
- HTTP routes → Controllers: delegates · Routes stay thin and hand off to controllers
- HTTP routes → Auth middleware: protects · Authorized endpoints enforce access control
- Controllers → Models: uses · Controllers read and write persisted domain data
- Controllers → Braintree: charges · Payment controller integrates with Braintree
- Config & upload → MongoDB: connects · Database config points to MongoDB
- Models → MongoDB: persists to · Application state is stored in MongoDB
- Config & upload → Express app: configures · Runtime config and upload conventions support the API
- Catalog admin → Config & upload: depends on · Media-heavy admin flows rely on upload conventions
- Checkout → Braintree: depends on · Payment completion is mediated by the server via Braintree