How azzaky9/jwt-todo-app works
Main Components
• Frontend (Next.js UI):
• Next.js “app” directory, showing its separation into different routes and groups (e.g., authentication pages under (auth), todo pages, and user profile pages).
• Reusable UI components (Forms, Navbar, Todo components, etc.) from the “src/components” directory.
• That the UI is built using React with TypeScript and styled using Tailwind CSS.
• API / Backend Layer:
• Server-side API endpoints located in “src/app/api”. Group endpoints by functionality (e.g., todo endpoints and user profile endpoints).
• That these endpoints encapsulate business logic and serve as the interface between the frontend and backend.
• Service Layer:
• “src/service” directory where the core business logic for authentication, todo management, and user handling is implemented.
• That these services orchestrate interactions between the API routes and lower-level operations.
• Database:
• PostgreSQL component, highlighting that the connection and queries are managed in the “src/db” directory.
• Schema definitions (e.g., “src/db/schema/schema.sql”) and the database interface (e.g., “src/db/interface.ts” and “src/db/pg.ts”).
• Utility and Validation Modules:
• Modules such as “src/lib/validation” which handles rules for auth, profile, and todos, and “src/lib/tanstack” for React Query utilities.
• Miscellaneous utilities (e.g., cookie handling, error utilities in “src/utils”).
Relationships and Interactions
• Frontend components making API calls (e.g., via the built-in Next.js API routes) to the backend.
• Service layer as the intermediary that encapsulates business logic invoked by the API endpoints.
• Service layer with the database module for data persistence, making clear that CRUD operations and user authentication rely on database interactions.
• External libraries (e.g., bcryptjs for hashing, jose for JWT processing) within the authentication flow.
Architectural Patterns and Design Principles
• That the application employs a modular structure by separating concerns (UI, API, business logic, and data access).
• Usage of serverless function endpoints in Next.js (via “src/app/api”) which simplifies scalability.
• Pattern of having clear service layers and validation to ensure robust interactions between the UI and the database.
• Mention the integration of state management and data fetching via React Query.