Live demo: Next.js Boilerplate
Developer experience first, extremely flexible code structure and only keep what you need:
- β‘ Next.js with App Router support
- π₯ Type checking TypeScript
- π Integrate with Tailwind CSS
- β Strict Mode for TypeScript and React 18
- π Authentication with Clerk: Sign up, Sign in, Sign out, Forgot password, Reset password, and more.
- π€ Passwordless Authentication with Magic Links, Multi-Factor Auth (MFA), Social Auth (Google, Facebook, Twitter, GitHub, Apple, and more), Passwordless login with Passkeys, User Impersonation
- β¨οΈ Form handling with React Hook Form
- π΄ Validation library with Zod
- π Linter with ESLint (default Next.js, Next.js Core Web Vitals, Tailwind CSS and Antfu configuration)
- π Code Formatter with Prettier
- π¦ Husky for Git Hooks
- π« Lint-staged for running linters on Git staged files
- π Lint git commit with Commitlint
- π Write standard compliant commit messages with Commitizen
- π Storybook for UI development
- π‘ Absolute Imports using
@prefix - π VSCode configuration: Debug, Settings, Tasks and Extensions
- π€ SEO metadata, JSON-LD and Open Graph tags
- πΊοΈ Sitemap.xml and robots.txt
- βοΈ Bundler Analyzer
- π Include a FREE minimalist theme
- π― Maximize lighthouse score
Built-in feature from Next.js:
- β Minify HTML & CSS
- π¨ Live reload
- β Cache busting
- Nothing is hidden from you, allowing you to make any necessary adjustments to suit your requirements and preferences.
- Dependencies are regularly updated on a monthly basis
- Start for free without upfront costs
- Easy to customize
- Minimal code
- Unstyled template
- SEO-friendly
- π Production-ready
- Node.js 20+ and pnpm
Run the following command on your local environment:
npm run devOpen http://localhost:3000 with your favorite browser to see your project.
To get started, you will need to create a Clerk account at Clerk.com and create a new application in the Clerk Dashboard. Once you have done that, copy the NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY values and add them to the .env.local file (not tracked by Git):
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_pub_key
CLERK_SECRET_KEY=your_clerk_secret_keyNow you have a fully functional authentication system with Next.js, including features such as sign up, sign in, sign out, forgot password, reset password, update profile, update password, update email, delete account, and more.
.
βββ README.md # README file
βββ .github # GitHub folder
βββ .husky # Husky configuration
βββ .storybook # Storybook folder
βββ .vscode # VSCode configuration
βββ public # Public assets folder
βββ src
β βββ app # Next JS App (App Router)
β βββ core # Contains core logic and Clean Architecture layers.
β β βββ application # Application-level logic and business rules.
β β β βββ repositories # Interfaces for repositories, defining how data should be handled (e.g., CRUD operations).
β β β βββ services # Business services that interact with repositories and execute application logic.
β β β βββ use-cases # Specific use cases for the application, implementing business logic using services and repositories.
β β βββ entities # Domain entities and business logic.
β β β βββ models # Domain models representing the core data structures (e.g., User, Product).
β β β βββ dto # Data Transfer Objects used to define the shape of data sent or received.
β β βββ infrastructure # Handles communication with external systems (e.g., APIs).
β β β βββ services # Concrete service implementations.
β β β βββ repositories # API and database communication implementations
β βββ components # React components ( maybe use atomic design )
β βββ styles # Styles folder
β βββ utils # Utilities folder
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configurationpublic/apple-touch-icon.png,public/favicon.ico,public/favicon-16x16.pngandpublic/favicon-32x32.png: your website faviconnext.config.ts: Next.js configuration.env: default environment variables
You have full access to the source code for further customization. The provided code is just an example to help you start your project. The sky's the limit π.
The project follows the Conventional Commits specification, meaning all commit messages must be formatted accordingly. To help you write commit messages, the project uses Commitizen, an interactive CLI that guides you through the commit process. To use it, run the following command:
npm run commitOne of the benefits of using Conventional Commits is the ability to automatically generate a CHANGELOG file. It also allows us to automatically determine the next version number based on the types of commits that are included in a release.
During the build process, database migrations are automatically executed, so there's no need to run them manually.
Then, you can generate a production build with:
$ npm run buildIt generates an optimized production build of the boilerplate. To test the generated build, run:
$ npm run startYou also need to defined the environment variables CLERK_SECRET_KEY using your own key.
This command starts a local server using the production build. You can now open http://localhost:3000 in your preferred browser to see the result.
Next.js Boilerplate includes a built-in bundle analyzer. It can be used to analyze the size of your JavaScript bundles. To begin, run the following command:
npm run build-statsIf you are VSCode user, you can have a better integration with VSCode by installing the suggested extension in .vscode/extension.json. The starter code comes up with Settings for a seamless integration with VSCode. The Debug configuration is also provided for frontend and backend debugging experience.
With the plugins installed in your VSCode, ESLint and Prettier can automatically fix the code and display errors. The same applies to testing: you can install the VSCode Vitest extension to automatically run your tests, and it also shows the code coverage in context.
Pro tips: if you need a project wide-type checking with TypeScript, you can run a build with Cmd + Shift + B on Mac.
Everyone is welcome to contribute to this project. Feel free to open an issue if you have any questions or find a bug. Totally open to suggestions and improvements.
Licensed under the MIT License, Copyright Β© 2024
Made with β₯ by LiamPham
Looking for a custom boilerplate to kick off your project? I'd be glad to discuss how I can help you build one.
