Skip to content

πŸš€ Nuxt 4 Boilerplate for Starter β€” A clean, modern, production-ready Nuxt 4 setup with i18n, UI presets, API layer & best practices to kickstart your next project.✨

Notifications You must be signed in to change notification settings

sonht113/nuxt4-boilerplate-for-starter

Repository files navigation

🍳 Nuxt Boilerplate for Starter

Banner

A modern, full-stack boilerplate for building web applications with Nuxt 4, Prisma, TypeScript, and PostgreSQL. This project includes authentication, CRUD operations, i18n support, and a beautiful UI ready for production.

Created by nuicoder

✨ Features

  • πŸ” Authentication System - Complete auth flow with JWT tokens (access & refresh)
  • πŸ“ Recipe Management - Full CRUD operations for recipes
  • 🌐 Internationalization (i18n) - Support for multiple languages (EN, VI)
  • 🎨 Modern UI - Beautiful, responsive design with custom components
  • πŸ—„οΈ Database - Prisma ORM with PostgreSQL
  • πŸ”„ API Routes - RESTful API built with Nuxt server routes
  • 🧩 Reusable Components - Modular and maintainable component architecture
  • 🎯 Type Safety - Full TypeScript support
  • πŸ“± Responsive Design - Mobile-first approach
  • πŸš€ SEO Optimized - Meta tags, OG images, and sitemap
  • πŸ”’ Middleware Protection - Route guards for authentication
  • βœ… Form Validation - Zod schema validation
  • 🎭 Modal System - Reusable confirmation modals
  • 🌍 Language Switcher - Easy language switching
  • πŸ“Š State Management - Pinia for global state
  • πŸ”§ Git Hooks - Husky + Commitlint for conventional commits
  • πŸ”„ CI/CD Ready - GitHub Actions workflow included

πŸ› οΈ Tech Stack

  • Frontend Framework: Nuxt 4
  • Language: TypeScript
  • Styling: Tailwind CSS + Custom CSS
  • Database: PostgreSQL
  • ORM: Prisma
  • Authentication: JWT (jsonwebtoken + bcrypt)
  • i18n: @nuxtjs/i18n
  • State Management: Pinia
  • Image Optimization: @nuxt/image
  • OG Images: nuxt-og-image
  • Code Quality: ESLint, Husky, Commitlint

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher)
  • Yarn (or npm/pnpm)
  • PostgreSQL (v14 or higher)
  • Git

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/sonht113/nuxt-boilerplate-for-starter.git
cd nuxt-boilerplate-for-starter

2. Install Dependencies

yarn install
# or
npm install

3. Environment Setup

Create a .env file in the root directory:

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/recipe_db"

# JWT Secret (change this in production)
JWT_SECRET="your-super-secret-jwt-key-change-in-production"

# Base URL (for i18n)
BASE_URL="http://localhost:3000"

4. Database Setup

Run Prisma migrations to set up your database:

# Generate Prisma Client
npx prisma generate

# Run migrations
npx prisma migrate dev

# (Optional) Seed the database
npx prisma db seed

5. Start Development Server

yarn dev

The application will be available at http://localhost:3000

πŸ“Έ Screenshots

Home Page

Code App

Recipes List

Recipes

Recipe Detail

Recipe Detail

πŸ“ Project Structure

nuxt-boilerplate-for-starter/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ app.vue                 # Root component
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ common/             # Reusable components
β”‚   β”‚   β”‚   β”œβ”€β”€ ConfirmModal.vue
β”‚   β”‚   β”‚   └── LanguageSwitcher.vue
β”‚   β”‚   └── layout/             # Layout components
β”‚   β”‚       β”œβ”€β”€ header.vue
β”‚   β”‚       └── footer.vue
β”‚   β”œβ”€β”€ layouts/
β”‚   β”‚   └── default.vue         # Default layout
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.global.ts      # Global auth middleware
β”‚   β”‚   └── guest.ts            # Guest middleware
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ index.vue           # Home page
β”‚   β”‚   β”œβ”€β”€ login.vue           # Login page
β”‚   β”‚   β”œβ”€β”€ register.vue        # Register page
β”‚   β”‚   └── recipes/
β”‚   β”‚       β”œβ”€β”€ index.vue       # Recipe list
β”‚   β”‚       β”œβ”€β”€ [id].vue        # Recipe detail
β”‚   β”‚       β”œβ”€β”€ create.vue      # Create recipe
β”‚   β”‚       β”œβ”€β”€ my.vue          # My recipes
β”‚   β”‚       └── edit/
β”‚   β”‚           └── [id].vue    # Edit recipe
β”‚   └── plugins/
β”‚       └── auth-interceptor.ts # Global API interceptor
β”œβ”€β”€ composables/
β”‚   β”œβ”€β”€ useAuth.ts              # Authentication composable
β”‚   β”œβ”€β”€ useRecipe.ts            # Single recipe composable
β”‚   β”œβ”€β”€ useRecipes.ts           # Recipes list composable
β”‚   β”œβ”€β”€ useRecipeForm.ts        # Recipe form composable
β”‚   └── ...
β”œβ”€β”€ i18n/
β”‚   └── locales/
β”‚       β”œβ”€β”€ en.ts               # English translations
β”‚       └── vi.ts               # Vietnamese translations
β”œβ”€β”€ prisma/
β”‚   β”œβ”€β”€ schema.prisma           # Database schema
β”‚   └── migrations/             # Database migrations
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ auth/               # Auth endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ login.post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ register.post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ logout.post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ refresh.post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ me.get.ts
β”‚   β”‚   β”‚   └── change-password.post.ts
β”‚   β”‚   └── recipes/            # Recipe endpoints
β”‚   β”‚       β”œβ”€β”€ index.get.ts
β”‚   β”‚       β”œβ”€β”€ index.post.ts
β”‚   β”‚       β”œβ”€β”€ [id].get.ts
β”‚   β”‚       β”œβ”€β”€ [id].put.ts
β”‚   β”‚       β”œβ”€β”€ [id].patch.ts
β”‚   β”‚       β”œβ”€β”€ [id].delete.ts
β”‚   β”‚       β”œβ”€β”€ my.get.ts
β”‚   β”‚       β”œβ”€β”€ categories.get.ts
β”‚   β”‚       └── stats.get.ts
β”‚   └── utils/
β”‚       β”œβ”€β”€ auth.ts             # Auth utilities
β”‚       └── prisma.ts           # Prisma client
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml              # CI/CD pipeline
β”œβ”€β”€ .husky/
β”‚   └── commit-msg              # Commit message hook
β”œβ”€β”€ commitlint.config.js        # Commitlint configuration
β”œβ”€β”€ nuxt.config.ts              # Nuxt configuration
β”œβ”€β”€ prisma/schema.prisma        # Database schema
β”œβ”€β”€ tailwind.config.js          # Tailwind configuration
└── tsconfig.json               # TypeScript configuration

πŸ” Authentication Flow

  1. Register - Create a new account with email, name, and password
  2. Login - Authenticate and receive access + refresh tokens
  3. Protected Routes - Middleware checks authentication status
  4. Token Refresh - Automatic token refresh on expiration
  5. Logout - Clear tokens and redirect to login
  6. Auto Redirect - 401 errors automatically redirect to login

πŸ—„οΈ Database Schema

User Model

  • id, email, name, password (hashed)
  • recipes (relation)
  • refreshTokens (relation)

Recipe Model

  • id, title, description, ingredients, instructions
  • cookingTime, servings, imageUrl, category, difficulty
  • isPublic, authorId (relation to User)
  • author (relation)

RefreshToken Model

  • id, token, userId (relation to User)
  • expiresAt, createdAt

πŸ“ API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • POST /api/auth/refresh - Refresh access token
  • GET /api/auth/me - Get current user
  • POST /api/auth/change-password - Change password

Recipes

  • GET /api/recipes - Get all recipes (with filters)
  • GET /api/recipes/:id - Get recipe by ID
  • POST /api/recipes - Create new recipe (auth required)
  • PUT /api/recipes/:id - Update recipe (auth required)
  • PATCH /api/recipes/:id - Partial update (auth required)
  • DELETE /api/recipes/:id - Delete recipe (auth required)
  • GET /api/recipes/my - Get user's recipes (auth required)
  • GET /api/recipes/categories - Get recipe categories
  • GET /api/recipes/stats - Get recipe statistics

🌐 Internationalization

The app supports multiple languages. Add translations in i18n/locales/:

// i18n/locales/en.ts
export default {
  welcome: "Welcome",
  // ... more translations
};

// i18n/locales/vi.ts
export default {
  welcome: "ChΓ o mα»«ng",
  // ... more translations
};

Use in components:

<template>
  <h1>{{ $t("welcome") }}</h1>
</template>

🎨 Components

ConfirmModal

Reusable confirmation modal for delete/important actions:

<CommonConfirmModal
  v-model="showModal"
  title="Delete Recipe"
  message="Are you sure?"
  type="danger"
  @confirm="handleDelete"
/>

LanguageSwitcher

Language switcher with dropdown:

<CommonLanguageSwitcher />

πŸ§ͺ Scripts

# Development
yarn dev              # Start dev server

# Build
yarn build            # Build for production
yarn preview          # Preview production build

# Database
npx prisma studio     # Open Prisma Studio
npx prisma migrate dev # Run migrations

# Code Quality
yarn prepare          # Setup Husky hooks

πŸ“¦ Commit Convention

This project uses Conventional Commits:

feat: add new feature
fix: bug fix
docs: documentation changes
style: code style changes
refactor: code refactoring
perf: performance improvements
test: add tests
build: build system changes
ci: CI configuration
chore: other changes

See COMMIT_CONVENTION.md for details.

πŸš€ Deployment

Build for Production

yarn build

Environment Variables

Make sure to set these in your production environment:

  • DATABASE_URL - Production database URL
  • JWT_SECRET - Strong secret key
  • BASE_URL - Production domain

Hosting Options

  • Vercel - Recommended for Nuxt apps
  • Netlify - Good alternative
  • DigitalOcean - Full control with droplets
  • Railway - Easy deployment with databases

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes using conventional commits
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ‘¨β€πŸ’» Author

nuicoder

πŸ™ Acknowledgments

πŸ“ž Support

If you have any questions or need help, please open an issue on GitHub.


Built with ❀️ using Nuxt 4, Prisma, TypeScript & PostgreSQL

About

πŸš€ Nuxt 4 Boilerplate for Starter β€” A clean, modern, production-ready Nuxt 4 setup with i18n, UI presets, API layer & best practices to kickstart your next project.✨

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published