How antoinemcx/react-nextjs-boilerplate works
This project is a full-stack application boilerplate built on Next.js (version 14+), intended to serve as a production-ready starter template for React projects. It provides a modern UI (using Tailwind CSS, shadcn/ui, and next-themes for theming), a well-structured Next.js file layout (including the new App Router pattern), full-stack API routes, and integrated database support via Prisma (usable with MySQL or compatible systems). Authentication is handled using next-auth with custom endpoints for login and registration.
Overall System Components
• Frontend User Interface: Represented by the Next.js pages and components in the “src/app” and “src/components” directories. This component includes:
• Authentication pages (login and register in src/app/(auth))
• Admin and general user pages (src/app/page, src/app/admin)
• Reusable UI components like Navbar, Avatar, Buttons, and Dropdowns.
• Global providers and theme toggling, wrapped in components like src/components/Providers.tsx and configuration through next-themes.
• API Layer: Found under “src/app/api” where endpoints for authentication (next-auth routes and custom register endpoints) reside. These endpoints orchestrate business logic, authentication workflows, and database operations.
• Database and ORM Layer: Managed through the “prisma” directory which contains the Prisma schema along with migration files. The connection to the database is abstracted in src/lib/db.ts and is used by next-auth for user authentication.
• Utility and Shared Components: Includes custom hooks (e.g., useGoogleSignIn, useSignOut, useToast), helper functions (src/helpers, src/lib/utils.ts), middleware, and type definitions.
• Project Infrastructure & Configuration: Outlined in the root configuration files (.env.example, next.config.js, tailwind.config.js, tsconfig.json, etc.) and the documentation files in “docs”. This provides deployment, environment, and code styling configurations.
Defining Relationships & Interactions
• The Frontend communicates with the API layer using Next.js API routes that encapsulate authentication and registration logic.
• UI components (for instance, the Navbar and Auth forms) trigger calls to these endpoints using custom hooks that abstract away the networking concerns.
• The API layer leverages middleware (e.g., src/middleware.ts) to enforce private routing and secure access.
• Database interactions are managed through Prisma such that API routes perform CRUD operations on the user database.
Highlighting Architectural Patterns & Design Principles
• Separation of Concerns: Clear distinction between UI components, API routes, and backend logic (database layer).
• Modular Structure: The directory structure shows modularization (e.g., separate folders for authentication, admin, and common UI components), following a component-driven design.
• Declarative Routing (Next.js App Router): Uses file-based routing in src/app to enable clear URL mappings.
• API-first and Data-driven: Built using Next.js API routes, with next-auth and Prisma powering centralized authentication and data persistence.
• Responsive and Themed UI: Implemented via shadcn/ui, Tailwind CSS, and next-themes for a consistent look and feel.
• A Frontend/UI Block that includes pages, components (e.g., Navbar, auth forms), and theming providers.
• An API Block capturing the Next.js API routes for authentication, registration, and possibly other business logic.
• A Database Block showing Prisma as the ORM and the underlying MySQL (or other) database.
• An Infrastructure/Configuration Block representing build tools (ESLint, Prettier, Tailwind, etc.) and deployment configuration.
b. Directional interactions:
d. Design details:
• That the authentication system uses next-auth related endpoints.
• File-based routing inherent in Next.js.
• External dependencies like next-sitemap for SEO elements (sitemap.xml, robots.txt in the public directory).