Skip to content

ertancurr1/fullstack-ecommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Full-Stack eCommerce Application

A modern eCommerce web application built with React (frontend) and PHP with GraphQL (backend). This project demonstrates clean architecture, and OOP principles.

πŸ›οΈ Features

  • Product Catalog - Browse products by category (All, Clothes, Tech)
  • Product Details - View product images, attributes, and descriptions
  • Attribute Selection - Choose size, color, capacity, and other product variants
  • Shopping Cart - Add/remove items, adjust quantities, view totals
  • Quick Shop - Add in-stock products directly from the listing page

πŸ› οΈ Tech Stack

Frontend

  • React 18 with TypeScript
  • Vite (build tool)
  • Apollo Client (GraphQL)
  • React Router DOM
  • SCSS for styling

Backend

  • PHP 8.2 (no frameworks)
  • GraphQL (webonyx/graphql-php)
  • MySQL/MariaDB
  • FastRoute for routing

πŸ“ Project Structure

fullstack-ecommerce/
β”œβ”€β”€ frontend/                 # React application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/            # Page components
β”‚   β”‚   β”œβ”€β”€ context/          # React Context (Cart)
β”‚   β”‚   β”œβ”€β”€ graphql/          # GraphQL queries
β”‚   β”‚   β”œβ”€β”€ types/            # TypeScript interfaces
β”‚   β”‚   └── styles/           # Global styles
β”‚   └── package.json
β”œβ”€β”€ src/                      # PHP backend
β”‚   β”œβ”€β”€ Controller/           # Request handlers
β”‚   β”œβ”€β”€ Database/             # Database connection (Singleton)
β”‚   β”œβ”€β”€ GraphQL/              # Schema and resolvers
β”‚   β”œβ”€β”€ Model/                # Domain models (Abstract classes)
β”‚   └── Repository/           # Data access layer
β”œβ”€β”€ config/                   # Configuration files
β”œβ”€β”€ database/                 # SQL schema and seed data
β”œβ”€β”€ public/                   # Entry point (index.php)
└── vendor/                   # Composer dependencies

πŸš€ Getting Started

Prerequisites

  • PHP 8.0 or higher
  • MySQL/MariaDB
  • Node.js 18+ and npm
  • Composer
  • XAMPP (recommended) or similar local server

Backend Setup

  1. Clone the repository

    git clone https://github.com/ertancurri/fullstack-ecommerce.git
    cd fullstack-ecommerce
  2. Install PHP dependencies

    composer install
  3. Create the database

  4. Run database migrations

    • Import database/schema.sql to create tables
    • Import database/seed.sql to populate sample data
  5. Configure database connection

    • Edit config/database.php with your credentials:
    return [
        'host' => 'localhost',
        'dbname' => 'ecommerce_db',
        'username' => 'root',
        'password' => ''
    ];
  6. Start the backend server

    • Place project in htdocs folder (for XAMPP)
    • Access GraphQL endpoint at: http://localhost/fullstack-ecommerce/public/graphql

Frontend Setup

  1. Navigate to frontend directory

    cd frontend
  2. Install dependencies

    npm install
  3. Start development server

    npm run dev
  4. Open in browser

    • Navigate to http://localhost:5173

πŸ“Š GraphQL API

Queries

# Get all categories
query {
  categories {
    name
  }
}

# Get products (optionally by category)
query {
  products(category: "clothes") {
    id
    name
    brand
    inStock
    gallery
    prices {
      amount
      currency {
        symbol
      }
    }
    attributes {
      id
      name
      type
      items {
        id
        displayValue
        value
      }
    }
  }
}

# Get single product
query {
  product(id: "huarache-x-stussy-le") {
    id
    name
    description
    # ... other fields
  }
}

Mutations

# Create an order
mutation {
  createOrder(products: ["product-id-1", "product-id-2"])
}

πŸ—οΈ Architecture Highlights

OOP Principles

  • Abstract Classes: AbstractProduct and AbstractAttributeSet for polymorphism
  • Factory Pattern: ProductFactory and AttributeFactory for object creation
  • Repository Pattern: Separation of data access from business logic
  • Singleton Pattern: Database connection management

No If/Switch for Types

Product and attribute types are handled through class maps and polymorphism:

private static array $categoryMap = [
    'clothes' => ClothesProduct::class,
    'tech' => TechProduct::class,
];

πŸ“ Sample Products

Product Category Attributes
Nike Air Huarache Le Clothes Size (40-43)
Canada Goose Jacket Clothes Size (S/M/L/XL)
PlayStation 5 Tech Color, Capacity
Xbox Series S Tech Color, Capacity
iMac 2021 Tech Capacity, USB 3, Touch ID
iPhone 12 Pro Tech Capacity, Color
AirPods Pro Tech None
AirTag Tech None

πŸ§ͺ Testing the Application

  1. Browse products on the home page
  2. Filter by category (All, Clothes, Tech)
  3. Click a product to view details
  4. Select required attributes
  5. Add to cart
  6. View cart overlay
  7. Adjust quantities or remove items
  8. Place an order

πŸš€ Deployment

This project is ready for 100% FREE deployment using:

  • Backend: InfinityFree (PHP + MySQL)
  • Frontend: Vercel (React + Vite)

Quick Deploy

  1. Backend: Sign up at infinityfree.com, upload files, create database
  2. Frontend: Push to GitHub, deploy to vercel.com

Documentation

Total Cost: $0/month πŸŽ‰

πŸ“„ License

This project is open source and available for learning purposes.

πŸ‘€ Author

Ertan Curri

About

Full-stack eCommerce application - React + PHP + GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •