A modern, production-ready template built with Next.js 15, React 19, and TypeScript, exclusively managed with Bun for optimal performance and developer experience. This template enforces Bun as the only package manager and comes pre-configured with best practices for styling, code quality, and developer workflow.
Important: This repository is locked to Bun. Using other package managers is not supported.
- β‘ Next.js 15 with App Router
- π¨ Tailwind CSS with shadcn/ui components
- π οΈ TypeScript for type safety
- π§Ή ESLint + Prettier for code quality
- πΆ Husky + lint-staged for pre-commit hooks
- π Conventional Commits
- π Security-focused configuration
- π― Optimized build and development experience
- Bun v1.2.21 or later
-
Clone the repository:
git clone https://github.com/your-username/nextjs-bun-template.git cd nextjs-bun-template -
Install dependencies:
bun install
-
Start the development server:
bun run dev
Open http://localhost:3000 in your browser.
All scripts are run using Bun:
bun run dev- Start development serverbun run build- Create production buildbun run start- Start production serverbun run lint- Run ESLintbun run format- Format code with Prettierbun run prepare- Set up Git hooksNote: Always use
buncommands instead ofnpm,yarn, orpnpm.
- ESLint: Configured with Next.js and React best practices
- Prettier: Automatic code formatting on save
- TypeScript: Strict type checking enabled
-
Create a new branch:
git checkout -b feature/your-feature-name
-
Make your changes and commit them:
git add . git commit -m "feat: add new feature"
-
Push your changes:
git push origin feature/your-feature-name
This project uses Conventional Commits. Example commit messages:
feat: add user authenticationfix: resolve login form validationdocs: update READMErefactor: improve component structure
This project uses Tailwind CSS with the following configurations:
- Tailwind CSS: Utility-first CSS framework
- shadcn/ui: Reusable components built with Radix UI
- CSS Modules: For component-scoped styles
To add a new shadcn/ui component:
bunx shadcn-ui@latest add buttonCreate a .env.local file in the root directory and add the following variables:
# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
# API
NEXT_PUBLIC_API_URL=http://localhost:3000/api- Push your code to a GitHub/GitLab/Bitbucket repository
- Import your project on Vercel
- Set up environment variables in the Vercel dashboard
- Deploy!
-
Build the application:
bun run build
-
Start the production server:
bun run start
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
.
# Root Configuration
βββ .husky/ # Git hooks (pre-commit, commit-msg, pre-push)
β βββ commit-msg # Validates commit messages
β βββ pre-commit # Runs lint-staged before commit
β βββ pre-push # Validates branch naming before push
βββ .vscode/ # VS Code settings
β βββ extensions.json # Recommended extensions
β βββ settings.json # Workspace settings
βββ public/ # Static files served at root (/)
β βββ next.svg # Next.js logo
β βββ vercel.svg # Vercel logo
# Source Code
βββ src/ # Application source code
βββ app/ # App Router (Next.js 13+)
β βββ (auth)/ # Authentication related pages
β βββ (dashboard)/ # Dashboard related pages
β βββ api/ # API routes
β βββ globals.css # Global CSS styles
β βββ layout.tsx # Root layout component
β βββ not-found.tsx # 404 page
β βββ page.tsx # Home page component
β
βββ assets/ # Static assets (images, fonts, etc.)
β βββ images/ # Image assets
β
βββ components/ # Reusable UI components
β βββ ui/ # shadcn/ui components
β βββ shared/ # Shared components
β
βββ contexts/ # React context providers
β βββ index.ts # Context exports
β
βββ hooks/ # Custom React hooks
β βββ index.ts # Hooks exports
β
βββ lib/ # Utility libraries
β βββ utils.ts # Shared utility functions
β
βββ services/ # API and service integrations
β βββ api/ # API client configuration
β
βββ types/ # TypeScript type definitions
β βββ index.ts # Type exports
β
βββ utils/ # Utility functions
βββ index.ts # Utility exports
# Configuration Files
βββ .eslint.config.mjs # ESLint configuration
βββ .prettierrc.js # Prettier configuration
βββ .prettierignore # Files to ignore for Prettier
βββ .validate-branch-namerc.json # Branch naming conventions
βββ bun.lock # Bun lockfile (only lockfile used in this project)
βββ commitlint.config.js # Commit message linting rules
βββ components.json # shadcn/ui configuration
βββ next.config.mjs # Next.js configuration
βββ package.json # Project metadata and dependencies
βββ postcss.config.mjs # PostCSS configuration
βββ tailwind.config.ts # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
Notes:
src/app/layout.tsxis an async server component and usescookies()fromnext/headersto read thelangcookie, sets<html lang={lang}>, applies a light theme (className="light",style={{ colorScheme: "light" }}), and setssuppressHydrationWarning.- Edge runtime is enabled via
export const runtime = "edge".
Run all scripts with Bun:
-
Development
bun run dev
-
Production
bun run buildbun run start
-
Linting & Formatting
bun run lintbun run lint:fixbun run formatbun run format:check
-
Husky
bun run prepare(already set up)
- Prefer Server Components; use Client Components only where necessary (state/effects/browser APIs).
- Keep server-only code out of client boundaries.
- Co-locate components by feature/domain; re-export from
src/components/index.tswhen helpful. - Keep utilities pure in
src/lib/. - Use TypeScript everywhere.
-
Branch naming enforced by
.validate-branch-namerc.json:- Allowed roots:
master | main | dev | uat | ppt | upgrade - Or typed prefixes:
(feature|release|bugfix|hotfix|test|chore|upgrade)/(:<TASK-NO>-)?<short-desc> - Examples:
upgrade/nextjs15,feature/:123-add-profile-card
- Allowed roots:
-
Conventional commits enforced by
commitlint.config.js:- Types:
feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release, workflow, clean, upgrade - Example:
upgrade: bump to Next.js 15.5.2 and React 19
- Types:
-
Linting & Formatting
- ESLint (flat config) +
eslint-plugin-react - Prettier +
prettier-plugin-tailwindcss - Husky + lint-staged to auto-format staged files
- ESLint (flat config) +
- TailwindCSS configured via
tailwind.config.tsandpostcss.config.mjs. - Global styles in
src/app/globals.css. - Use
clsx+class-variance-authorityfor conditional classes and variants. tailwind-mergeto dedupe utility classes.- Icons via
lucide-react. shadcn/uiis configured viacomponents.json. Scaffold withbunx shadcn add <component>and export viasrc/components/index.tsas needed.
- Audit dependencies:
bun audit - Update dependencies:
bun update - Avoid introducing deprecated toolchains that reintroduce transitive vulnerabilities.
- Never commit secrets. Prefer environment variables and secret stores.
- Create
.env.localfor local development (ignored by git). - Server-only variables should NOT be prefixed.
- Client-exposed variables MUST be prefixed with
NEXT_PUBLIC_.
Example .env.local:
# Server-only
DATABASE_URL=...
# Client-exposed
NEXT_PUBLIC_API_BASE_URL=https://api.example.com
- Use Bun in CI/CD for install and build steps.
- Example CI steps:
bun installbun run lintbun run build- (optional)
bun audit
- Edge runtime is enabled in the layout β ensure your platform supports Edge runtime for affected routes.
-
Accidentally used npm/yarn/pnpm:
- Remove non-Bun lockfiles (e.g.,
package-lock.json,yarn.lock,pnpm-lock.yaml). - Re-run
bun install.
- Remove non-Bun lockfiles (e.g.,
-
Hydration warnings:
- Check server/client component boundaries and
suppressHydrationWarninginlayout.tsx.
- Check server/client component boundaries and
-
TypeScript issues:
- Ensure
typescriptand@types/nodematchpackage.jsonversions. - React 19 bundles types; do not add
@types/reactor@types/react-dom.
- Ensure
To get the most out of this repo, use VS Code with these extensions and settings:
Recommended extensions
- ESLint (dbaeumer.vscode-eslint)
- Prettier β Code formatter (esbenp.prettier-vscode)
- Tailwind CSS IntelliSense (bradlc.vscode-tailwindcss)
- EditorConfig for VS Code (EditorConfig.EditorConfig)
- GitLens β Git supercharged (eamodio.gitlens)
- Code Spell Checker (streetsidesoftware.code-spell-checker)
Suggested VS Code settings (User or Workspace)
Notes
-
This project is Bun-only. Use
bun install,bun run <script>, andbunx. -
ESLint: explicit return types are enforced for
.tsutilities but relaxed for React components in.tsxfiles. -
The ESLint config uses flat config (ESLint 9+) and Next.js Core Web Vitals rules via compatibility bridge.
ESLint Highlights
- Next.js Core Web Vitals (
plugin:@next/next/core-web-vitals) - Accessibility (
plugin:jsx-a11y/recommended) - TypeScript strictness
explicit-function-return-type(off in.tsx, on in.ts)strict-boolean-expressions,no-floating-promises,no-misused-promises,consistent-type-imports,no-import-type-side-effects,promise-function-async
- Import hygiene and organization
import/orderwith groups and@/**as internal path groupimport/newline-after-import,import/no-duplicates,import/no-self-import,import/no-cycle,import/first
- React quality & performance
react/jsx-no-bind,react/jsx-fragments,react/jsx-no-useless-fragment,react/self-closing-comp,react/jsx-boolean-value,react/jsx-curly-brace-presence,react/jsx-no-constructed-context-values,react/no-unstable-nested-components
- Security & safety
react/no-danger,react/no-danger-with-children,no-eval,no-implied-eval,no-new-func,no-script-url
- Prettier integration
eslint-config-prettierto disable stylistic conflicts andeslint-plugin-prettierto surface formatting issues in lint
- Add unit tests (e.g., Vitest) and E2E tests (e.g., Playwright).
- Add CI pipelines (GitHub Actions) using Bun for lint, build, test, and audit.
- Provide example components and patterns using
shadcn/ui.
{ // Formatting "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true, "source.organizeImports": true }, // ESLint flat config support "eslint.experimental.useFlatConfig": true, // Tailwind CSS "tailwindCSS.experimental.classRegex": [ // class-variance-authority (cva) ["cva\\(([^)]*)\\)", "[ '`"]([^'"`]*).*?[ '`"]"], ["cx\\(([^)]*)\\)", "[ '`"]([^'"`]*).*?[ '`"]"] ] }