Skip to content

Repository files navigation

Next.js + Bun Template

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.

πŸš€ Features

  • ⚑ 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

🏁 Getting Started

Prerequisites

  • Bun v1.2.21 or later

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/nextjs-bun-template.git
    cd nextjs-bun-template
  2. Install dependencies:

    bun install
  3. Start the development server:

    bun run dev

    Open http://localhost:3000 in your browser.

Available Scripts

All scripts are run using Bun:

  • bun run dev - Start development server
  • bun run build - Create production build
  • bun run start - Start production server
  • bun run lint - Run ESLint
  • bun run format - Format code with Prettier
  • bun run prepare - Set up Git hooks

    Note: Always use bun commands instead of npm, yarn, or pnpm.

πŸ›  Development

Code Style

  • ESLint: Configured with Next.js and React best practices
  • Prettier: Automatic code formatting on save
  • TypeScript: Strict type checking enabled

Git Workflow

  1. Create a new branch:

    git checkout -b feature/your-feature-name
  2. Make your changes and commit them:

    git add .
    git commit -m "feat: add new feature"
  3. Push your changes:

    git push origin feature/your-feature-name

Commit Message Format

This project uses Conventional Commits. Example commit messages:

  • feat: add user authentication
  • fix: resolve login form validation
  • docs: update README
  • refactor: improve component structure

🎨 Styling

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

Adding New Components

To add a new shadcn/ui component:

bunx shadcn-ui@latest add button

πŸ” Environment Variables

Create 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

πŸš€ Deployment

Vercel (Recommended)

  1. Push your code to a GitHub/GitLab/Bitbucket repository
  2. Import your project on Vercel
  3. Set up environment variables in the Vercel dashboard
  4. Deploy!

Self-Hosted

  1. Build the application:

    bun run build
  2. Start the production server:

    bun run start

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ—‚ Project Structure

.
# 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.tsx is an async server component and uses cookies() from next/headers to read the lang cookie, sets <html lang={lang}>, applies a light theme (className="light", style={{ colorScheme: "light" }}), and sets suppressHydrationWarning.
  • Edge runtime is enabled via export const runtime = "edge".

Scripts

Run all scripts with Bun:

  • Development

    • bun run dev
  • Production

    • bun run build
    • bun run start
  • Linting & Formatting

    • bun run lint
    • bun run lint:fix
    • bun run format
    • bun run format:check
  • Husky

    • bun run prepare (already set up)

Development Practices

  • 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.ts when helpful.
  • Keep utilities pure in src/lib/.
  • Use TypeScript everywhere.

Code Quality and Conventions

  • 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
  • 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
  • Linting & Formatting

    • ESLint (flat config) + eslint-plugin-react
    • Prettier + prettier-plugin-tailwindcss
    • Husky + lint-staged to auto-format staged files

Styling

  • TailwindCSS configured via tailwind.config.ts and postcss.config.mjs.
  • Global styles in src/app/globals.css.
  • Use clsx + class-variance-authority for conditional classes and variants.
  • tailwind-merge to dedupe utility classes.
  • Icons via lucide-react.
  • shadcn/ui is configured via components.json. Scaffold with bunx shadcn add <component> and export via src/components/index.ts as needed.

Security

  • 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.

Environment Variables

  • Create .env.local for 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

Deployment Notes

  • Use Bun in CI/CD for install and build steps.
  • Example CI steps:
    • bun install
    • bun run lint
    • bun run build
    • (optional) bun audit
  • Edge runtime is enabled in the layout β€” ensure your platform supports Edge runtime for affected routes.

Troubleshooting

  • Accidentally used npm/yarn/pnpm:

    • Remove non-Bun lockfiles (e.g., package-lock.json, yarn.lock, pnpm-lock.yaml).
    • Re-run bun install.
  • Hydration warnings:

    • Check server/client component boundaries and suppressHydrationWarning in layout.tsx.
  • TypeScript issues:

    • Ensure typescript and @types/node match package.json versions.
    • React 19 bundles types; do not add @types/react or @types/react-dom.

Editor Setup (VS Code)

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)

{
  // 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\\(([^)]*)\\)", "[ '`"]([^'"`]*).*?[ '`"]"]
  ]
}

Notes

  • This project is Bun-only. Use bun install, bun run <script>, and bunx.

  • ESLint: explicit return types are enforced for .ts utilities but relaxed for React components in .tsx files.

  • 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/order with groups and @/** as internal path group
    • import/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-prettier to disable stylistic conflicts and eslint-plugin-prettier to surface formatting issues in lint

Roadmap

  • 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages