An open API service indexing awesome lists of open source software.

https://github.com/10up/sanity-ignite


https://github.com/10up/sanity-ignite

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# Ignite for Sanity

A Sanity starter kit providing modern, clean designs for your content-driven websites. Built with Next.js and Tailwind CSS.

Out of the box it includes schema for pages, posts, categories, authors, and global settings. Pages are structured with a page builder that lets you compose a number of components: hero, CTA, post list, subscribe, content, etc.

## Key Dependencies

- Next.js
- Sanity
- Tailwind CSS
- Shadcn/ui
- React
- TypeScript
- Vitest

## Getting Started

### 1. Initialize template with Sanity CLI

```bash
npm create sanity@latest -- --template 10up/sanity-ignite
```

This will install your NPM dependencies and populate the `.env.local` file.

### 2. Start the Development Server

```bash
npm run dev
```

### 3. Open the Project and sign in to Sanity

Open the next app locally at [http://localhost:3000](http://localhost:3000) and the Sanity Studio at [http://localhost:3000/studio](http://localhost:3000/studio).

## Folder Structure

```

πŸ”₯ sanity-ignite
β”œβ”€β”€ πŸ“‚ src # Main source code directory
β”‚ β”œβ”€β”€ πŸ“‚ app # Next.js application
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ (frontend) # Frontend routes
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ studio # Sanity Studio route
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ api # API routes (Next.js route handlers)
β”‚ β”œβ”€β”€ πŸ“‚ components # UI components and icons
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ icons # Custom SVG/icon components
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ ui # Presentational UI components with no side effects
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ modules # Components that receive Sanity data and may call server actions
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ sections # Page builder sections
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ templates # Page templates
β”‚ β”œβ”€β”€ πŸ“‚ hooks # Custom react hooks
β”‚ β”œβ”€β”€ πŸ“‚ actions # Server-side actions
β”‚ β”œβ”€β”€ πŸ“‚ env # Environment specific functions and `.env` validation
β”‚ β”œβ”€β”€ πŸ“‚ lib # Shared libraries and integrations
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ sanity # Sanity integration
β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ“‚ queries # Sanity GraphQL/GROQ queries
β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ“‚ client # Sanity client configuration
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ (example) # Every integration (e.g., CRM, Newsletter SDKs) gets its own subfolder
β”‚ β”œβ”€β”€ πŸ“‚ studio # Sanity Studio configuration
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ schemas # Schema definitions for Sanity content models
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ components # Custom Sanity components
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ plugins # Custom Sanity plugins
β”‚ β”‚ β”œβ”€β”€ πŸ“‚ structure # Custom Sanity structure definitions
β”‚ β”œβ”€β”€ πŸ“‚ utils # Utility functions and TypeScript types
```

### πŸ“‚ `src/components` - UI Component Structure

- **`ui/` - Presentational UI Components**

- This folder contains **pure UI components** that have **no side effects**.
- Components here can be used **both in client and server components**.
- **🚫 Do not use:** Sanity types, data fetching, or global state within these components.

- **`modules/` - Components that Accept Sanity Data**

- These components receive **data from Sanity queries** and might contain logic to manipulate or render that data.
- No direct data fetching should happen inside these components.
- They can, however, call **server actions** that fetch or modify data.

- **`sections/` - Page Builder Sections**

- Large, structured UI sections that form reusable parts of pages.
- Used to assemble pages dynamically in a CMS-driven way.

- **`templates/` - Page Templates**

- Higher-level layout structures that can be shared between multiple routes.

- **`icons/` - Custom SVG/Icon Components**
- Collection of SVG-based components used throughout the UI.
- Icons should be stored as SVG files and imported as React components. Icons should NOT be added as React components directly.

---

### πŸ“‚ `src/lib` - Shared Libraries & Integrations

- **`sanity/` - Sanity Integration**

- **`queries/`** β†’ Contains all Sanity **GROQ queries** used in the frontend.
- **`client/`** β†’ Configures the Sanity client and SanityLive client used for API calls

- **`(example)/` - External Service Integrations**
- Each external service (e.g., CRM, Newsletter SDKs) should have its own **subfolder** under `lib/`.
- Example: `/lib/newsletter/` for newsletter subscriptions, `/lib/crm/` for CRM integrations.

---

### πŸ“‚ `src/studio` - Sanity Studio Configuration

This folder contains everything needed to **configure and customize Sanity Studio**, the headless content operating system used in this project.

- **`schemas/` - Content Models**

- Defines the schema of content in Sanity (e.g., `Post`, `Author`, `Category`).

- **`components/` - Custom Sanity Components**

- Custom React components that enhance the Sanity Studio interface.
- These might include **custom inputs, preview components, or UI overrides**.

- **`plugins/` - Sanity Plugins**

- Third-party or custom plugins that **extend Sanity’s functionality**.
- Examples: AI-powered content suggestions, media management, or real-time collaboration tools.

- **`structure/` - Custom Studio Structure**
- Defines how content is **organized** inside the Sanity Studio UI.
- Custom menus, navigation rules, and UI layouts are configured here.

## 🌍 Environment Variables (`.env` Files)

The project uses **environment variables** to store **configuration values** that differ between environments (e.g., local development, testing, and production). These variables are stored in `.env` files, which Next.js loads automatically. Read more on the Nex.js Docs [here](https://nextjs.org/docs/app/building-your-application/configuring/environment-variables).

### πŸ“‚ Available `.env` Files

| File | Purpose |
| ------------------ | ------------------------------------------------------------------------------------------------- |
| **`.env.local`** | Stores **local** environment variables. This file is **git-ignored** and should not be committed. |
| **`.env.example`** | A **template** for environment variables. It lists required variables without actual values. |
| **`.env.test`** | Contains environment variables used specifically for running **unit tests**. |

---

## πŸ› οΈ How to Use `.env` Files

### 1️⃣ **Setting Up Your Local Environment**

Before running the project locally, copy `.env.example` and create a `.env.local` file:

```sh
cp .env.example .env.local
```

Then, **fill in the required values** based on your local setup.

### 2️⃣ **Validation of Environment Variables**

This project uses **valibot** for schema validation of environment variables.
To add a new environment variable:

1. Update the `.env.example` file
2. Add the new variable to the `envSchema` object in `src/env/serverEnv.ts` or `src/env/clientEnv.ts`

### 3️⃣ **Accessing Environment Variables in Code**

All environment variables should be accessed using the `serverEnv` or `clientEnv` objects.

Example:

```ts
const projectId = serverEnv.NEXT_PUBLIC_SANITY_PROJECT_ID;
```

πŸ’‘ **Public vs. Private Variables:**

- Variables **prefixed with `NEXT_PUBLIC_`** are **exposed to the browser** and can be used in client-side code. Validation of these variables is done in `src/env/clientEnv.ts`.
- Variables **without `NEXT_PUBLIC_`** remain **server-only**. Validation of these variables is done in `src/env/serverEnv.ts`.

### 4️⃣ **Testing with `.env.test`**

When running unit or integration tests, the `.env.test` file is loaded automatically.

---

### πŸ”’ Best Practices

βœ”οΈ **Never commit `.env.local`!** It's ignored by `.gitignore`.
βœ”οΈ **Use `.env.example`** to document required variables without exposing secrets.
βœ”οΈ **Keep private keys and API secrets out of `NEXT_PUBLIC_` variables.**

---

## Linter and Code Formatting

This project uses ESLint and Prettier for code linting and formatting. Run the following commands to lint and format your code:

```bash
npm run lint # Lint the code
```

### Custom ESLint Configurations

This project has custom ESLint rules configured for the following scenarios:

- Sanity Studio
- `next-sanity` package cannot be imported into the studio. This is a frontend only package.
- Next.js Frontend
- Assets from the sanity studio or from studio related packages cannot be imported into the frontend. They can only be used in the `sanity.config.ts` file or in the `src/studio` folder. This is to prevent the frontend from loading unoptimized studio assets.

### Analyze Bundle Sizes

Sanity Ignite uses the `@next/bundle-analyzer` plugin to analyze the bundle sizes of the project. To run the bundle analyzer, run the following command:

```bash
ANALYZE=true npm run next:build
```

## Learn More

- [Next.js Documentation](https://nextjs.org/docs)
- [Sanity Documentation](https://www.sanity.io/docs)
- [Tailwind CSS Documentation](https://tailwindcss.com/docs)
- [Shadcn/ui Documentation](https://ui.shadcn.com)