# azzaky9/jwt-todo-app architecture

> Architecture diagram of the GitHub repository azzaky9/jwt-todo-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azzaky9/jwt-todo-app
- Repository: https://github.com/azzaky9/jwt-todo-app

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User interaction
    U["User Interaction"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["Next.js UI Routes (Next.js with Tailwind CSS)"]
        COMP["Reusable UI Components (React with TypeScript)"]
    end

    %% API Layer
    subgraph "API Layer"
        API["API Endpoints (Serverless Functions)"]
    end

    %% Service Layer
    subgraph "Service Layer"
        SVC["Business Logic / Service Layer"]
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["PostgreSQL Database"]
    end

    %% Utility and Validation Modules
    subgraph "Utility & Validation Modules"
        VAL["Validation Modules (Valibot)"]
        RQ["React Query Utilities"]
        UTIL["Miscellaneous Utilities"]
    end

    %% Data flow connections
    U -->|"triggers"| UI
    UI -->|"calls"| API
    API -->|"executes"| SVC
    SVC -->|"CRUD & Auth ops"| DB
    DB -->|"data response"| SVC
    SVC -->|"returns"| API
    API -->|"sends back"| UI
    UI -->|"data fetching"| RQ
    UI -->|"error handling"| UTIL
    API -->|"input validation"| VAL
    API -->|"JWT/Bcrypt/Jose"| SVC

    %% Click Events
    click UI "https://github.com/azzaky9/jwt-todo-app/tree/main/src/app"
    click COMP "https://github.com/azzaky9/jwt-todo-app/tree/main/src/components"
    click API "https://github.com/azzaky9/jwt-todo-app/tree/main/src/app/api"
    click SVC "https://github.com/azzaky9/jwt-todo-app/tree/main/src/service"
    click DB "https://github.com/azzaky9/jwt-todo-app/tree/main/src/db"
    click VAL "https://github.com/azzaky9/jwt-todo-app/tree/main/src/lib/validation"
    click RQ "https://github.com/azzaky9/jwt-todo-app/tree/main/src/lib/tanstack"
    click UTIL "https://github.com/azzaky9/jwt-todo-app/tree/main/src/utils"

    %% Styling classes
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef api fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef service fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef database fill:#ff9999,stroke:#000,stroke-width:2px;
    classDef utilities fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef user fill:#ffd700,stroke:#000,stroke-width:2px;

    class UI,COMP frontend
    class API api
    class SVC service
    class DB database
    class VAL,RQ,UTIL utilities
    class U user
```
