# a-b-h-i-n-a-v-1-9/custom-tshirt-store architecture

> Architecture diagram of the GitHub repository a-b-h-i-n-a-v-1-9/custom-tshirt-store, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store
- Repository: https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store

## Overview

##### Project Type and Purpose
- That this is a full-stack e-commerce application.
- That users can customize t-shirts in a live 3D environment, manage shopping carts, process payments, and view order histories.
- That the backend uses MySQL for data storage (with tables for users, products, cart, orders, payments, and custom designs) and employs JWT for secure authentication.

##### Main Components Identification
- Frontend Component:
- Built with React.
- Incorporates routing (React Router), API service calls (Axios), and Three.js libraries for 3D customization.
- Consists of various pages and components (e.g., Home, Cart, Profile, etc.).
- Backend Component:
- Built with Node.js and Express.
- Organized into routes (e.g., authRoutes, productRoutes, cartRoutes, orderRoutes, paymentRoutes, designRoutes), controllers (with business logic), and models (representing MySQL tables).
- Uses middleware (e.g., authMiddleware) for authentication.
- Handles file uploads for custom design images (using Multer).
- Database:
- MySQL database which stores structured data such as user information, product details, cart contents, orders, payments, and custom design records.
- Supporting Components:
- Environment and configuration management using .env and configuration files in backend/config.
- Uploads directory for storing user-uploaded custom t-shirt designs.
- External libraries: Three.js for the live 3D experience, JWT for security, bcrypt for password hashing, etc.

##### Relationships and Data Flow
- Frontend communicates with the backend via REST API calls using Axios.
- Backend processes requests by routing them to appropriate controller functions and uses models to interact with the MySQL database.
- Interactions between the backend and the uploads folder where custom design images are stored.
- Security flow:
- A note on the JWT authentication flow from client to server and the use of auth middleware to secure API endpoints.

##### Architectural Patterns and Design Principles
- The design largely follows the MVC (Model-View-Controller) pattern on the backend:
- Models represent the data structures (e.g., UserModel, ProductModel).
- Controllers handle the business logic.
- Routes serve as the connection between controllers and client requests.
- The separation of concerns is clearly maintained by isolating frontend and backend functionalities.
- Use of a RESTful API design that separates concerns between client and server.

## Diagram (Mermaid)

```mermaid
graph TD
    A["React Frontend"]:::frontend
    B["Node.js Express Backend"]:::backend

    subgraph "Backend Components"
        C["Configuration (.env & DB Setup)"]:::backend
        D["Middleware (Auth)"]:::backend
        E["API Routes"]:::backend
        F["Controllers"]:::backend
        G["Data Models"]:::backend
    end

    H["MySQL Database"]:::database
    I["Uploads (File Storage)"]:::uploads

    A -->|"APIRequests"| B
    B -->|"Routes"| E
    C -->|"Supports"| E
    C -->|"Supports"| F
    E -->|"Uses"| D
    E -->|"DirectsRequest"| F
    F -->|"CRUD"| G
    F -->|"StoresData"| H
    F -->|"UploadsFiles"| I

    click A "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/tree/main/frontend/"
    click B "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/blob/main/backend/server.js"
    click E "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/tree/main/backend/routes"
    click F "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/tree/main/backend/controllers"
    click G "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/tree/main/backend/models"
    click D "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/blob/main/backend/middleware/authMiddleware.js"
    click C "https://github.com/a-b-h-i-n-a-v-1-9/custom-tshirt-store/tree/main/backend/config"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#F5A623,stroke:#333,stroke-width:2px;
    classDef database fill:#FA8072,stroke:#333,stroke-width:2px;
    classDef uploads fill:#98FB98,stroke:#333,stroke-width:2px;
```
