WIP
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx
. The page auto-updates as you edit the file.
This project uses next/font
to automatically optimize and load Inter, a custom Google Font.
"dev": "next dev",
"dev:turbo": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix",
"format": "prettier --check --ignore-path .gitignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"prepare": "husky",
"test": "jest",
"test:watch": "jest --watch",
"prisma:studio": "prisma studio",
"prisma:generate": "prisma generate",
"prisma:validate": "prisma validate",
"prisma:format": "prisma format",
"prisma:migrate:dev": "prisma migrate dev",
"prisma:migrate:reset": "prisma migrate reset",
"prisma:migrate:deploy": "prisma migrate deploy",
"vercel-build": "prisma generate && prisma migrate deploy && next build"
โโโ .env.example # Example environment variables file
โโโ .gitignore # Git ignore file to exclude files and directories from version control
โโโ .husky # Husky configuration for Git hooks
โโโ .prettierrc # Prettier configuration file
โโโ .vscode # VSCode configurations (extensions, settings, etc.)
โโโ commitlint.config.ts # Commitlint configuration file
โโโ components.json # JSON file for component configurations
โโโ eslint.config.mjs # ESLint configuration file
โโโ jest.config.ts # Jest configuration file for testing
โโโ jest.setup.ts # Jest setup file for initializing tests
โโโ messages # Folder for translation files
โ โโโ en # English translations
โ โโโ fr # French translations
โโโ next-env.d.ts # TypeScript definitions for Next.js
โโโ next.config.mjs # Next.js configuration file
โโโ package.json # Project dependencies and scripts
โโโ postcss.config.mjs # PostCSS configuration file
โโโ prisma # Prisma ORM configuration and migrations
โ โโโ migrations # Folder for database migrations
โ โโโ schema.prisma # Prisma schema file
โโโ public # Public assets directory
โโโ src # Source code directory
โ โโโ app # Main application folder
โ โ โโโ [locale] # Locale-specific routes
โ โ โ โโโ (auth) # Authentication-related pages
โ โ โ โโโ dashboard # Dashboard pages
โ โ โ โโโ layout.tsx # Layout component for locale-specific routes
โ โ โ โโโ not-found.tsx # 404 Not Found page for locale-specific routes
โ โ โ โโโ page.tsx # Main page component for locale-specific routes
โ โ โ โโโ settings # Settings pages
โ โ โโโ favicon.ico # Favicon for the application
โ โ โโโ global-error.tsx # Global error handling component
โ โ โโโ globals.css # Global CSS styles
โ โ โโโ layout.tsx # Main layout component
โ โ โโโ not-found.tsx # 404 Not Found page
โ โโโ assets # Static assets like images, fonts, and icons
โ โโโ constants # Constant values used across the application
โ โโโ components # Reusable components
โ โ โโโ shared # Shared components
โ โ โ โโโ ThemeToggle # Theme toggle component
โ โ โโโ theme-provider.tsx # Theme provider component
โ โ โโโ ui # UI components
โ โโโ db # Database-related utilities and configurations
โ โโโ i18n # Internationalization configuration
โ โโโ lib # Utility functions and libraries
โ โโโ middleware.ts # Middleware configuration
โ โโโ services # Service layer for API calls and business logic
โ โโโ types # TypeScript type definitions
โ โโโ utils # List of utils functions
โโโ tailwind.config.ts # Tailwind CSS configuration file
โโโ tsconfig.json # TypeScript configuration file
โโโ vercel.json # Vercel deployment configuration
WIP
commitlint checks if your commit messages meet the conventional commit format.
In general the pattern mostly looks like this:
type(scope?): subject #scope is optional; multiple scopes are supported (current delimiter options: "/", "\" and ",")
Real world examples can look like this:
chore: run tests on travis ci
fix(server): send cors headers
feat(blog): add comment section
Common types according to commitlint-config-conventional (based on the Angular convention) can be:
[ci skip]
in the commit title:art:
when improving the format/structure of the code:racehorse:
when improving performance:non-potable_water:
when plugging memory leaks:memo:
when writing docs:penguin:
when fixing something on Linux:apple:
when fixing something on macOS:checkered_flag:
when fixing something on Windows:bug:
when fixing a bug:fire:
when removing code or files:green_heart:
when fixing the CI build:white_check_mark:
when adding tests:lock:
when dealing with security:arrow_up:
when upgrading dependencies:arrow_down:
when downgrading dependencies:shirt:
when removing linter warningsWIP
This project uses the next-intl
library for internationalization (i18n). Below are the steps to set up and use i18n in this project.
Configuration:
The i18n configuration is defined in src/i18n/routing.ts
. This file sets up the supported locales and the default locale.
import { createNavigation } from "next-intl/navigation";
import { defineRouting } from "next-intl/routing";
export const routing = defineRouting({
locales: ["en", "fr"],
defaultLocale: "en",
});
export type Locale = (typeof routing.locales)[number];
export const { Link, redirect, usePathname, useRouter, getPathname } =
createNavigation(routing);
Middleware:
The middleware for handling i18n routing is set up in src/middleware.ts
. This middleware ensures that the correct locale is used based on the request.
import createMiddleware from "next-intl/middleware";
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { routing } from "./i18n/routing";
const handleI18nRouting = createMiddleware(routing);
const isProtectedRoute = createRouteMatcher(["/:locale/dashboard(.*)"]);
export default clerkMiddleware(async (auth, req) => {
if (isProtectedRoute(req)) await auth.protect();
return handleI18nRouting(req);
});
export const config = {
matcher: [
"/",
"/(en|fr)/:path*",
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
"/(api|trpc)(.*)",
],
};
Messages:
Translation messages are stored in the messages
directory. Each locale has its own folder containing JSON files for different namespaces. For example:
messages/en/home.json
messages/fr/home.json
Request Configuration:
The request configuration for i18n is defined in src/i18n/request.ts
. This file ensures that the correct messages are loaded based on the request locale.
import { getRequestConfig } from "next-intl/server";
import { Locale, routing } from "./routing";
export default getRequestConfig(async ({ requestLocale }) => {
let locale = await requestLocale;
if (!locale || !routing.locales.includes(locale as Locale)) {
locale = routing.defaultLocale;
}
return {
locale,
messages: {
...(await import(`../../messages/${locale}/home.json`)).default,
...(await import(`../../messages/${locale}/auth.json`)).default,
...(await import(`../../messages/${locale}/notFound.json`)).default,
},
};
});
Adding Translations:
To add translations, create or update the JSON files in the messages
directory. For example, to add a new translation for the home page in French, update messages/fr/home.json
:
{
"Home": {
"Docs": {
"title": "Documents",
"text": "Trouvez des informations dรฉtaillรฉes sur les fonctionnalitรฉs et l'API de Next.js."
},
"Learn": {
"title": "Apprendre",
"text": "Apprenez ร connaรฎtre Next.js dans un cours interactif avec des quiz !"
}
}
}
Using Translations in Components:
Use the useTranslations
hook from next-intl
to access translations in your components. For example, in a component:
import { useTranslations } from "next-intl";
export default function Home() {
const t = useTranslations("Home");
return (
<main>
<h1>{t("Docs.title")}</h1>
<p>{t("Docs.text")}</p>
</main>
);
}
Linking to Different Locales:
Use the Link
component from next-intl/navigation
to create links that respect the current locale. For example:
import { Link } from "@/i18n/routing";
export default function Navigation() {
return (
<nav>
<Link href="/">{t("Home")}</Link>
<Link href="/about">{t("About")}</Link>
</nav>
);
}
By following these steps, you can set up and use i18n in your Next.js project to support multiple languages.
# Set up a new Prisma project
$ prisma init
# Generate artifacts (e.g. Prisma Client)
$ prisma generate
# Browse your data
$ prisma studio
# Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
$ prisma migrate dev
# Pull the schema from an existing database, updating the Prisma schema
$ prisma db pull
# Push the Prisma schema state to the database
$ prisma db push
# Validate your Prisma schema
$ prisma validate
# Format your Prisma schema
$ prisma format
# Display Prisma version info
$ prisma version
# Display Prisma debug info
$ prisma debug
In some scenarios, you need to edit a migration file before you apply it. For example, to change the direction of a 1-1 relation (moving the foreign key from one side to another) without data loss, you need to move data as part of the migration - this SQL is not part of the default migration, and must be written by hand.
This guide explains how to edit migration files and gives some examples of use cases where you may want to do this.
To edit a migration file before applying it, the general procedure is the following:
Make a schema change that requires custom SQL (for example, to preserve existing data)
Create a draft migration using:
npx prisma migrate dev --create-only
Modify the generated SQL file.
Apply the modified SQL by running:
npx prisma migrate dev
WIP
Generate a basic Jest configuration file by running the following command npm init jest@latest
This will take you through a series of prompts to setup Jest for your project, including automatically creating a jest.config.ts
.
Jest will look for test files with any of the following popular naming conventions:
.js
suffix in __tests__
folders..test.js
suffix..spec.js
suffix.The .test.js
/ .spec.js
files (or the __tests__
folders) can be located at any depth under the src
top level folder.
We recommend to put the test files (or __tests__
folders) next to the code they are testing so that relative imports appear shorter. For example, if App.test.js
and App.js
are in the same folder, the test only needs to import App from './App'
instead of a long relative path. Collocation also helps find tests more quickly in larger projects.
To run test yarn test
The Better Comments extension will help you create more human-friendly comments in your code. With this extension, you will be able to categorize your annotations into:
Tailwind CSS IntelliSense enhances the Tailwind development experience by providing Visual Studio Code users with advanced features such as autocomplete, syntax highlighting, and linting.
Integrates ESLint into VS Code. If you are new to ESLint check the documentation.
The extension uses the ESLint library installed in the opened workspace folder. If the folder doesn't provide one the extension looks for a global install version. If you haven't installed ESLint either locally or globally do so by running npm install eslint in the workspace folder for a local install or npm install -g eslint
for a global install.
On new folders you might also need to create an .eslintrc configuration file. You can do this by either using the VS Code command Create ESLint configuration or by running the eslint command in a terminal with npx eslint --init
.
General Features
SonarLint by Sonar is a free IDE extension that empowers you to fix coding issues before they exist. More than a linter, SonarLint detects and highlights issues that can lead to bugs, vulnerabilities, and code smells as you create your code. It offers clear remediation guidance and educational help, so you can fix issues before the code is committed. SonarLint in VS Code supports analysis of JS/TS, Python, PHP, Java, C, C++, C#, Go, and IaC code locally in your IDE.
ErrorLens turbo-charges language diagnostic features by making diagnostics stand out more prominently, highlighting the entire line wherever a diagnostic is generated by the language and also prints the message inline.
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
To learn more about Next.js, take a look at the following resources:
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!