# hasan-py/hayroo architecture

> Architecture diagram of the GitHub repository hasan-py/hayroo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hasan-py/hayroo
- Repository: https://github.com/hasan-py/hayroo

## Overview

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: [`server/routes/auth.js`](https://github.com/hasan-py/hayroo/blob/master/server/routes/auth.js) (HTTP routes), [`client/src/components/shop/index.js`](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/index.js) (Shop flow), [`client/src/components/admin/index.js`](https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/index.js) (Admin flow), [`client/src/App.js`](https://github.com/hasan-py/hayroo/blob/master/client/src/App.js) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["App shell<br/>React entry/router<br/>[App.js]"]
  node_client_public["Shop flow<br/>customer UI<br/>[index.js]"]
  node_client_admin["Admin flow<br/>admin UI<br/>[index.js]"]
  node_client_auth{{"Access gates<br/>route guards<br/>[ProtectedRoute.js]"}}
  node_client_home["Browse home<br/>shop browsing<br/>[index.js]"]
  node_client_product["Product detail<br/>product page<br/>[index.js]"]
  node_client_checkout["Checkout<br/>order UI<br/>[CheckoutPage.js]"]
  node_client_userdash["User dashboard<br/>customer account<br/>[index.js]"]
  node_client_admin_dash["Admin dashboard<br/>ops dashboard<br/>[index.js]"]
  node_client_admin_catalog["Catalog admin<br/>CRUD UI<br/>[index.js]"]
  node_client_admin_orders["Order admin<br/>order ops<br/>[index.js]"]
  node_client_shared["Shared UI<br/>partials/layout<br/>[index.js]"]
end

subgraph group_server["Server"]
  node_server_app["Express app<br/>API bootstrap<br/>[app.js]"]
  node_server_routes["HTTP routes<br/>REST routes<br/>[auth.js]"]
  node_server_ctrl["Controllers<br/>business logic<br/>[products.js]"]
  node_server_models[("Models<br/>[products.js]")]
  node_server_authmw{{"Auth middleware<br/>authorization<br/>[auth.js]"}}
  node_server_config["Config & upload<br/>runtime config<br/>[db.js]"]
end

subgraph group_external["External"]
  node_mongo[("MongoDB<br/>database")]
  node_braintree{{"Braintree<br/>payments"}}
end

node_client_app -->|"guards"| node_client_auth
node_client_app -->|"routes to"| node_client_public
node_client_app -->|"routes to"| node_client_admin
node_client_app -->|"routes to"| node_client_userdash
node_client_public -->|"includes"| node_client_home
node_client_public -->|"includes"| node_client_product
node_client_public -->|"includes"| node_client_checkout
node_client_public -->|"reuses"| node_client_shared
node_client_admin -->|"includes"| node_client_admin_dash
node_client_admin -->|"includes"| node_client_admin_catalog
node_client_admin -->|"includes"| node_client_admin_orders
node_client_admin -->|"reuses"| node_client_shared
node_client_userdash -->|"reuses"| node_client_shared
node_client_checkout -->|"calls"| node_server_routes
node_client_home -->|"calls"| node_server_routes
node_client_product -->|"calls"| node_server_routes
node_client_admin_catalog -->|"calls"| node_server_routes
node_client_admin_orders -->|"calls"| node_server_routes
node_client_userdash -->|"calls"| node_server_routes
node_server_app -->|"mounts"| node_server_routes
node_server_routes -->|"delegates"| node_server_ctrl
node_server_routes -->|"protects"| node_server_authmw
node_server_ctrl -->|"uses"| node_server_models
node_server_ctrl -->|"charges"| node_braintree
node_server_config -->|"connects"| node_mongo
node_server_models -->|"persists to"| node_mongo
node_server_config -->|"configures"| node_server_app
node_client_admin_catalog -.->|"depends on"| node_server_config
node_client_checkout -.->|"depends on"| node_braintree

click node_client_app "https://github.com/hasan-py/hayroo/blob/master/client/src/App.js"
click node_client_public "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/index.js"
click node_client_admin "https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/index.js"
click node_client_auth "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/auth/ProtectedRoute.js"
click node_client_home "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/home/index.js"
click node_client_product "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/productDetails/index.js"
click node_client_checkout "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/order/CheckoutPage.js"
click node_client_userdash "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/dashboardUser/index.js"
click node_client_admin_dash "https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/dashboardAdmin/index.js"
click node_client_admin_catalog "https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/products/index.js"
click node_client_admin_orders "https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/orders/index.js"
click node_client_shared "https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/partials/index.js"
click node_server_app "https://github.com/hasan-py/hayroo/blob/master/server/app.js"
click node_server_routes "https://github.com/hasan-py/hayroo/blob/master/server/routes/auth.js"
click node_server_ctrl "https://github.com/hasan-py/hayroo/blob/master/server/controller/products.js"
click node_server_models "https://github.com/hasan-py/hayroo/blob/master/server/models/products.js"
click node_server_authmw "https://github.com/hasan-py/hayroo/blob/master/server/middleware/auth.js"
click node_server_config "https://github.com/hasan-py/hayroo/blob/master/server/config/db.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_app,node_client_public,node_client_admin,node_client_auth,node_client_home,node_client_product,node_client_checkout,node_client_userdash,node_client_admin_dash,node_client_admin_catalog,node_client_admin_orders,node_client_shared toneBlue
class node_server_app,node_server_routes,node_server_ctrl,node_server_models,node_server_authmw,node_server_config toneAmber
class node_mongo,node_braintree toneMint
```

## Components

### Client

React SPA and feature modules

- [App shell](https://github.com/hasan-py/hayroo/blob/master/client/src/App.js): React entry/router · Top-level SPA entry with client-side routing and role-based entry points · `client/src/App.js`
- [Shop flow](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/index.js): customer UI · Public shopping experience for browsing, carting, login, and checkout · `client/src/components/shop/index.js`
- [Admin flow](https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/index.js): admin UI · Admin-side experience for catalog, orders, and dashboard management · `client/src/components/admin/index.js`
- [Access gates](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/auth/ProtectedRoute.js): route guards · Protected route wrappers for user, admin, and cart-restricted actions · `client/src/components/shop/auth/ProtectedRoute.js`
- [Browse home](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/home/index.js): shop browsing · Homepage browsing, category navigation, product tiles, and merchandising · `client/src/components/shop/home/index.js`
- [Product detail](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/productDetails/index.js): product page · Single-product view, reviews, and detail subcomponents · `client/src/components/shop/productDetails/index.js`
- [Checkout](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/order/CheckoutPage.js): order UI · Cart review and checkout flow for completing purchases · `client/src/components/shop/order/CheckoutPage.js`
- [User dashboard](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/dashboardUser/index.js): customer account · Authenticated customer area for profile settings and order history · `client/src/components/shop/dashboardUser/index.js`
- [Admin dashboard](https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/dashboardAdmin/index.js): ops dashboard · High-level admin overview and sales widgets · `client/src/components/admin/dashboardAdmin/index.js`
- [Catalog admin](https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/products/index.js): CRUD UI · Category and product management screens and modals · `client/src/components/admin/products/index.js`
- [Order admin](https://github.com/hasan-py/hayroo/blob/master/client/src/components/admin/orders/index.js): order ops · Order listing, filtering, and update screens for fulfillment · `client/src/components/admin/orders/index.js`
- [Shared UI](https://github.com/hasan-py/hayroo/blob/master/client/src/components/shop/partials/index.js): partials/layout · Reusable navigation, footer, sidebar, modal, and layout pieces · `client/src/components/shop/partials/index.js`

### Server

Express API, controllers, models, and config

- [Express app](https://github.com/hasan-py/hayroo/blob/master/server/app.js): API bootstrap · Server application wiring and middleware setup · `server/app.js`
- [HTTP routes](https://github.com/hasan-py/hayroo/blob/master/server/routes/auth.js): REST routes · Endpoint definitions for auth, users, products, categories, orders, customize, and payments · `server/routes/auth.js`
- [Controllers](https://github.com/hasan-py/hayroo/blob/master/server/controller/products.js): business logic · Domain logic for auth, users, products, categories, orders, customize, and Braintree · `server/controller/products.js`
- [Models](https://github.com/hasan-py/hayroo/blob/master/server/models/products.js): data models · Mongo-backed persistence models for the main domains · `server/models/products.js`
- [Auth middleware](https://github.com/hasan-py/hayroo/blob/master/server/middleware/auth.js): authorization · Server-side authentication and authorization checks · `server/middleware/auth.js`
- [Config & upload](https://github.com/hasan-py/hayroo/blob/master/server/config/db.js): runtime config · Database connection, secrets, and upload-folder setup · `server/config/db.js`

### External

Managed data and payment dependencies

- **MongoDB**: database · Primary system of record for users, products, categories, orders, and customization
- **Braintree**: payments · External payment provider for tokenization and transactions

## Connections

- 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
