# ranjithpn292/jwt-with-nodejs architecture

> Architecture diagram of the GitHub repository ranjithpn292/jwt-with-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ranjithpn292/jwt-with-nodejs
- Repository: https://github.com/ranjithpn292/jwt-with-nodejs

## Overview

This repository is a small Express/JWT demonstration with two independently listening servers: an authentication server on port 4000 and a protected-post server on port 3000. The workflow is login to obtain tokens, submit a refresh token to receive a new access token, then use that access token to request matching posts. Logout filters an in-memory token list. The README gives no additional product capabilities; the graph reflects the sampled source, including the refresh-token flow as implemented.

Main entry points: [`server.js`](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js) (Posts API), [`authServer.js`](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js) (Refresh and logout), [`.env`](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/.env) (Environment secrets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_auth["Authentication server"]
  node_auth_api["Auth API<br/>[authServer.js]"]
  node_login["Login route<br/>[authServer.js]"]
  node_refresh_logout["Refresh and logout<br/>[authServer.js]"]
  node_token_list[("Refresh token list<br/>[authServer.js]")]
end

subgraph group_protected["Protected posts"]
  node_posts_api["Posts API<br/>[server.js]"]
  node_auth_middleware["Token middleware<br/>[server.js]"]
  node_post_data[("In-memory posts<br/>[server.js]")]
end

subgraph group_tokens["JWT operations"]
  node_access_sign["Access token signing<br/>[authServer.js]"]
  node_refresh_sign["Refresh token signing<br/>[authServer.js]"]
  node_jwt["jsonwebtoken"]
end

node_client(("API client"))
node_env["Environment secrets<br/>[.env]"]

node_client -->|"POST login"| node_login
node_login -->|"generates"| node_access_sign
node_login -->|"signs refresh"| node_refresh_sign
node_refresh_logout -->|"generates"| node_access_sign
node_refresh_logout -->|"adds or filters"| node_token_list
node_refresh_logout -->|"verifies token"| node_jwt
node_access_sign -->|"signs access"| node_jwt
node_refresh_sign -->|"signs refresh"| node_jwt
node_client -->|"POST token or DELETE logout"| node_refresh_logout
node_client -->|"GET posts"| node_posts_api
node_posts_api -->|"guards route"| node_auth_middleware
node_auth_middleware -->|"verifies access"| node_jwt
node_auth_middleware -->|"continues request"| node_posts_api
node_posts_api -->|"filters posts"| node_post_data
node_env -->|"provides secrets"| node_auth_api
node_env -->|"provides secret"| node_posts_api

click node_auth_api "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_login "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_refresh_logout "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_token_list "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_access_sign "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_refresh_sign "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js"
click node_posts_api "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js"
click node_auth_middleware "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js"
click node_post_data "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js"
click node_env "https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/.env"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_auth_api,node_login,node_refresh_logout,node_token_list,node_client toneBlue
class node_posts_api,node_auth_middleware,node_post_data toneAmber
class node_access_sign,node_refresh_sign,node_jwt toneMint
class node_env toneTeal
```

## Components

### Authentication server

- [Auth API](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`
- [Login route](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`
- [Refresh and logout](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`
- [Refresh token list](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`

### Protected posts

- [Posts API](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js): `server.js`
- [Token middleware](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js): `server.js`
- [In-memory posts](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/server.js): `server.js`

### JWT operations

- [Access token signing](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`
- [Refresh token signing](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/authServer.js): `authServer.js`
- **jsonwebtoken**

### Other components

- **API client**
- [Environment secrets](https://github.com/ranjithpn292/jwt-with-nodejs/blob/main/.env): `.env`

## Connections

- API client → Login route: POST login (evidence: `authServer.js`)
- Login route → Access token signing: generates (evidence: `authServer.js`)
- Login route → Refresh token signing: signs refresh (evidence: `authServer.js`)
- Refresh and logout → Access token signing: generates (evidence: `authServer.js`)
- Refresh and logout → Refresh token list: adds or filters (evidence: `authServer.js`)
- Refresh and logout → jsonwebtoken: verifies token (evidence: `authServer.js`)
- Access token signing → jsonwebtoken: signs access (evidence: `authServer.js`)
- Refresh token signing → jsonwebtoken: signs refresh (evidence: `authServer.js`)
- API client → Refresh and logout: POST token or DELETE logout (evidence: `authServer.js`)
- API client → Posts API: GET posts (evidence: `server.js`)
- Posts API → Token middleware: guards route (evidence: `server.js`)
- Token middleware → jsonwebtoken: verifies access (evidence: `server.js`)
- Token middleware → Posts API: continues request (evidence: `server.js`)
- Posts API → In-memory posts: filters posts (evidence: `server.js`)
- Environment secrets → Auth API: provides secrets (evidence: `authServer.js`)
- Environment secrets → Posts API: provides secret (evidence: `server.js`)
