# muhdhanish/session_cookies architecture

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

## Overview

This Express application supports signup, login, logout, and an authenticated dashboard. Signup validates input, hashes the password, and saves a user; login validates credentials and establishes session state; authentication middleware guards the dashboard and login/signup pages; logout destroys the session. Express renders EJS views, while MongoDB stores user records and sessions. The sampled index.js shows these runtime relationships; the README documents the browser cookie/session behavior and protected routes.

Main entry points: [`index.js`](https://github.com/muhdhanish/session_cookies/blob/main/index.js) (Express app), [`models/user.js`](https://github.com/muhdhanish/session_cookies/blob/main/models/user.js) (User model), [`views/dashboard.ejs`](https://github.com/muhdhanish/session_cookies/blob/main/views/dashboard.ejs) (Dashboard view), [`views/login.ejs`](https://github.com/muhdhanish/session_cookies/blob/main/views/login.ejs) (Login view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_express["Express app<br/>[index.js]"]
  node_session["Session middleware<br/>[index.js]"]
end

subgraph group_identity["Authentication"]
  node_access["Access guards<br/>[index.js]"]
  node_signup["Signup handler<br/>[index.js]"]
  node_login["Login handler<br/>[index.js]"]
  node_logout["Logout handler<br/>[index.js]"]
end

subgraph group_persistence["MongoDB persistence"]
  node_user_model["User model<br/>[user.js]"]
  node_users_db[("User records<br/>[user.js]")]
  node_session_store[("Session store<br/>[index.js]")]
end

subgraph group_presentation["Rendered pages"]
  node_dashboard["Dashboard view<br/>[dashboard.ejs]"]
  node_login_view["Login view<br/>[login.ejs]"]
  node_signup_view["Signup view<br/>[signup.ejs]"]
end

node_browser(("Browser"))

node_browser -->|"sends requests"| node_express
node_express -->|"routes through"| node_access
node_access -->|"checks session"| node_session
node_express -->|"dispatches signup"| node_signup
node_express -->|"dispatches login"| node_login
node_express -->|"dispatches logout"| node_logout
node_signup -->|"creates user"| node_user_model
node_user_model -->|"persists records"| node_users_db
node_login -->|"looks up user"| node_user_model
node_express -->|"configures middleware"| node_session
node_session -->|"stores sessions"| node_session_store
node_browser -->|"carries session cookie"| node_session
node_logout -->|"destroys session"| node_session
node_express -->|"renders dashboard"| node_dashboard
node_express -->|"renders login"| node_login_view
node_express -->|"renders signup"| node_signup_view

click node_express "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_access "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_signup "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_login "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_logout "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_session "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_user_model "https://github.com/muhdhanish/session_cookies/blob/main/models/user.js"
click node_users_db "https://github.com/muhdhanish/session_cookies/blob/main/models/user.js"
click node_session_store "https://github.com/muhdhanish/session_cookies/blob/main/index.js"
click node_dashboard "https://github.com/muhdhanish/session_cookies/blob/main/views/dashboard.ejs"
click node_login_view "https://github.com/muhdhanish/session_cookies/blob/main/views/login.ejs"
click node_signup_view "https://github.com/muhdhanish/session_cookies/blob/main/views/signup.ejs"

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_express,node_session,node_browser toneBlue
class node_access,node_signup,node_login,node_logout toneAmber
class node_user_model,node_users_db,node_session_store toneMint
class node_dashboard,node_login_view,node_signup_view toneRose
```

## Components

### Web application

- [Express app](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`
- [Session middleware](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`

### Authentication

- [Access guards](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`
- [Signup handler](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`
- [Login handler](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`
- [Logout handler](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`

### MongoDB persistence

- [User model](https://github.com/muhdhanish/session_cookies/blob/main/models/user.js): `models/user.js`
- [User records](https://github.com/muhdhanish/session_cookies/blob/main/models/user.js): `models/user.js`
- [Session store](https://github.com/muhdhanish/session_cookies/blob/main/index.js): `index.js`

### Rendered pages

- [Dashboard view](https://github.com/muhdhanish/session_cookies/blob/main/views/dashboard.ejs): `views/dashboard.ejs`
- [Login view](https://github.com/muhdhanish/session_cookies/blob/main/views/login.ejs): `views/login.ejs`
- [Signup view](https://github.com/muhdhanish/session_cookies/blob/main/views/signup.ejs): `views/signup.ejs`

### Other components

- **Browser**

## Connections

- Browser → Express app: sends requests (evidence: `README.md`)
- Express app → Access guards: routes through (evidence: `index.js`)
- Access guards → Session middleware: checks session (evidence: `index.js`)
- Express app → Signup handler: dispatches signup (evidence: `index.js`)
- Express app → Login handler: dispatches login (evidence: `index.js`)
- Express app → Logout handler: dispatches logout (evidence: `index.js`)
- Signup handler → User model: creates user (evidence: `index.js`)
- User model → User records: persists records (evidence: `models/user.js`)
- Login handler → User model: looks up user (evidence: `index.js`)
- Express app → Session middleware: configures middleware (evidence: `index.js`)
- Session middleware → Session store: stores sessions (evidence: `index.js`)
- Browser → Session middleware: carries session cookie (evidence: `README.md`)
- Logout handler → Session middleware: destroys session (evidence: `index.js`)
- Express app → Dashboard view: renders dashboard (evidence: `index.js`)
- Express app → Login view: renders login (evidence: `index.js`)
- Express app → Signup view: renders signup (evidence: `index.js`)
