How duthanhduoc/nextjs-free works
Main Components
a. Frontend Client:
• Built with Next.js and organized under the client directory.
• Contains the Next.js “app” directory with various pages for authentication (login, register, logout), product operations (list, add, edit, view), and shared UI components.
• Handles API requests (see folder “src/apiRequests”) and static assets (public/images).
b. Backend Server:
• Located under the server directory and built with Fastify.
• Contains a set of controllers (e.g., account.controller, auth.controller, product.controller) and routes (e.g., auth.route, product.route) which define RESTful endpoints.
• Includes plugins for common functionalities such as authentication, error handling, and request validation.
• Uses a middleware architecture (noting use of hooks in auth.hooks.ts).
c. Database:
• Managed via Prisma (found in the server/prisma folder) with a schema that supports development (evidenced by dev.db and schema.prisma).
• Acts as the persistent storage for user credentials, product information, and any other business data.
Relationships and Interactions
a. The user interacts with the frontend client (Next.js application).
b. The client makes HTTP requests (using the API requests layer in client/src/apiRequests) to the backend server’s RESTful endpoints.
c. The backend server processes these requests by invoking the appropriate controllers, applying authentication, validation (via schema validations in both client and server), and business logic.
d. Backend controllers interact with the database via Prisma, performing CRUD operations on user profiles, product listings, etc.
e. Responses and data flows travel back from the server to the client, where the UI is updated accordingly.
Incorporate Architectural Patterns and Technologies
a. Client-Side Routing and Server-side Rendering:
• Next.js handles both client and server rendering (there are even API endpoints under client/src/app/api).
b. MVC-like Pattern on the Backend:
• Controllers manage the business logic.
• Routes define endpoints.
• Database access is mediated via an ORM (Prisma).
c. Authentication and Middleware:
• Both client and server maintain schema validations and authentication flows.
• The server includes plugins and hooks for authentication and error-handling.
d. Build & Deployment:
• There are ecosystem configuration files (ecosystem.config.js, nodemon.json) and configuration files (e.g., .eslintrc, tailwind.config.ts) to streamline development and deployment.