# seyityahya/ecommerce_react_node architecture

> Architecture diagram of the GitHub repository seyityahya/ecommerce_react_node, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seyityahya/ecommerce_react_node
- Repository: https://github.com/seyityahya/ecommerce_react_node

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce style application.
- Frontend: React SPA (Create-React-App) with pages for authentication, product browsing, basket, orders, admin dashboard.
- Backend: Node.js/Express REST API with modules for auth, products, orders, role-based access, rate limiting.
- Data Stores: MongoDB (persistent storage) and Redis (cache and rate-limiter).
- Authentication: JWT (access + refresh tokens).
- Purpose: allow customers to browse products, place orders, maintain a shopping basket; allow admins to manage products and view orders.

##### File Structure
- Top‐level: /frontend and /backend.
- Backend layers under src/
- clients/ – MongoDB client (mongoose), Redis client (ioredis)
- controllers/ – business logic per resource (auth, product, order)
- models/ – Mongoose schemas (user, product, order)
- middlewares/ – grantAccess, input validations, JWT checks
- helpers/ – JWT token creation/verification
- rate-limiter.js – Redis‐based request throttling
- routes/ – Express router modules mapping endpoints to controllers
- app.js – Express server setup, CORS, body parsing, route mounting
- Frontend under src/
- pages/ – each route view (Auth, Products, Basket, Profile, Admin)
- components/ – reusable UI widgets (Card, Navbar, etc.)
- contexts/ – React Context for auth state and basket state
- api.js – axios instance pointing at backend API
- React-Query, Formik, Yup for data fetching and form management

1. Client Browser (React SPA)
2. Frontend Application (React + Context + React-Query + Router)
3. HTTP/API Layer (axios calls to backend)
4. Backend Application (Node.js/Express)
– Rate Limiter (Redis)
– Authentication Middleware (JWT)
– Controllers (Auth, Product, Order)
– Validation Layer (Joi/Yup rules)
5. Data Layer
– MongoDB (persistent)
– Redis (cache, session, rate-limiting)
- User → Browser → React SPA → triggers API call → axios →
- Express Router → Middleware (rate-limit → auth) → Controller →
- Controller uses Data Clients → reads/writes Redis or MongoDB → returns JSON →
- Axios receives response → React-Query updates cache → UI re-renders.
c. Architectural Patterns
- Layered (Presentation → API → Business Logic → Data Access)
- MVC-style within backend (Routes → Controllers → Models)
- Use of middleware chain (CORS, logging, rate-limit, auth, validation)
- Separation of concerns: dedicated clients for DB & cache, helpers for JWT, contexts for frontend state.
d. Key Technologies & Libraries
- Frontend: React, React Router, React-Query, Formik, Chakra UI, AntD, Axios
- Backend: Node.js, Express, Mongoose, ioredis, Joi, jsonwebtoken, accesscontrol, bcrypt
- Data Stores: MongoDB Atlas, Redis
- Dev & Env: Yarn, dotenv, sucrase, nodemon

##### Detail
- Cross-cutting concerns: validation, error handling (boom), logging if used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    Client["Client Browser"]:::infra

    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        App["App.js"]:::frontend
        Index["index.js"]:::frontend
        Signin["Signin Page"]:::frontend
        SigninVal["Signin Validations"]:::frontend
        Signup["Signup Page"]:::frontend
        SignupVal["Signup Validations"]:::frontend
        ProdList["Product List Page"]:::frontend
        ProdVal["Product List Validations"]:::frontend
        ProdNew["New Product Page"]:::frontend
        ProdDetailPage["Product Detail Page"]:::frontend
        Basket["Basket Page"]:::frontend
        Profile["Profile Page"]:::frontend
        AdminHome["Admin Home Page"]:::frontend
        AdminProd["Admin Products Page"]:::frontend
        AdminProdDet["Admin Product Detail Page"]:::frontend
        AdminProdDetVal["Admin ProdDetail Validations"]:::frontend
        AdminOrders["Admin Orders Page"]:::frontend
        ProtAdmin["ProtectedAdmin"]:::frontend
        ProtProfile["ProtectedProfile"]:::frontend
        Card["Card Component"]:::frontend
        Navbar["Navbar Component"]:::frontend
        NavbarCSS["Navbar Styles"]:::frontend
        AuthCtx["AuthContext"]:::frontend
        BasketCtx["BasketContext"]:::frontend
        API["api.js"]:::frontend
    end

    %% Connection: User interaction
    Client -->|"renders"| App
    App -->|"uses context & pages"| AuthCtx
    App --> BasketCtx
    App --> API
    API -->|"HTTP/JSON"| BackendApp

    %% Backend Layer
    subgraph "Backend (Express API)"
        BackendApp["app.js"]:::backend
        RoutesIndex["routes/index.js"]:::backend
        AuthRoutes["Auth Routes"]:::backend
        ProdRoutes["Product Routes"]:::backend
        OrderRoutes["Order Routes"]:::backend
        RateLimiter["Rate Limiter"]:::backend
        CacheMod["cache.js"]:::backend
        GrantAccess["grantAccess Middleware"]:::backend
        AuthCtrl["Auth Controller"]:::backend
        AuthVal["Auth Validations"]:::backend
        JWT["JWT Helpers"]:::backend
        ProdCtrl["Product Controller"]:::backend
        ProdValB["Product Validations"]:::backend
        OrderCtrl["Order Controller"]:::backend
        OrderVal["Order Validations"]:::backend
        DBClient["db.js (MongoDB Client)"]:::backend
        RedisClient["redis.js (Redis Client)"]:::backend
        Roles["roles.js"]:::backend
    end

    %% Backend Flow
    BackendApp -->|"mounts"| RoutesIndex
    RoutesIndex --> AuthRoutes
    RoutesIndex --> ProdRoutes
    RoutesIndex --> OrderRoutes

    AuthRoutes --> RateLimiter
    ProdRoutes --> RateLimiter
    OrderRoutes --> RateLimiter

    RateLimiter --> CacheMod
    CacheMod --> RedisClient

    AuthRoutes --> GrantAccess
    ProdRoutes --> GrantAccess
    OrderRoutes --> GrantAccess

    GrantAccess --> JWT
    GrantAccess --> Roles

    AuthRoutes --> AuthVal
    AuthRoutes --> AuthCtrl
    AuthCtrl --> DBClient
    AuthCtrl --> RedisClient

    ProdRoutes --> ProdValB
    ProdRoutes --> ProdCtrl
    ProdCtrl --> DBClient
    ProdCtrl --> RedisClient

    OrderRoutes --> OrderVal
    OrderRoutes --> OrderCtrl
    OrderCtrl --> DBClient
    OrderCtrl --> RedisClient

    %% Data Stores
    subgraph "Data Stores"
        Mongo["MongoDB"]:::datastore
        Redis["Redis"]:::datastore
    end

    DBClient --> Mongo
    RedisClient --> Redis

    %% Styles
    classDef frontend fill:#e0f7ff,stroke:#333,stroke-width:1px
    classDef backend fill:#e0ffe0,stroke:#333,stroke-width:1px
    classDef datastore fill:#fff3e0,stroke:#333,stroke-width:1px
    classDef infra fill:#f0f0f0,stroke:#333,stroke-width:1px

    %% Click Events
    click App "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/App.js"
    click Index "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/index.js"
    click Signin "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Auth/Signin/index.js"
    click SigninVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Auth/Signin/validations.js"
    click Signup "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Auth/Signup/index.js"
    click SignupVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Auth/Signup/validations.js"
    click ProdList "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Products/index.js"
    click ProdVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Products/validations.js"
    click ProdNew "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Products/New.js"
    click ProdDetailPage "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/ProductDetail/index.js"
    click Basket "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Basket/index.js"
    click Profile "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Profile/index.js"
    click AdminHome "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Admin/AdminHome/index.js"
    click AdminProd "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Admin/AdminProducts/index.js"
    click AdminProdDet "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Admin/AdminProductDetail/index.js"
    click AdminProdDetVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Admin/AdminProductDetail/validations.js"
    click AdminOrders "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/Admin/Orders/index.js"
    click ProtAdmin "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/ProductedRoute/ProductedAdmin.js"
    click ProtProfile "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/pages/ProductedRoute/ProductedProfile.js"
    click Card "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/components/Card/index.js"
    click Navbar "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/components/Navbar/index.js"
    click NavbarCSS "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/components/Navbar/style.module.css"
    click AuthCtx "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/contexts/AuthContext.js"
    click BasketCtx "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/contexts/BasketContext.js"
    click API "https://github.com/seyityahya/ecommerce_react_node/blob/main/frontend/src/api.js"
    click BackendApp "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/app.js"
    click RoutesIndex "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/routes/index.js"
    click AuthRoutes "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/routes/auth.js"
    click ProdRoutes "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/routes/product.js"
    click OrderRoutes "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/routes/order.js"
    click RateLimiter "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/rate-limiter.js"
    click CacheMod "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/cache.js"
    click GrantAccess "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/middlewares/grantAccess.js"
    click AuthCtrl "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/auth/index.js"
    click AuthVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/auth/validations.js"
    click JWT "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/helpers/jwt.js"
    click ProdCtrl "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/product/index.js"
    click ProdValB "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/product/validations.js"
    click OrderCtrl "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/order/index.js"
    click OrderVal "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/controllers/order/validations.js"
    click DBClient "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/clients/db.js"
    click RedisClient "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/clients/redis.js"
    click Roles "https://github.com/seyityahya/ecommerce_react_node/blob/main/backend/src/roles.js"
```
