# sonykar/react-online-shop architecture

> Architecture diagram of the GitHub repository sonykar/react-online-shop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sonykar/react-online-shop
- Repository: https://github.com/sonykar/react-online-shop

## Overview

The project is a full-stack online shop application with a clear separation between the frontend (a React-based client) and the backend (a PHP-based API). The backend handles data operations and business logic for entities such as products, collections, cart items, and authentication, while the frontend delivers the user interface and communicates with the backend via HTTP (likely with Axios).

##### Main Components
- Frontend (React Application)
- Located in the "web" directory.
- Contains components, containers, state management (Redux store), assets, and the routing logic.
- Implements features like authentication, catalog browsing, shopping cart management, and checkout.
- Backend (PHP API)
- Found under the "php" directory.
- Handles database connectivity (connection.php), entity definitions (product, collection, cartItem), and response endpoints for authentication, cart, products, and collections.
- Includes endpoints for actions such as login, signup, adding/removing products, updating collections, merging cart items, sending emails, and subscribing.
- Database
- Represented by the "doublem.sql" file. This likely contains the schema for tables related to users, products, collections, cart items, etc.
- External Services (if any)
- The PHP scripts for sending emails and handling subscriptions may interact with external services.

##### Relationships and Data Flow
- User Interactions → React Frontend:
- React Frontend → Backend API:
- Endpoints for authentication (login/signup), cart management (add, update, delete cart items), collections, and products.
- Backend API → Database:
- Additional Interactions:
- A connection for sending emails (sendMail.php) and subscribing (subscribe.php) which might involve external systems.

##### Architectural Patterns and Technologies
- MVC or Layered Architecture:
- On the backend, the code structure in the "php" directory indicates a layered approach: entity models, API response endpoints, and potentially a thin controller layer.
- Separation of Concerns:
- Clearly separate the presentation layer (React components and containers), application logic (Redux actions and reducers), and data access (PHP API and database).
- Technology Stack:
- Frontend: React, Redux, Axios.
- Backend: PHP.
- Database: SQL-based (likely MySQL, based on the SQL file).
- Other: Possibly third-party APIs for email and subscription services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level user
    user("User Interface (Browser)"):::external

    %% Frontend Subgraph
    subgraph "Frontend: React Online Shop"
        FE("React App"):::frontend
        redux("Redux Store"):::frontend
        axios("Axios Communication Module"):::frontend
        authLogin("Login Component"):::frontend
        authSignup("Signup Component"):::frontend
        catalog("Catalog/Collection Components"):::frontend
        shopCollections("Shop Collections Container"):::frontend
        productDetails("Product Details Container"):::frontend
        navigation("Navigation Components"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend: PHP API"
        BE("PHP API"):::backend

        subgraph "Authentication Endpoints"
            loginEndpoint("Login Endpoint"):::backend
            signupEndpoint("Signup Endpoint"):::backend
        end

        subgraph "Cart Management Endpoints"
            addCart("Add Cart Item"):::backend
            deleteCart("Delete Cart Item"):::backend
            getCart("Get Cart Items"):::backend
            updateCart("Update Cart Item"):::backend
            mergeCart("Merge Cart Items"):::backend
        end

        subgraph "Collection Management Endpoints"
            addCollection("Add Collection"):::backend
            updateCollection("Update Collection"):::backend
            removeCollection("Remove Collection"):::backend
            retrieveCollections("Retrieve Collections"):::backend
        end

        subgraph "Product Management Endpoints"
            addProduct("Add Product"):::backend
            updateProduct("Update Product"):::backend
            removeProduct("Remove Product"):::backend
            retrieveProduct("Retrieve Product Info"):::backend
            retrieveProducts("Retrieve Products"):::backend
        end

        subgraph "Entity Definitions"
            productEntity("Product Entity"):::backend
            collectionEntity("Collection Entity"):::backend
            cartEntity("Cart Item Entity"):::backend
        end

        emailService("Email Service"):::backend
        subscriptionService("Subscription Service"):::backend
        dbConnection("Database Connection"):::backend
    end

    %% Database Subgraph
    subgraph "Database"
        database("MySQL Database Schema"):::database
    end

    %% Data Flow Connections
    user -->|"loads"| FE
    FE -->|"manages"| redux
    FE -->|"communicates via"| axios
    FE -->|"renders"| authLogin
    FE -->|"renders"| authSignup
    FE -->|"renders"| catalog
    FE -->|"renders"| shopCollections
    FE -->|"renders"| productDetails
    FE -->|"renders"| navigation

    axios -->|"API calls"| BE

    BE -->|"handles"| loginEndpoint
    BE -->|"handles"| signupEndpoint
    BE -->|"handles"| addCart
    BE -->|"handles"| deleteCart
    BE -->|"handles"| getCart
    BE -->|"handles"| updateCart
    BE -->|"handles"| mergeCart
    BE -->|"handles"| addCollection
    BE -->|"handles"| updateCollection
    BE -->|"handles"| removeCollection
    BE -->|"handles"| retrieveCollections
    BE -->|"handles"| addProduct
    BE -->|"handles"| updateProduct
    BE -->|"handles"| removeProduct
    BE -->|"handles"| retrieveProduct
    BE -->|"handles"| retrieveProducts
    BE -->|"invokes"| emailService
    BE -->|"invokes"| subscriptionService
    BE -->|"connects via"| dbConnection

    addProduct -->|"uses"| productEntity
    updateProduct -->|"uses"| productEntity
    removeProduct -->|"uses"| productEntity
    retrieveProduct -->|"uses"| productEntity
    retrieveProducts -->|"uses"| productEntity

    addCollection -->|"uses"| collectionEntity
    updateCollection -->|"uses"| collectionEntity
    removeCollection -->|"uses"| collectionEntity
    retrieveCollections -->|"uses"| collectionEntity

    addCart -->|"uses"| cartEntity
    deleteCart -->|"uses"| cartEntity
    getCart -->|"uses"| cartEntity
    updateCart -->|"uses"| cartEntity
    mergeCart -->|"uses"| cartEntity

    dbConnection -->|"queries"| database

    %% Click Events for Frontend
    click FE "https://github.com/sonykar/react-online-shop/tree/master/web/"
    click redux "https://github.com/sonykar/react-online-shop/tree/master/web/src/store/"
    click axios "https://github.com/sonykar/react-online-shop/blob/master/web/src/axios.js"
    click authLogin "https://github.com/sonykar/react-online-shop/tree/master/web/src/components/Auth/Login/"
    click authSignup "https://github.com/sonykar/react-online-shop/tree/master/web/src/components/Auth/Signup/"
    click catalog "https://github.com/sonykar/react-online-shop/tree/master/web/src/components/Collection/"
    click shopCollections "https://github.com/sonykar/react-online-shop/tree/master/web/src/containers/Shop/Collections/"
    click productDetails "https://github.com/sonykar/react-online-shop/tree/master/web/src/containers/Shop/Product/"
    click navigation "https://github.com/sonykar/react-online-shop/tree/master/web/src/components/Navigation/Navbar/"

    %% Click Events for Backend
    click BE "https://github.com/sonykar/react-online-shop/tree/master/php/"
    click loginEndpoint "https://github.com/sonykar/react-online-shop/blob/master/php/response/auth/login.php"
    click signupEndpoint "https://github.com/sonykar/react-online-shop/blob/master/php/response/auth/signup.php"
    click addCart "https://github.com/sonykar/react-online-shop/blob/master/php/response/cart/addCartItem.php"
    click deleteCart "https://github.com/sonykar/react-online-shop/blob/master/php/response/cart/deleteCartItem.php"
    click getCart "https://github.com/sonykar/react-online-shop/blob/master/php/response/cart/getCartItems.php"
    click updateCart "https://github.com/sonykar/react-online-shop/blob/master/php/response/cart/updateCartItem.php"
    click mergeCart "https://github.com/sonykar/react-online-shop/blob/master/php/response/cart/mergeCartItems.php"
    click addCollection "https://github.com/sonykar/react-online-shop/blob/master/php/response/collections/addCollection.php"
    click updateCollection "https://github.com/sonykar/react-online-shop/blob/master/php/response/collections/updateCollection.php"
    click removeCollection "https://github.com/sonykar/react-online-shop/blob/master/php/response/collections/removeCollection.php"
    click retrieveCollections "https://github.com/sonykar/react-online-shop/blob/master/php/response/collections/collections.php"
    click addProduct "https://github.com/sonykar/react-online-shop/blob/master/php/response/products/addProduct.php"
    click updateProduct "https://github.com/sonykar/react-online-shop/blob/master/php/response/products/updateProduct.php"
    click removeProduct "https://github.com/sonykar/react-online-shop/blob/master/php/response/products/removeProduct.php"
    click retrieveProduct "https://github.com/sonykar/react-online-shop/blob/master/php/response/products/product.php"
    click retrieveProducts "https://github.com/sonykar/react-online-shop/blob/master/php/response/products/products.php"
    click productEntity "https://github.com/sonykar/react-online-shop/blob/master/php/entity/product.php"
    click collectionEntity "https://github.com/sonykar/react-online-shop/blob/master/php/entity/collection.php"
    click cartEntity "https://github.com/sonykar/react-online-shop/blob/master/php/entity/cartItem.php"
    click emailService "https://github.com/sonykar/react-online-shop/blob/master/php/response/sendMail.php"
    click subscriptionService "https://github.com/sonykar/react-online-shop/blob/master/php/response/subscribe.php"
    click dbConnection "https://github.com/sonykar/react-online-shop/blob/master/php/connection.php"

    %% Click Event for Database Schema
    click database "https://github.com/sonykar/react-online-shop/blob/master/doublem.sql"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px,color:#000;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px,color:#000;
    classDef database fill:#fff3cd,stroke:#333,stroke-width:2px,color:#000;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px,color:#000;
```
