# trrajputdev/shopcrm architecture

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

- Interactive diagram: https://gitdiagram.com/trrajputdev/shopcrm
- Repository: https://github.com/trrajputdev/shopcrm

## Overview

##### Project Type and Purpose
- This is a full-stack retail CRM system (“ShopCRM”) with a modern React/TypeScript frontend (built with Vite and Tailwind CSS) and a PHP/Apache backend (served via XAMPP) connecting to a MySQL database.
- The frontend provides customer management UIs (list, details, add/edit forms), landing/marketing pages, and reusable UI components. The backend exposes CRUD operations through a single PHP “shop-api.php” endpoint.

##### High-Level Components
a. Frontend (React + Vite + TypeScript + Tailwind)
- Pages: CustomerManagement, Landing, Blog, Documentation, etc.
- Layout Components: MainLayout (Header + Sidebar), Dialogs, Loading/Error UI.
- Domain Components: CustomerList, CustomerDetails, AddCustomerForm, ShopCalculators.
- Shared UI Library: button, input, table, dialog, tabs, etc.
- Hooks & Utilities: useCustomerAPI (CRUD + error handling), lib/utils.ts, formatters, custom hooks.
b. Backend (PHP API on Apache/XAMPP)
- shop-api.php (single entry point, query-param driven actions: get_customers, create_customer, update_customer, delete_customer)
- Error handling and JSON responses.
c. Database (MySQL on XAMPP)
- customers table (id, name, email, phone, balance, timestamps)

##### Relationships & Data Flow
- Browser (React app) ⇄ HTTP/HTTPS ⇄ Apache/PHP API
- GET /shop-api.php?action=get_customers → returns JSON array
- POST /shop-api.php?action=create_customer, update_customer, delete_customer
- PHP API ⇄ (SQL) ⇄ MySQL
- CRUD operations on the `customers` table
- React’s useCustomerAPI hook centralizes all HTTP calls, state (customers, loading, error), and error handling.

##### Architectural Patterns & Design Principles
- Layered architecture: Presentation (Components & Pages) → API layer (custom hook) → Service layer (PHP backend) → Persistence (MySQL).
- Component-based design: each UI piece has single responsibility and is reusable.
- Hooks for cross-cutting concerns: state + side-effects (data fetching, error handling) encapsulated in useCustomerAPI.
- TypeScript for static typing: interfaces (Customer, NewCustomer) ensure consistency.
- Centralized styling & theming via Tailwind and shared UI library.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "React/TypeScript Frontend (Vite + Tailwind)"
        direction TB
        subgraph "Pages"
            direction TB
            CM["CustomerManagement"]:::frontend
            LND["Landing"]:::frontend
            BLG["Blog / BlogPost"]:::frontend
            DOC["Documentation"]:::frontend
            TOS["TermsOfService"]:::frontend
        end
        subgraph "Layout Components"
            direction TB
            ML["MainLayout"]:::frontend
            HDR["Header"]:::frontend
            SB["Sidebar"]:::frontend
            ST["ScrollToTop"]:::frontend
        end
        subgraph "Domain Components"
            direction TB
            CL["CustomerList"]:::frontend
            CD["CustomerDetails"]:::frontend
            ACF["AddCustomerForm"]:::frontend
            SC["ShopCalculators"]:::frontend
        end
        subgraph "Shared UI Library"
            direction TB
            BTN["Button"]:::frontend
            INP["Input"]:::frontend
            TBL["Table"]:::frontend
            DLG["Dialog"]:::frontend
            TBS["Tabs"]:::frontend
        end
        HC["useCustomerAPI Hook"]:::frontend
    end

    API["PHP API (shop-api.php) on Apache/XAMPP"]:::api
    DB["MySQL Database\n(customers table)"]:::db

    CM -->|uses| HC
    LND -->|uses| HC
    BLG -->|uses| HC
    DOC -->|uses| HC
    TOS -->|uses| HC
    ML -->|wraps pages| CM
    ML -->|wraps pages| LND
    ML -->|wraps pages| BLG
    ML -->|wraps pages| DOC
    ML -->|wraps pages| TOS
    HDR -->|part of layout| ML
    SB -->|part of layout| ML
    ST -->|routing helper| ML
    CL -->|uses| HC
    CD -->|uses| HC
    ACF -->|uses| HC
    SC -->|uses| HC
    BTN -->|used by| CM
    INP -->|used by| ACF
    TBL -->|used by| CL
    DLG -->|used by| HC
    TBS -->|used by| CD

    HC -->|HTTP GET/POST /shop-api.php| API
    API -->|CRUD SQL queries| DB

    click CM "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/Pages/CustomerManagement.tsx"
    click LND "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/Pages/Landing.tsx"
    click BLG "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/Pages/Blog.tsx"
    click DOC "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/Pages/Documentation.tsx"
    click TOS "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/Pages/TermsOfService.tsx"
    click ML "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/layout/MainLayout.tsx"
    click HDR "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/layout/Header.tsx"
    click SB "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/layout/Sidebar.tsx"
    click ST "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/layout/ScrollToTop.tsx"
    click CL "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/customers/CustomerList.tsx"
    click CD "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/customers/CustomerDetails.tsx"
    click ACF "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/customers/AddCustomerForm.tsx"
    click SC "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/customers/ShopCalculators.tsx"
    click BTN "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/ui/button.tsx"
    click INP "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/ui/input.tsx"
    click TBL "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/ui/table.tsx"
    click DLG "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/ui/dialog.tsx"
    click TBS "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/components/ui/tabs.tsx"
    click HC "https://github.com/trrajputdev/shopcrm/blob/master/Y/src/hooks/useCustomerAPI.ts"

    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef api fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
    classDef db fill:#fff3e0,stroke:#ef6c00,color:#e65100
```
