How diegovallejodev/jwt-test-playground works
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.