# louisephillips-eng/pern_login architecture

> Architecture diagram of the GitHub repository louisephillips-eng/pern_login, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/louisephillips-eng/pern_login
- Repository: https://github.com/louisephillips-eng/pern_login

## Overview

This PERN authentication app lets users register or log in, then uses an HTTP-only JWT cookie to restore their session, protect the current-user endpoint, and log out. The repository contains parallel copies of the frontend and backend at the root and under `frontend/` and `backend/`; the graph keeps these implementations distinct rather than assuming they are wired together. The README documents the broader capabilities, while source excerpts show the root and `backend/` server flows. Database wiring from each copy is shown; the relationship between the frontend and a particular backend copy is not established.

Main entry points: [`src/App.jsx`](https://github.com/louisephillips-eng/pern_login/blob/main/src/App.jsx) (App routing), [`frontend/src/App.jsx`](https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/App.jsx) (App routing), [`routes/auth.js`](https://github.com/louisephillips-eng/pern_login/blob/main/routes/auth.js) (Auth routes), [`backend/routes/auth.js`](https://github.com/louisephillips-eng/pern_login/blob/main/backend/routes/auth.js) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root_client["Root frontend"]
  node_root_app["App routing<br/>[App.jsx]"]
  node_root_pages["Auth pages"]
  node_root_nav["Navbar<br/>[navbar.jsx]"]
  node_root_api["API client<br/>[App.jsx]"]
end

subgraph group_frontend_client["Frontend copy"]
  node_front_app["App routing<br/>[App.jsx]"]
  node_front_pages["Auth pages"]
  node_front_nav["Navbar<br/>[Navbar.jsx]"]
  node_front_api["API client<br/>[api.js]"]
end

subgraph group_root_server["Root backend"]
  node_root_server_entry["HTTP server<br/>[server.js]"]
  node_root_auth["Auth routes<br/>[auth.js]"]
  node_root_protect["JWT protection<br/>[auth.js]"]
  node_root_db_config["DB pool<br/>[db.js]"]
end

subgraph group_backend_server["Backend copy"]
  node_back_server_entry["HTTP server<br/>[server.js]"]
  node_back_auth["Auth routes<br/>[auth.js]"]
  node_back_protect["JWT protection<br/>[auth.js]"]
  node_back_db_config["DB pool<br/>[db.js]"]
end

node_user(("User"))
node_root_db[("PostgreSQL")]
node_back_db[("PostgreSQL")]

node_user -.->|"uses"| node_root_app
node_root_app -->|"routes to"| node_root_pages
node_root_app -->|"renders"| node_root_nav
node_root_app -.->|"requests session"| node_root_api
node_user -.->|"uses"| node_front_app
node_front_app -->|"routes to"| node_front_pages
node_front_app -->|"renders"| node_front_nav
node_front_app -->|"requests session"| node_front_api
node_front_pages -->|"sends auth requests"| node_front_api
node_front_nav -->|"sends logout"| node_front_api
node_root_server_entry -->|"mounts routes"| node_root_auth
node_root_auth -->|"protects current user"| node_root_protect
node_root_auth -->|"queries users"| node_root_db_config
node_root_protect -->|"loads user"| node_root_db_config
node_root_db_config -->|"connects pool"| node_root_db
node_back_server_entry -->|"mounts routes"| node_back_auth
node_back_auth -->|"protects current user"| node_back_protect
node_back_auth -->|"queries users"| node_back_db_config
node_back_protect -->|"loads user"| node_back_db_config
node_back_db_config -->|"connects pool"| node_back_db
node_front_api -.->|"calls auth API"| node_back_auth
node_root_api -.->|"calls auth API"| node_root_auth

click node_root_app "https://github.com/louisephillips-eng/pern_login/blob/main/src/App.jsx"
click node_root_pages "https://github.com/louisephillips-eng/pern_login/tree/main/src/pages"
click node_root_nav "https://github.com/louisephillips-eng/pern_login/blob/main/src/components/navbar.jsx"
click node_root_api "https://github.com/louisephillips-eng/pern_login/blob/main/src/App.jsx"
click node_front_app "https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/App.jsx"
click node_front_pages "https://github.com/louisephillips-eng/pern_login/tree/main/frontend/src/pages"
click node_front_nav "https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/components/Navbar.jsx"
click node_front_api "https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/api.js"
click node_root_server_entry "https://github.com/louisephillips-eng/pern_login/blob/main/server.js"
click node_root_auth "https://github.com/louisephillips-eng/pern_login/blob/main/routes/auth.js"
click node_root_protect "https://github.com/louisephillips-eng/pern_login/blob/main/middleware/auth.js"
click node_root_db_config "https://github.com/louisephillips-eng/pern_login/blob/main/config/db.js"
click node_back_server_entry "https://github.com/louisephillips-eng/pern_login/blob/main/backend/server.js"
click node_back_auth "https://github.com/louisephillips-eng/pern_login/blob/main/backend/routes/auth.js"
click node_back_protect "https://github.com/louisephillips-eng/pern_login/blob/main/backend/middleware/auth.js"
click node_back_db_config "https://github.com/louisephillips-eng/pern_login/blob/main/backend/config/db.js"

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_root_app,node_root_pages,node_root_nav,node_root_api,node_user toneBlue
class node_front_app,node_front_pages,node_front_nav,node_front_api,node_root_db,node_back_db toneAmber
class node_root_server_entry,node_root_auth,node_root_protect,node_root_db_config toneMint
class node_back_server_entry,node_back_auth,node_back_protect,node_back_db_config toneRose
```

## Components

### Root frontend

- [App routing](https://github.com/louisephillips-eng/pern_login/blob/main/src/App.jsx): `src/App.jsx`
- [Auth pages](https://github.com/louisephillips-eng/pern_login/tree/main/src/pages): `src/pages`
- [Navbar](https://github.com/louisephillips-eng/pern_login/blob/main/src/components/navbar.jsx): `src/components/navbar.jsx`
- [API client](https://github.com/louisephillips-eng/pern_login/blob/main/src/App.jsx): `src/App.jsx`

### Frontend copy

- [App routing](https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth pages](https://github.com/louisephillips-eng/pern_login/tree/main/frontend/src/pages): `frontend/src/pages`
- [Navbar](https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [API client](https://github.com/louisephillips-eng/pern_login/blob/main/frontend/src/api.js): `frontend/src/api.js`

### Root backend

- [HTTP server](https://github.com/louisephillips-eng/pern_login/blob/main/server.js): `server.js`
- [Auth routes](https://github.com/louisephillips-eng/pern_login/blob/main/routes/auth.js): `routes/auth.js`
- [JWT protection](https://github.com/louisephillips-eng/pern_login/blob/main/middleware/auth.js): `middleware/auth.js`
- [DB pool](https://github.com/louisephillips-eng/pern_login/blob/main/config/db.js): `config/db.js`

### Backend copy

- [HTTP server](https://github.com/louisephillips-eng/pern_login/blob/main/backend/server.js): `backend/server.js`
- [Auth routes](https://github.com/louisephillips-eng/pern_login/blob/main/backend/routes/auth.js): `backend/routes/auth.js`
- [JWT protection](https://github.com/louisephillips-eng/pern_login/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`
- [DB pool](https://github.com/louisephillips-eng/pern_login/blob/main/backend/config/db.js): `backend/config/db.js`

### Other components

- **User**
- **PostgreSQL**
- **PostgreSQL**

## Connections

- User → App routing: uses
- App routing → Auth pages: routes to (evidence: `src/App.jsx`)
- App routing → Navbar: renders (evidence: `src/App.jsx`)
- App routing → API client: requests session (evidence: `src/App.jsx`)
- User → App routing: uses
- App routing → Auth pages: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Navbar: renders (evidence: `frontend/src/App.jsx`)
- App routing → API client: requests session (evidence: `frontend/src/App.jsx`)
- Auth pages → API client: sends auth requests (evidence: `frontend/src/pages/Login.jsx`)
- Navbar → API client: sends logout (evidence: `frontend/src/components/Navbar.jsx`)
- HTTP server → Auth routes: mounts routes (evidence: `server.js`)
- Auth routes → JWT protection: protects current user (evidence: `routes/auth.js`)
- Auth routes → DB pool: queries users (evidence: `routes/auth.js`)
- JWT protection → DB pool: loads user (evidence: `middleware/auth.js`)
- DB pool → PostgreSQL: connects pool (evidence: `config/db.js`)
- HTTP server → Auth routes: mounts routes (evidence: `backend/server.js`)
- Auth routes → JWT protection: protects current user (evidence: `backend/routes/auth.js`)
- Auth routes → DB pool: queries users (evidence: `backend/routes/auth.js`)
- JWT protection → DB pool: loads user (evidence: `backend/middleware/auth.js`)
- DB pool → PostgreSQL: connects pool (evidence: `backend/config/db.js`)
- API client → Auth routes: calls auth API
- API client → Auth routes: calls auth API
