Building an e-commerce website with Sanity.io

Table of contents

Motivation

This is a project that leverages Sanity’s headless CMS. The idea is that the store owner (who doesn’t code) is able to control the content of their store, while developers build the front-end according to their needs. What is good about Sanity is that developers do not have to worry about back-end and database integration as that is already handled by Sanity. All devs need to do is provide the schema, and the appropriate fields will be displayed in Sanity studio. Sanity studio is a UI where administrators (store owners) can go and edit the contents. In order to fetch data from Sanity, devs need to use Groq query syntax, which is quite similar to GraphQL.

How to set up the project?

First we need to decide the basic tech stack that we wanna use for the project. Following are what I decided to use:

  1. Next.js 13 (keep in mind that this is still experimental)
  2. TypeScript
  3. TailwindCSS

Then, we will create a guide or boilerplate that we can refer to, should we have similar projects in the future.

Set up Next JS

Set up Sanity.io

Integrate Sanity with NextJS

  1. "sanity/vision": "^3.0.0"
  2. "sanity": "^3.0.0",
  3. "styled-components": "^5.2.0”
  4. "@sanity/eslint-config-studio": "^2.0.1",

Create schemas

Build your UI

Integrate Stripe API

Set up global state management

Deployment