# chetansharma2428/authwith-turnstile architecture

> Architecture diagram of the GitHub repository chetansharma2428/authwith-turnstile, 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/chetansharma2428/authwith-turnstile
- Repository: https://github.com/chetansharma2428/authwith-turnstile

## Overview

This is a full-stack, user-isolated Todo app. Users sign up or log in with Turnstile verification, then manage tasks in a protected dashboard; JWT access tokens and rotating HttpOnly refresh cookies maintain sessions. The map preserves the documented auth, bot-protection, and CRUD stages. Some subsystem links come from README documentation or SOURCE INDEX references; unsampled implementations are represented only where the tree supports a path.

Main entry points: [`frontend/src/pages/Home.jsx`](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Home.jsx) (Todo dashboard), [`backend/src/controllers/authController.js`](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/controllers/authController.js) (Auth controller), [`frontend/src/pages/Login.jsx`](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Login.jsx) (Login page), [`frontend/src/pages/Signup.jsx`](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Signup.jsx) (Signup page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_app["Client routes<br/>[App.jsx]"]
  node_login["Login page<br/>[Login.jsx]"]
  node_signup["Signup page<br/>[Signup.jsx]"]
  node_widget["Turnstile widget"]
  node_home["Todo dashboard<br/>[Home.jsx]"]
  node_navbar["Navigation<br/>[Navbar.jsx]"]
  node_todoform["Todo form<br/>[TodoForm.jsx]"]
  node_todoitem["Todo item<br/>[TodoItem.jsx]"]
end

subgraph group_auth["Authentication"]
  node_authstate["Auth state<br/>[AuthContext.jsx]"]
  node_authhook["Auth hook<br/>[useAuth.js]"]
  node_authservice["Auth API service<br/>[authService.js]"]
  node_api["HTTP client<br/>[api.js]"]
  node_authcontroller["Auth controller<br/>[authController.js]"]
  node_authmiddleware["JWT middleware<br/>[authMiddleware.js]"]
  node_tokenutils["Token utilities<br/>[tokenUtils.js]"]
  node_turnstile["Turnstile verifier<br/>[turnstile.js]"]
end

subgraph group_server["API server"]
  node_serverapp["Express app<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_todoroutes["Todo routes<br/>[todoRoutes.js]"]
end

subgraph group_tasks["Todo management"]
  node_todoservice["Todo API service<br/>[todoService.js]"]
  node_todoctrl["Todo controller<br/>[todoController.js]"]
end

subgraph group_persistence["Persistence"]
  node_userdb[("User records<br/>[User.js]")]
  node_tododb[("Todo records<br/>[Todo.js]")]
  node_dbconfig["Mongo connection<br/>[db.js]"]
end

node_user(("User"))
node_mongoservice[("MongoDB")]
node_cloudflare["Cloudflare"]

node_user -->|"submits credentials"| node_login
node_user -->|"submits registration"| node_signup
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_signup
node_app -->|"guards route"| node_home
node_login -->|"uses auth"| node_authhook
node_signup -->|"uses auth"| node_authhook
node_login -->|"renders"| node_widget
node_signup -->|"renders"| node_widget
node_authhook -->|"reads context"| node_authstate
node_authstate -->|"calls"| node_authservice
node_authservice -->|"sends requests"| node_api
node_api -->|"calls auth endpoints"| node_authroutes
node_api -->|"calls todo endpoints"| node_todoroutes
node_home -->|"reads user"| node_authhook
node_home -->|"renders"| node_navbar
node_home -->|"renders"| node_todoform
node_home -->|"renders"| node_todoitem
node_home -->|"calls"| node_todoservice
node_todoservice -->|"sends requests"| node_api
node_serverapp -->|"mounts"| node_authroutes
node_serverapp -->|"mounts"| node_todoroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authroutes -->|"protects profile"| node_authmiddleware
node_todoroutes -->|"protects routes"| node_authmiddleware
node_todoroutes -->|"dispatches"| node_todoctrl
node_authcontroller -->|"reads and writes"| node_userdb
node_authcontroller -->|"generates and verifies"| node_tokenutils
node_authcontroller -->|"verifies token"| node_turnstile
node_turnstile -->|"verifies remotely"| node_cloudflare
node_authmiddleware -->|"verifies access token"| node_tokenutils
node_authmiddleware -->|"loads user"| node_userdb
node_todoctrl -->|"reads and writes"| node_tododb
node_dbconfig -.->|"connects"| node_mongoservice

click node_app "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/App.jsx"
click node_login "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Login.jsx"
click node_signup "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Signup.jsx"
click node_widget "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TurnstileWidget.jsx"
click node_authstate "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/context/AuthContext.jsx"
click node_authhook "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/hooks/useAuth.js"
click node_authservice "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/authService.js"
click node_api "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/api.js"
click node_home "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Home.jsx"
click node_navbar "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/Navbar.jsx"
click node_todoform "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TodoForm.jsx"
click node_todoitem "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TodoItem.jsx"
click node_todoservice "https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/todoService.js"
click node_serverapp "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/app.js"
click node_authroutes "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/routes/authRoutes.js"
click node_todoroutes "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/routes/todoRoutes.js"
click node_authcontroller "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/controllers/authController.js"
click node_authmiddleware "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/middleware/authMiddleware.js"
click node_tokenutils "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/utils/tokenUtils.js"
click node_turnstile "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/utils/turnstile.js"
click node_todoctrl "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/controllers/todoController.js"
click node_userdb "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/models/User.js"
click node_tododb "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/models/Todo.js"
click node_dbconfig "https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/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_app,node_login,node_signup,node_widget,node_home,node_navbar,node_todoform,node_todoitem,node_user toneBlue
class node_authstate,node_authhook,node_authservice,node_api,node_authcontroller,node_authmiddleware,node_tokenutils,node_turnstile,node_mongoservice toneAmber
class node_serverapp,node_authroutes,node_todoroutes toneMint
class node_todoservice,node_todoctrl toneRose
class node_userdb,node_tododb,node_dbconfig,node_cloudflare toneIndigo
```

## Components

### React client

- [Client routes](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Login page](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Signup page](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Signup.jsx): `frontend/src/pages/Signup.jsx`
- [Turnstile widget](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TurnstileWidget.jsx): `frontend/src/components/TurnstileWidget.jsx`
- [Todo dashboard](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Navigation](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [Todo form](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TodoForm.jsx): `frontend/src/components/TodoForm.jsx`
- [Todo item](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/components/TodoItem.jsx): `frontend/src/components/TodoItem.jsx`

### Authentication

- [Auth state](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Auth hook](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/hooks/useAuth.js): `frontend/src/hooks/useAuth.js`
- [Auth API service](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/authService.js): `frontend/src/services/authService.js`
- [HTTP client](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`
- [Auth controller](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [JWT middleware](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/middleware/authMiddleware.js): `backend/src/middleware/authMiddleware.js`
- [Token utilities](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/utils/tokenUtils.js): `backend/src/utils/tokenUtils.js`
- [Turnstile verifier](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/utils/turnstile.js): `backend/src/utils/turnstile.js`

### API server

- [Express app](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/app.js): `backend/src/app.js`
- [Auth routes](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [Todo routes](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/routes/todoRoutes.js): `backend/src/routes/todoRoutes.js`

### Todo management

- [Todo API service](https://github.com/chetansharma2428/authwith-turnstile/blob/main/frontend/src/services/todoService.js): `frontend/src/services/todoService.js`
- [Todo controller](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/controllers/todoController.js): `backend/src/controllers/todoController.js`

### Persistence

- [User records](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/models/User.js): `backend/src/models/User.js`
- [Todo records](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/models/Todo.js): `backend/src/models/Todo.js`
- [Mongo connection](https://github.com/chetansharma2428/authwith-turnstile/blob/main/backend/src/config/db.js): `backend/src/config/db.js`

### Other components

- **User**
- **MongoDB**
- **Cloudflare**

## Connections

- User → Login page: submits credentials (evidence: `README.md`)
- User → Signup page: submits registration (evidence: `README.md`)
- Client routes → Login page: routes to (evidence: `frontend/src/App.jsx`)
- Client routes → Signup page: routes to (evidence: `frontend/src/App.jsx`)
- Client routes → Todo dashboard: guards route (evidence: `frontend/src/App.jsx`)
- Login page → Auth hook: uses auth (evidence: `frontend/src/pages/Login.jsx`)
- Signup page → Auth hook: uses auth (evidence: `frontend/src/pages/Signup.jsx`)
- Login page → Turnstile widget: renders (evidence: `frontend/src/pages/Login.jsx`)
- Signup page → Turnstile widget: renders (evidence: `frontend/src/pages/Signup.jsx`)
- Auth hook → Auth state: reads context (evidence: `frontend/src/hooks/useAuth.js`)
- Auth state → Auth API service: calls (evidence: `frontend/src/context/AuthContext.jsx`)
- Auth API service → HTTP client: sends requests (evidence: `frontend/src/services/authService.js`)
- HTTP client → Auth routes: calls auth endpoints (evidence: `README.md`)
- HTTP client → Todo routes: calls todo endpoints (evidence: `README.md`)
- Todo dashboard → Auth hook: reads user (evidence: `frontend/src/pages/Home.jsx`)
- Todo dashboard → Navigation: renders (evidence: `frontend/src/pages/Home.jsx`)
- Todo dashboard → Todo form: renders (evidence: `frontend/src/pages/Home.jsx`)
- Todo dashboard → Todo item: renders (evidence: `frontend/src/pages/Home.jsx`)
- Todo dashboard → Todo API service: calls (evidence: `frontend/src/pages/Home.jsx`)
- Todo API service → HTTP client: sends requests (evidence: `frontend/src/services/todoService.js`)
- Express app → Auth routes: mounts (evidence: `backend/src/app.js`)
- Express app → Todo routes: mounts (evidence: `backend/src/app.js`)
- Auth routes → Auth controller: dispatches (evidence: `backend/src/routes/authRoutes.js`)
- Auth routes → JWT middleware: protects profile (evidence: `backend/src/routes/authRoutes.js`)
- Todo routes → JWT middleware: protects routes (evidence: `backend/src/routes/todoRoutes.js`)
- Todo routes → Todo controller: dispatches (evidence: `backend/src/routes/todoRoutes.js`)
- Auth controller → User records: reads and writes (evidence: `backend/src/controllers/authController.js`)
- Auth controller → Token utilities: generates and verifies (evidence: `backend/src/controllers/authController.js`)
- Auth controller → Turnstile verifier: verifies token (evidence: `backend/src/controllers/authController.js`)
- Turnstile verifier → Cloudflare: verifies remotely (evidence: `README.md`)
- JWT middleware → Token utilities: verifies access token (evidence: `backend/src/middleware/authMiddleware.js`)
- JWT middleware → User records: loads user (evidence: `backend/src/middleware/authMiddleware.js`)
- Todo controller → Todo records: reads and writes (evidence: `backend/src/controllers/todoController.js`)
- Mongo connection → MongoDB: connects
