# diegovallejodev/jwt-test-playground architecture

> Architecture diagram of the GitHub repository diegovallejodev/jwt-test-playground, 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/diegovallejodev/jwt-test-playground
- Repository: https://github.com/diegovallejodev/jwt-test-playground

## Overview

##### Main Components
- Frontend UI: Represented by the Next.js pages, especially the main page (pages/index.tsx) and any other page under the “pages” directory. The _app.tsx file in pages sets up the global structure.
- API Routes (Backend Logic): Found in the pages/api folder that includes endpoints for login, refresh, and validate. These endpoints handle the JWT-related operations.
- Core JWT and Utility Modules: Under the src directory, there are several modules such as JWTdecode.ts, Users.ts, sha256.ts, timingUtils.ts, and a dedicated “jwt” folder. They encapsulate the logic for decoding, signing, validating tokens, and handling session configurations.
- React Components: Residing in src/components (e.g., Login.tsx, Logout.tsx, RefreshSession.tsx, JWTInfo.tsx, Table.tsx, ExpirationCountdown.tsx, Timer.tsx, Validate.tsx). These components compose the interactive UI elements that interact with API endpoints and utility modules.
- Static Assets & Styling: The public folder for public/static files and the styles folder for CSS (globals.css) that provide visual presentation.

##### Relationships and Data Flows
- API to Utility Modules: API endpoints (in pages/api) internally call functions from the src directory (for JWT decoding, session handling, etc.). Mark these as internal dependencies.
- Component Interactions: Show that React components in src/components import and use helper functions from utility modules and optionally share state or prop information where needed.

##### Architectural Patterns
- Next.js Framework: Emphasize the Next.js file structure which automatically maps pages to routes, both for page views and API endpoints.
- Separation of Concerns: Demonstrate how UI (components/pages) is cleanly separated from backend logic (API endpoints) and further modularized into utility libraries (src directory).

##### Technologies and Frameworks
- Next.js for server-side rendering and routing.
- TypeScript (as files have .ts and .tsx extensions), ensuring type safety.
- Node.js environment for API endpoints.
- JWT libraries/logic implemented within the custom utility modules in src.
- ESLint for code quality (via .eslintrc.json).
- CSS styling managed in the styles folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    expWarn["WARNING: DO NOT USE IN PRODUCTION"]:::warning

    subgraph "Frontend UI"
        nextPages["Next.js Pages"]
        reactComp["React Components"]
    end

    subgraph "API Endpoints"
        loginAPI["Login API Endpoint"]
        refreshAPI["Refresh API Endpoint"]
        validateAPI["Validate API Endpoint"]
    end

    subgraph "Utility/Service Layer"
        jwtDec["JWT Decoding"]
        userMgmt["User Management"]
        sha256["Crypto (sha256)"]
        timingUtils["Timing Utilities"]
        jwtFuncs["JWT Functions"]
        sessionCfg["Session Config"]
        prettyJson["JSON Prettification"]
    end

    subgraph "Static Assets & Styling"
        publicFiles["Public Files"]
        globalStyles["Global Styles"]
    end

    %% Data flows from Frontend to API Endpoints
    nextPages -->|"triggers"| loginAPI
    nextPages -->|"triggers"| refreshAPI
    nextPages -->|"triggers"| validateAPI

    reactComp -->|"calls/API"| loginAPI
    reactComp -->|"calls/API"| refreshAPI
    reactComp -->|"calls/API"| validateAPI

    %% API Endpoints to Utility/Service Layer flows
    loginAPI -->|"decodes"| jwtDec
    loginAPI -->|"auths"| userMgmt
    loginAPI -->|"crypto"| sha256
    loginAPI -->|"uses"| jwtFuncs

    refreshAPI -->|"reconfigures"| sessionCfg
    refreshAPI -->|"uses"| jwtFuncs

    validateAPI -->|"validates"| jwtDec
    validateAPI -->|"timing"| timingUtils
    validateAPI -->|"uses"| jwtFuncs

    %% Direct dependency from React Components to Utility layer
    reactComp -->|"imports"| jwtFuncs

    %% Frontend usage of Static Assets & Styling
    nextPages ---|"styledWith"| globalStyles
    reactComp ---|"styledWith"| globalStyles
    nextPages ---|"resources"| publicFiles

    %% Class Definitions for styling
    class nextPages,reactComp frontend
    class loginAPI,refreshAPI,validateAPI api
    class jwtDec,userMgmt,sha256,timingUtils,jwtFuncs,sessionCfg,prettyJson util
    class publicFiles,globalStyles static
    class expWarn warning

click nextPages "https://github.com/diegovallejodev/jwt-test-playground/blob/main/pages/index.tsx"
click reactComp "https://github.com/diegovallejodev/jwt-test-playground/tree/main/src/components"
click loginAPI "https://github.com/diegovallejodev/jwt-test-playground/blob/main/pages/api/login.ts"
click refreshAPI "https://github.com/diegovallejodev/jwt-test-playground/blob/main/pages/api/refresh.ts"
click validateAPI "https://github.com/diegovallejodev/jwt-test-playground/blob/main/pages/api/validate.ts"
click jwtDec "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/JWTdecode.ts"
click userMgmt "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/Users.ts"
click sha256 "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/sha256.ts"
click timingUtils "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/timingUtils.ts"
click jwtFuncs "https://github.com/diegovallejodev/jwt-test-playground/tree/main/src/jwt"
click sessionCfg "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/sessionconfig.ts"
click prettyJson "https://github.com/diegovallejodev/jwt-test-playground/blob/main/src/pretifyJson.ts"
click publicFiles "https://github.com/diegovallejodev/jwt-test-playground/tree/main/public"
click globalStyles "https://github.com/diegovallejodev/jwt-test-playground/blob/main/styles/globals.css"
```
