/next-boilerplate

The perfect boilerplate for your next.js projects

Primary LanguageTypeScriptMIT LicenseMIT

Next.js Enterprise Boilerplate

Project intro image

GitHub license

Welcome to the Next.js Boilerplate, an open-source template for all your nextjs projects! It's loaded with features that'll help you build a high-performance, maintainable, and enjoyable app. We've done all the heavy lifting for you, so sit back, relax, and get ready to conquer the world with your incredible app! ๐ŸŒ Inspired by Next enterprise

You can test the demo here.

email: test@mail.com
password: Azerty123!

๐Ÿ“š Features

With this template, you get all the awesomeness you need:

  • ๐ŸŽ๏ธ Next.js - Fast by default, with config optimized for performance
  • ๐Ÿ’… Tailwind CSS - A utility-first CSS framework for rapid UI development
  • โœจ ESlint and Prettier - For clean, consistent, and error-free code
  • ๐Ÿซ™ Dev Container - For a consistent development environment
  • ๐Ÿณ Docker - For easy deployment
  • ๐Ÿ˜ PostgreSQL - A powerful, open-source relational database system
  • ๐Ÿ—ƒ๏ธ Prisma - Next-generation ORM for Node.js and TypeScript
  • โšก Redis - An in-memory data structure store, used as a database, cache, and message broker
  • ๐Ÿ”‘ Auth.js - A simple, lightweight authentication library
  • ๐Ÿ› ๏ธ Extremely strict TypeScript - With ts-reset library for ultimate type safety
  • ๐Ÿ“Š Bundle analyzer plugin - Keep an eye on your bundle size
  • ๐Ÿงช Jest and React Testing Library - For rock-solid unit and integration tests
  • ๐Ÿ“ Conventional commits git hook - Keep your commit history neat and tidy
  • ๐ŸŽฏ Absolute imports - No more spaghetti imports
  • โš•๏ธ Health checks - Kubernetes-compatible for robust deployments
  • ๐Ÿงฉ Radix UI - Headless UI components for endless customization
  • ๐Ÿ’Ž CVA - Create a consistent, reusable, and atomic design system
  • ๐Ÿค– Renovate BOT - Auto-updating dependencies, so you can focus on coding
  • ๐Ÿฉน Patch-package - Fix external dependencies without losing your mind
  • ๐Ÿš€ GitHub Actions - Pre-configured actions for smooth workflows, including Bundle Size and performance stats
  • ๐Ÿ’ฏ Perfect Lighthouse score - Because performance matters
  • ๐Ÿšข Semantic Release - for automatic changelog
  • ๐Ÿ’ป T3 Env - Manage your environment variables with ease
  • ๐Ÿ“ฆ Unused dependencies checker - Keep your dependencies clean
  • โœ‰๏ธ Nodemailer - Send emails with ease from any smtp server
  • ๐Ÿ”— Trpc - Move Fast and Break Nothing. End-to-end typesafe APIs made easy.
  • ๐ŸŽจ Shadcn - Beautifully designed components

Table of Contents

๐ŸŽฏ Getting Started

If you want to use the dev container, please follow the container stack instructions.

To get started with this boilerplate, follow these steps:

  1. Fork & clone repository:
## Don't forget to โญ star and fork it first :)
git clone https://github.com/rharkor/next-boilerplate
  1. Create a .env file and add the following environment variables:
cp .env.example .env
  1. Initialize the project:
npm run init
  1. Install the dependencies:
npm install
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 with your browser to see the result.

๐Ÿš€ Deployment

Easily deploy your Next.js app with Vercel by clicking the button below:

Deploy with Vercel

๐Ÿ“ƒ Scripts Overview

The following scripts are available in the package.json:

  • init: Initializes the project by setting up your information
  • dev: Starts the development server with colorized output
  • build: Builds the app for production
  • start: Starts the production server
  • lint: Lints the code using ESLint
  • lint:fix: Automatically fixes linting errors
  • prettier: Checks the code for proper formatting
  • prettier:fix: Automatically fixes formatting issues
  • analyze: Analyzes the bundle sizes for Client, Server and Edge environments
  • test: Runs unit and integration tests
  • e2e:headless: Runs end-to-end tests in headless mode
  • e2e:ui: Runs end-to-end tests with UI
  • format: Formats the code with Prettier
  • postinstall: Applies patches to external dependencies
  • preinstall: Ensures the project is installed with Npm
  • seed: Seeds the database with test data
  • depcheck: Checks for unused dependencies

๐Ÿณ Container Stack

The boilerplate comes with a pre-configured Docker container stack and a dev container. The stack includes the following services:

  • Next.js - A React framework for building fast and scalable web applications
  • PostgreSQL - A powerful, open-source relational database system
  • Redis - An in-memory data structure store, used as a database, cache, and message broker

To start the development container in vsCode see. You can also use devPod to easily start the development container.

Open in DevPod!

Ports:

  • Next.js: 3000
  • PostgreSQL: 5432
  • Redis: 6379
  • Desktop (password: vscode): 6080

๐Ÿงช Testing

This boilerplate comes with various testing setups to ensure your application's reliability and robustness.

Running Tests

  • Unit and integration tests: Run Jest tests using npm run test

image

๐ŸŽจ Styling and Design System

This boilerplate uses Tailwind CSS for styling and CVA for creating a powerful, easy-to-use design system. If you want to learn more about the setup, check out this fantastic video by Vercel:

CVA - A New Approach to Variants

While CSS-in-TS libraries such as Stitches and Vanilla Extract are great for building type-safe UI components, they might not be the perfect fit for everyone. You may prefer more control over your stylesheets, need to use a framework like Tailwind CSS, or simply enjoy writing your own CSS.

Creating variants using traditional CSS can be a tedious task, requiring you to manually match classes to props and add types. CVA is here to take that pain away, allowing you to focus on the enjoyable aspects of UI development. By providing an easy and type-safe way to create variants, CVA simplifies the process and helps you create powerful design systems without compromising on the flexibility and control of CSS.

๐Ÿ’พ State Management

While this boilerplate doesn't include a specific state management library, we believe it's essential for you to choose the one that best suits your project's needs. Here are some libraries we recommend for state management:

Tanstack query

Tanstack query is a powerful, fast, and lightweight data fetching and caching library. It provides a concise, declarative API for fetching data that integrates seamlessly with React.

๐Ÿ’ป Environment Variables handling

T3 Env is a library that provides environmental variables checking at build time, type validation and transforming. It ensures that your application is using the correct environment variables and their values are of the expected type. Youโ€™ll never again struggle with runtime errors caused by incorrect environment variable usage.

Config file is located at env.mjs. Simply set your client and server variables and import env from any file in your project.

export const env = createEnv({
  server: {
    // Server variables
    SECRET_KEY: z.string(),
  },
  client: {
    // Client variables
    API_URL: z.string().url(),
  },
  runtimeEnv: {
    // Assign runtime variables
    SECRET_KEY: process.env.SECRET_KEY,
    API_URL: process.env.NEXT_PUBLIC_API_URL,
  },
})

If the required environment variables are not set, you'll get an error message:

  โŒ Invalid environment variables: { SECRET_KEY: [ 'Required' ] }

๐Ÿค Contribution

Contributions are always welcome! To contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch with a descriptive name.
  3. Make your changes, and commit them using the Conventional Commits format.
  4. Push your changes to the forked repository.
  5. Create a pull request, and we'll review your changes.

Support

For support, contact me on discord at ryzer or by email at louis@huort.com.

๐Ÿ“œ License

This project is licensed under the MIT License. For more information, see the LICENSE file.

Contributors

Bart Stefanski
Bart Stefanski

๐Ÿ’ป
Jakub Jabล‚oล„ski
Jakub Jabล‚oล„ski

๐Ÿš‡
Louis Huort
Louis Huort

๐Ÿ’ป