Gel with Replicache on Next.js

Gel with Replicache on Next.js

A minimal todo app that demonstrating how to set up Replicache with Gel and Next.js for real-time, offline-first capabilities.

0

boilerplate.detail.metadata.lastUpdated

il y a 4 mois

R

boilerplate.detail.metadata.author

Renaud

boilerplate.detail.metadata.price

boilerplate.detail.metadata.free

npx boilerapp gel-replicache

Documentation

šŸŽ‰ Next.js + Replicache + Gel Todo App Template

This starter template is crafted to help developers build and deploy applications using Next.js, Replicache, and Gel. It includes essential functionalities for real-time collaboration with offline capabilities and a ready-to-use API setup.

Deploy with Vercel

šŸš€ Features

  • Next.js for building the React frontend.
  • Replicache for enabling real-time collaborative features and offline capabilities.
  • Gel as the backend database to store and sync data efficiently.
  • TypeScript for static type-checking along with modern JavaScript features.
  • Tailwind CSS for utility-first CSS styling.

Data Synchronization and Conflict Resolution

This project implements Replicache's "reset strategy" for data synchronization and conflict resolution.

For more details on the reset strategy and other synchronization approaches with Replicache, visit the synchronization strategies overview on their documentation site.

🧐 What's Inside?

This project follows a structured approach typical of Next.js applications with additional directories specific to Replicache and Gel:

.
ā”œā”€ā”€ app                    # Next.js pages and components
│   ā”œā”€ā”€ api                # API routes
│   │   ā”œā”€ā”€ pull           # Pull endpoint for Replicache
│   │   │   └── route.ts
│   │   └── push           # Push endpoint for Replicache
│   │       └── route.ts
│   ā”œā”€ā”€ components         # React components
│   │   └── TodoList.tsx   # Todo list component
│   ā”œā”€ā”€ favicon.ico        # Favicon
│   ā”œā”€ā”€ globals.css        # Global CSS styles
│   ā”œā”€ā”€ layout.tsx         # Layout component
│   └── page.tsx           # Entry point for the app
ā”œā”€ā”€ dbschema               # gel schema files
│   ā”œā”€ā”€ default.gel        # gel schema definition
│   └── migrations         # Schema migrations
ā”œā”€ā”€ lib                    # Library functions and components
│   ā”œā”€ā”€ gel.ts             # Gel client configuration
│   ā”œā”€ā”€ mutators.ts        # Replicache mutator functions
│   └── types.ts           # TypeScript types for the project
ā”œā”€ā”€ public                 # Static assets like images and fonts
ā”œā”€ā”€ gel.toml               # Gel configuration file
ā”œā”€ā”€ eslint.config.js       # ESLint configuration
ā”œā”€ā”€ next-env.d.ts          # Next.js types
ā”œā”€ā”€ next.config.js         # Next.js configuration
ā”œā”€ā”€ package.json           # NPM dependencies and scripts
ā”œā”€ā”€ pnpm-lock.yaml         # pnpm lockfile
ā”œā”€ā”€ postcss.config.js      # PostCSS configuration
ā”œā”€ā”€ README.md              # Project README
ā”œā”€ā”€ tailwind.config.ts     # Tailwind CSS configuration
└── tsconfig.json          # TypeScript configuration

šŸ Getting Started

1. Clone the repository

git clone https://github.com/geldata/nextjs-replicache-gel-starter.git
cd nextjs-replicache-gel-starter

2. Install dependencies

pnpm install # or npm install or yarn install

3. Set up Gel

Run the Gel project initialization:

npx gel project init

4. Set up environment variables

Create a .env.local file in the root directory and add the following environment variables:

NEXT_PUBLIC_REPLICACHE_LICENSE_KEY = "your-replicache-license-key"

You can get your Replicache license key by running:

npx replicache@latest get-license

Replace the Replicache key in the page.tsx file with your license key.

  const replicache = new Replicache({
    name: userID,
-   licenseKey: TEST_LICENSE_KEY,
+   licenseKey: process.env.NEXT_PUBLIC_REPLICACHE_LICENSE_KEY,
    mutators: { createTodo, updateTodo, deleteTodo },
    puller: pull,
  });

5. Start the development server

pnpm dev # or npm run dev or yarn dev

Open http://localhost:3000 with your browser to see the app.

šŸ”§ Extend and customize

Modify the schema

Adjust the schema in dbschema/default.esdl to meet your application's needs. For example, add new types or extend existing ones with additional properties.

Update data fetching

Modify data fetching logic in the lib directory to enhance or alter how data interacts between the client and the database.

Enhance styles

Update the global CSS styles in app/globals.css or add new styles using Tailwind CSS utility classes.

🌐 Deployment

Deploy your application to production using Vercel:

Deploy with Vercel

šŸ‘€ Learn More

boilerplate.detail.sections.discussion

Comments (0)

FAQ

Frequently Asked Questions

Have a question? We have the answers. If you can't find what you're looking for, feel free to contact us.

Boilerapp is a community platform dedicated to sharing boilerplates, starter kits, and project templates for developers. Our goal is simple: save you time on initial setup so you can code what really matters. Whether you are looking for a simple code base or a complete SaaS project, you will find it here.

Have more questions?

Our team is here to help. Contact us and we will get back to you as soon as possible.