A modern headless commerce storefront built with React.js, Tailwind CSS, and Shopify's Storefront API. This project provides a fast, flexible, and customizable e-commerce solution that decouples the frontend from Shopify's backend.
This project demonstrates how to build a headless Shopify storefront using modern web technologies. By leveraging Shopify's Storefront API, you can create a fully customized shopping experience while still utilizing Shopify's powerful e-commerce backend for product management, inventory, checkout, and order processing.
- π Fast Performance: Built with React.js for optimal performance and user experience
- π¨ Modern UI: Styled with Tailwind CSS for a clean, responsive design
- π Shopify Integration: Seamless integration with Shopify Storefront API
- π± Responsive Design: Mobile-first approach that works on all devices
- π Cart Management: Full shopping cart functionality
- π Product Search: Search and filter products efficiently
- π³ Secure Checkout: Utilizes Shopify's secure checkout process
- β‘ GraphQL: Efficient data fetching with Shopify's GraphQL API
- Node.js (v14 or higher)
- npm or yarn
- A Shopify store with Storefront API access
- Clone the repository:
git clone https://github.com/Lakshya52/shopify-headless-storefront.git
cd shopify-headless-storefront- Install dependencies:
npm install
# or
yarn install- Create a
.envfile in the root directory and add your Shopify credentials:
REACT_APP_SHOPIFY_STORE_DOMAIN=your-store.myshopify.com
REACT_APP_SHOPIFY_STOREFRONT_ACCESS_TOKEN=your-storefront-access-token- Start the development server:
npm start
# or
yarn start- Open http://localhost:3000 to view it in your browser.
npm run build
# or
yarn build- Log in to your Shopify Admin panel
- Navigate to Apps > Develop apps
- Click Create an app
- Configure Storefront API permissions:
unauthenticated_read_product_listingsunauthenticated_read_product_inventoryunauthenticated_read_checkoutsunauthenticated_write_checkouts
- Install the app and copy your Storefront Access Token
The Shopify Storefront API client is configured in src/utils/shopify.js:
import Client from 'shopify-buy';
const client = Client.buildClient({
domain: process.env.REACT_APP_SHOPIFY_STORE_DOMAIN,
storefrontAccessToken: process.env.REACT_APP_SHOPIFY_STOREFRONT_ACCESS_TOKEN
});
export default client;shopify-headless-storefront/
βββ public/
β βββ index.html
β βββ favicon.ico
βββ src/
β βββ components/
β β βββ Cart/
β β β βββ Cart.jsx
β β β βββ CartItem.jsx
β β βββ Product/
β β β βββ ProductCard.jsx
β β β βββ ProductList.jsx
β β β βββ ProductDetail.jsx
β β βββ Header/
β β β βββ Header.jsx
β β βββ Footer/
β β βββ Footer.jsx
β βββ pages/
β β βββ Home.jsx
β β βββ Products.jsx
β β βββ Checkout.jsx
β βββ utils/
β β βββ shopify.js
β β βββ helpers.js
β βββ hooks/
β β βββ useProducts.js
β β βββ useCart.js
β βββ App.js
β βββ index.js
β βββ index.css
βββ .env.example
βββ package.json
βββ tailwind.config.js
βββ README.md
Here's an example of fetching products using Shopify's Storefront API GraphQL:
query GetProducts($first: Int!) {
products(first: $first) {
edges {
node {
id
title
description
handle
images(first: 1) {
edges {
node {
src
altText
}
}
}
variants(first: 1) {
edges {
node {
id
title
price {
amount
currencyCode
}
availableForSale
}
}
}
}
}
}
}import { useEffect, useState } from 'react';
import client from '../utils/shopify';
function useProducts() {
const [products, setProducts] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
client.product.fetchAll().then((products) => {
setProducts(products);
setLoading(false);
});
}, []);
return { products, loading };
}
export default useProducts;Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature-name) - Make your changes
- Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature-name) - Open a Pull Request
- Follow the existing code style
- Write clear commit messages
- Add comments for complex logic
- Test your changes thoroughly
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using React.js, Tailwind CSS, and Shopify Storefront API
For questions or support, please open an issue on GitHub.