A fullstack boilerplate project using Next.js, Prisma, PostgreSQL, and Tailwind CSS. This project provides a starting point for building fullstack applications with a modern tech stack. It includes essential features such as authentication, database integration, theming, and role-based access control (RBAC) along with Login and Signup pages with full functionality.
- Demo
- Features
- Tech Stack
- Project Structure
- Getting Started
- Pages and APIs
- Authentication and RBAC
- Contributing
- License
- Authentication:
- Login and Signup pages
- Authentication using JWT
- HTTP-only cookies for storing JWT
- Styling:
- Tailwind CSS for styling
- Light & Dark mode theme
- Responsive design
- Access Control:
- Role-Based Access Control (RBAC)
- Protected routes
- User and Admin roles
- Backend APIs:
- Next.js API routes
- Database:
- PostgreSQL database
- Prisma for database access
- Frontend: Next.js, React, Tailwind CSS
- Backend: Next.js API routes, Prisma
- Database: PostgreSQL
- Authentication: JSON Web Tokens (JWT) using the
jose
library
The project structure is as follows:
Before you begin, you'll need Git, pnpm, Node.js, Postgres installed on your computer with the following versions (lower versions may or may not work):
- Git (v2.39.x or later)
- pnpm (v9.11.x or later)
- Node.js (v20.x.x or later)
- PostgreSQL (v14.x.x or later)
Copy the .env.example
file to .env
and update the environment variables as needed.
-
Clone the repository:
git clone https://github.com/yourusername/nextjs-fullstack-boilerplate.git cd nextjs-fullstack-boilerplate
-
Install dependencies:
pnpm install
-
Set up the database:
Create a PostgreSQL database and update the
DATABASE_URL
in the.env
file. -
Run database migrations:
pnpm prisma migrate dev
Start the development server:
pnpm dev
Open your browser and navigate to http://localhost:3000.
Build the application for production:
pnpm build
Start the production server:
pnpm start
- Login Page (
/login
): The login page for users to log in. - Signup Page (
/signup
): The signup page for new users to create an account. - Home Page (
/
): The landing page of the application. - Admin Dashboard (
/admin/dashboard
): A protected page accessible only to users with admin roles.
- Login API (
/api/auth/login
): The API route for user login. - Signup API (
/api/auth/signup
): The API route for user signup. - Logout API (
/api/auth/logout
): The API route for user logout. - Check Auth API (
/api/auth/check
): The API route to check if the user is authenticated. - Catch-All API (
/api/*
): A catch-all API route to handle all other requests.
The application uses JSON Web Tokens (JWT) for authentication, implemented using the jose
library. The JWT is stored in an HTTP-only cookie to enhance security.
- Login: Users can log in by providing their credentials. Upon successful login, a JWT is generated and stored in an HTTP-only cookie.
- Signup: New users can create an account by providing their details. Upon successful signup, a JWT is generated and stored in an HTTP-only cookie.
- Logout: Users can log out, which clears the JWT cookie.
The application implements role-based access control to restrict access to certain pages based on user roles.
- Roles: The application supports multiple roles, such as
user
andadmin
. - Access Control: Middleware functions check the user's role before allowing access to protected routes.
I welcome contributions to make this project better for everyone. Here are some ways you can contribute:
- Report Bugs: If you encounter any bugs, please create an issue with detailed information about the problem and how to reproduce it.
- Suggest Features: Have an idea for a new feature? Open an issue to discuss it with the community.
- Improve Documentation: Help improve the documentation by making it clearer and more comprehensive.
- Submit Pull Requests: If you have made improvements or added new features to your fork, feel free to submit a pull request. Please ensure your code follows the project's coding standards and includes relevant tests.
- Fork the Repository: Click the "Fork" button at the top right of this page to create a copy of this repository in your GitHub account.
- Clone the Fork: Clone your fork to your local machine using the following command:
git clone https://github.com/yourusername/nextjs-fullstack-boilerplate.git
- Create a Branch: Create a new branch for your feature or bugfix:
git checkout -b feature-or-bugfix-name
- Make Changes: Make your changes in the new branch.
- Commit Changes: Commit your changes with a descriptive commit message:
git commit -m "Description of the changes"
- Push to Fork: Push your changes to your forked repository:
git push origin feature-or-bugfix-name
- Open a Pull Request: Go to the original repository and open a pull request from your forked repository. Provide a clear description of the changes and any related issues.
Thank you for your contributions!