# dhirajmoudgil/nodejs_loginapp architecture

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

- Interactive diagram: https://gitdiagram.com/dhirajmoudgil/nodejs_loginapp
- Repository: https://github.com/dhirajmoudgil/nodejs_loginapp

## Overview

This is a small Express login application. Users register with account details, the user model hashes passwords and saves accounts to MongoDB, and users can log in through Passport’s local strategy to access the authenticated homepage; logout clears the login session. Express serves the login, registration, and homepage templates, along with static assets. The README is empty, so the map is based on the supplied tree and source excerpts; the registration validation has apparent variable-name inconsistencies, so no validation-to-error-view flow is shown.

Main entry points: [`routes/users.js`](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/users.js) (User routes), [`app.js`](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/app.js) (Express app), [`routes/index.js`](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/index.js) (Homepage route), [`models/users.js`](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/models/users.js) (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_app["Express app<br/>[app.js]"]
  node_home["Homepage route<br/>[index.js]"]
end

subgraph group_auth["Authentication"]
  node_user_routes["User routes<br/>[users.js]"]
  node_passport["Passport local auth<br/>[users.js]"]
  node_session["Login session<br/>[app.js]"]
end

subgraph group_data["User data"]
  node_user_model["User model<br/>[users.js]"]
  node_mongo[("MongoDB")]
end

subgraph group_ui["User interface"]
  node_login_view["Login view<br/>[login.handlebars]"]
  node_register_view["Registration view"]
  node_home_view["Homepage view<br/>[index.handlebars]"]
  node_layout["Shared layout<br/>[layout.handlebars]"]
  node_static_assets["Static assets"]
end

node_visitor(("Visitor"))

node_visitor -->|"sends requests"| node_app
node_app -->|"mounts /users"| node_user_routes
node_app -->|"mounts /"| node_home
node_app -->|"initializes"| node_session
node_app -->|"serves files"| node_static_assets
node_user_routes -->|"renders login"| node_login_view
node_user_routes -->|"renders registration"| node_register_view
node_user_routes -->|"dispatches login"| node_passport
node_passport -->|"looks up and checks"| node_user_model
node_user_routes -->|"creates account"| node_user_model
node_user_model -->|"reads and writes"| node_mongo
node_passport -->|"serializes user"| node_session
node_session -->|"reloads user"| node_user_model
node_home -->|"checks authentication"| node_session
node_home -->|"redirects unauthenticated"| node_user_routes
node_home -->|"renders homepage"| node_home_view
node_login_view -->|"uses layout"| node_layout
node_register_view -->|"uses layout"| node_layout
node_home_view -->|"uses layout"| node_layout

click node_app "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/app.js"
click node_home "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/index.js"
click node_user_routes "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/users.js"
click node_passport "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/users.js"
click node_session "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/app.js"
click node_user_model "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/models/users.js"
click node_login_view "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/login.handlebars"
click node_register_view "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/register.handlebars"
click node_home_view "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/index.handlebars"
click node_layout "https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/layouts/layout.handlebars"
click node_static_assets "https://github.com/dhirajmoudgil/nodejs_loginapp/tree/master/public"

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_home toneBlue
class node_user_routes,node_passport,node_session toneAmber
class node_user_model,node_mongo toneMint
class node_login_view,node_register_view,node_home_view,node_layout,node_static_assets toneRose
class node_visitor toneIndigo
```

## Components

### Web app

- [Express app](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/app.js): `app.js`
- [Homepage route](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/index.js): `routes/index.js`

### Authentication

- [User routes](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/users.js): `routes/users.js`
- [Passport local auth](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/routes/users.js): `routes/users.js`
- [Login session](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/app.js): `app.js`

### User data

- [User model](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/models/users.js): `models/users.js`
- **MongoDB**

### User interface

- [Login view](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/login.handlebars): `views/login.handlebars`
- [Registration view](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/register.handlebars): `views/register.handlebars`
- [Homepage view](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/index.handlebars): `views/index.handlebars`
- [Shared layout](https://github.com/dhirajmoudgil/nodejs_loginapp/blob/master/views/layouts/layout.handlebars): `views/layouts/layout.handlebars`
- [Static assets](https://github.com/dhirajmoudgil/nodejs_loginapp/tree/master/public): `public`

### Other components

- **Visitor**

## Connections

- Visitor → Express app: sends requests
- Express app → User routes: mounts /users
- Express app → Homepage route: mounts /
- Express app → Login session: initializes
- Express app → Static assets: serves files
- User routes → Login view: renders login
- User routes → Registration view: renders registration
- User routes → Passport local auth: dispatches login
- Passport local auth → User model: looks up and checks
- User routes → User model: creates account
- User model → MongoDB: reads and writes
- Passport local auth → Login session: serializes user
- Login session → User model: reloads user
- Homepage route → Login session: checks authentication
- Homepage route → User routes: redirects unauthenticated
- Homepage route → Homepage view: renders homepage
- Login view → Shared layout: uses layout
- Registration view → Shared layout: uses layout
- Homepage view → Shared layout: uses layout
