# andersona7/task-manager architecture

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

- Interactive diagram: https://gitdiagram.com/andersona7/task-manager
- Repository: https://github.com/andersona7/task-manager

## Overview

This repository is a **monolithic full-stack Node/Express web app** using **server-side rendered EJS** and **MongoDB (Atlas)**. It implements:
- **Session-based auth** (register/login/logout)
- **Email OTP verification** (Nodemailer)
- **Profile image upload** (Multer, stored under `public/images/uploads/...`)
- **Task CRUD** with **authorization/ownership checks**
- A classic “MVC-ish” Express layout: **routes → middleware → controllers (likely inline in routes) → models → DB**

- The **web request lifecycle** (browser → Express routes → middleware → model/DB → EJS response)
- The **two main domains**: **Auth/Profile** and **Tasks**
- The **cross-cutting concerns**: sessions, authorization middleware, email service, file uploads, environment config
- The **deployment/runtime**: Node server on Render + MongoDB Atlas + SMTP provider

##### Entry / composition root
- `app.js`
Central Express app: registers middleware, session, route modules, static assets, view engine (EJS), error handling.

##### Configuration & integrations
- `config/db.js`
- `config/email.js`

##### Middleware layer
- `middleware/isLogged.js`

##### Domain models (data layer)
- `models/user.js`
User schema: credentials, verified flag/OTP, profile image path, timestamps, etc.
- `models/Task.js`
Task schema: owner/userId, status/completed, fields, timestamps.

##### HTTP routing (application layer)
- `routes/authRoutes.js`
Register/login/logout + OTP verification endpoints.
- `routes/taskRoutes.js`
Task CRUD endpoints; must include ownership checks.
- `routes/pageRouters.js`
“Pages” like home/contact/profile + likely renders EJS templates.

From the README, include explicit external dependencies and flows:
- **MongoDB Atlas** as external managed database
- **Render** as hosting runtime for Node/Express
- **Email OTP Verification** via **Nodemailer** (and an external SMTP provider)
- **express-session** (session store: if not explicit, assume in-memory unless there’s a store; represent as “Session Store (Memory/Default)” and annotate “replace with Redis in prod” if desired)
- **Multer** for uploads (filesystem under `public/images/uploads/...`)

**application flow** sequence: registration → OTP email → verify → create user → login → manage tasks.

##### Browser (User)
2. *(Optional)* **CDN / Static hosting** — but here static is served by Express; so just show “Express static `/public`”.

**Application (Render-hosted Node service)**
##### Route Modules
- `authRoutes`
- `taskRoutes`
- `pageRouters`
##### Middleware
- `isLogged` (auth guard)
- `multer` upload handling (even if not in `middleware/`, it exists logically)
- `express-session` (session mgmt)
##### Views (EJS templates)
- `views/auth/*`, `views/tasks/*`, `views/pages/*`, `views/partials/*`
##### Models (Mongoose)
- `User`
- `Task`

**External services**
##### SMTP/Email Provider (used by Nodemailer)

**Storage**
##### File System Storage for Uploads
- `public/images/uploads/dp` (profile images)

##### Architectural patterns (what to call out)
- **Monolith with layered structure**: Routes (controller-like) → Middleware → Models → DB
- **Server-Side Rendering**: EJS as view layer, not SPA
- **Session-based authentication**: cookies + server session
- **Externalized integrations**: `config/db.js`, `config/email.js` adapters
- **Feature-based view organization**: `views/auth`, `views/tasks`, etc.

- Express, Node.js
- EJS
- Mongoose/MongoDB
- express-session
- bcrypt
- Nodemailer (OTP)
- Multer (uploads)

- Browser
- Render-hosted Node/Express app
- MongoDB Atlas
- SMTP provider
- File storage (local disk inside instance)

Inside “Node/Express app”, break out:
- `app.js` composition
- `authRoutes`, `taskRoutes`, `pageRouters`
- `isLogged` middleware + sessions
- `User` + `Task` models
- `config/db` + `config/email`
- `views/*` and `public/*`

##### Register + OTP verify flow
- Browser → authRoutes (register)
- authRoutes → email service → SMTP
- Browser → authRoutes (verify OTP)
- authRoutes → User model → MongoDB

##### Task CRUD with authorization
- Browser → taskRoutes
- taskRoutes → isLogged
- taskRoutes → Task model → MongoDB
- taskRoutes → EJS render tasks pages

##### “As many components as possible” checklist (use this to avoid missing blocks)
- `app.js`
- `routes/authRoutes.js`
- `routes/taskRoutes.js`
- `routes/pageRouters.js`
- `middleware/isLogged.js`
- `config/db.js`
- `config/email.js`
- `models/user.js`
- `models/Task.js`
- `views/auth/*`, `views/tasks/*`, `views/pages/*`, `views/partials/*`
- `public/css/style.css`, `public/js/script.js`
- `public/images/uploads/dp` (profile images)
- MongoDB Atlas
- SMTP provider
- Render hosting environment
- Session mechanism (cookie + session store)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Diagram 1 — High-level container (vertical)
  %% =========================
  subgraph D1["Diagram 1 — High-level containers"]
    direction TB

    U1["Browser (User)"]:::external

    subgraph R1["Render Hosting (Runtime)"]
      direction TB
      N1["Node.js + Express SSR App"]:::host
    end

    MDB1[("MongoDB Atlas")]:::db
    SMTP1["SMTP Provider"]:::externalSvc
    FS1[("Instance File System\n(public/images/uploads/...)")]:::storage
  end

  U1 -->|"HTTPS (pages/forms, cookies)"| N1
  N1 -->|"Mongoose CRUD (users/tasks)"| MDB1
  N1 -->|"SMTP (Nodemailer) send OTP"| SMTP1
  N1 -->|"Write/read uploads (Multer)"| FS1

  %% =========================
  %% Diagram 2 — Internal component diagram (Express internals)
  %% =========================
  subgraph D2["Diagram 2 — Express internal components (monolith)"]
    direction TB

    A1["Express App (app.js)\n- middleware registration\n- route mounting\n- EJS view engine\n- static /public"]:::app

    subgraph CFG["Configuration & Integrations"]
      direction TB
      DB1["DB Connector (config/db.js)\nMongoose connect()"]:::config
      EM1["Email Adapter (config/email.js)\nNodemailer + OTP helpers"]:::config
    end

    subgraph MW["Cross-cutting Middleware"]
      direction TB
      SESS1["express-session\nSession Management"]:::middleware
      AUTHZ1["AuthZ Guard (middleware/isLogged.js)\nRequires session user"]:::middleware
      MUL1["Multer Upload Handler\nprofile image multipart/form-data"]:::middleware
      SS1[("Session Store\nMemory/Default")]:::db
    end

    subgraph RT["Route Modules (Controllers-in-routes)"]
      direction TB
      AR1["Auth Routes (routes/authRoutes.js)\nregister/login/logout/OTP verify"]:::routes
      TR1["Task Routes (routes/taskRoutes.js)\nCRUD + ownership checks"]:::routes
      PR1["Page Routes (routes/pageRouters.js)\nSSR pages: home/contact/profile"]:::routes
    end

    subgraph VIEWS["Presentation (EJS Views)"]
      direction TB
      V0["Views Root (views/)"]:::views
      VA["Auth Views (views/auth/)"]:::views
      VT["Task Views (views/tasks/)"]:::views
      VP["Page Views (views/pages/)"]:::views
      VPAR["Partials (views/partials/)"]:::views
    end

    subgraph PUB["Static Assets & Uploads"]
      direction TB
      P0["Public Root (public/)"]:::static
      CSS1["Stylesheet (public/css/style.css)"]:::static
      JS1["Frontend Script (public/js/script.js)"]:::static
      UP1["Profile Uploads Dir\n(public/images/uploads/dp)"]:::storage
    end

    subgraph MDL["Domain Models (Mongoose)"]
      direction TB
      UM1["User Model (models/user.js)\ncredentials, OTP/verified, profileImage"]:::model
      TM1["Task Model (models/Task.js)\nowner/userId, fields, timestamps"]:::model
    end

    MDB2[("MongoDB Atlas")]:::db
    SMTP2["SMTP Provider"]:::externalSvc
  end

  %% --- Request lifecycle / wiring ---
  U1 -->|"HTTPS request"| A1
  U1 -->|"GET /public/* (static)"| P0

  A1 -->|"mount"| AR1
  A1 -->|"mount"| TR1
  A1 -->|"mount"| PR1

  A1 -->|"use"| SESS1
  SESS1 <-->|"read/write"| SS1

  %% Auth domain
  AR1 -->|"uses"| UM1
  AR1 -->|"send OTP"| EM1
  EM1 -->|"SMTP"| SMTP2
  UM1 -->|"CRUD users"| MDB2
  DB1 -->|"connect"| MDB2
  AR1 -->|"render(view,data)"| VA

  %% Pages domain
  PR1 -->|"render(view,data)"| VP
  PR1 -->|"reads session user"| SESS1

  %% Tasks domain (+ ownership)
  TR1 -->|"guard"| AUTHZ1
  AUTHZ1 -->|"requires session userId"| SESS1
  TR1 -->|"AuthZ check\nTask.owner == session.userId"| TM1
  TR1 -->|"CRUD tasks"| TM1
  TM1 -->|"queries"| MDB2
  TR1 -->|"render(view,data)"| VT

  %% Uploads
  PR1 -->|"profile update\nmultipart/form-data"| MUL1
  MUL1 -->|"write file"| UP1
  PR1 -->|"save image path"| UM1

  %% Views composition
  V0 -->|"includes"| VA
  V0 -->|"includes"| VT
  V0 -->|"includes"| VP
  VA -->|"uses"| VPAR
  VT -->|"uses"| VPAR
  VP -->|"uses"| VPAR

  %% Static assets
  P0 -->|"serves"| CSS1
  P0 -->|"serves"| JS1
  P0 -->|"serves uploads"| UP1

  %% =========================
  %% Diagram 3 — Sequence diagrams (critical flows)
  %% =========================
  subgraph D3["Diagram 3 — Critical flows (sequence)"]
    direction TB

    subgraph SQ1["3.1 Register + OTP verify"]
      direction TB
      S1U["Browser"]:::external
      S1A["authRoutes"]:::routes
      S1E["Email Adapter (Nodemailer)"]:::config
      S1S["SMTP Provider"]:::externalSvc
      S1UM["User Model"]:::model
      S1DB[("MongoDB Atlas")]:::db

      S1U -->|"POST /register"| S1A
      S1A -->|"create pending user / OTP"| S1UM
      S1UM -->|"insert/update"| S1DB
      S1A -->|"send OTP email"| S1E
      S1E -->|"SMTP send"| S1S
      S1U -->|"POST /verify-otp"| S1A
      S1A -->|"validate OTP + mark verified"| S1UM
      S1UM -->|"update"| S1DB
      S1A -->|"set session + redirect"| S1U
    end

    subgraph SQ2["3.2 Task CRUD with authorization"]
      direction TB
      S2U["Browser"]:::external
      S2T["taskRoutes"]:::routes
      S2M["isLogged middleware"]:::middleware
      S2SS["express-session"]:::middleware
      S2TM["Task Model"]:::model
      S2DB[("MongoDB Atlas")]:::db
      S2V["EJS Views (tasks)"]:::views

      S2U -->|"GET/POST /tasks/*"| S2T
      S2T -->|"guard"| S2M
      S2M -->|"read session userId"| S2SS
      S2T -->|"ownership check + CRUD"| S2TM
      S2TM -->|"query/update"| S2DB
      S2T -->|"render(view,data)"| S2V
      S2V -->|"HTML response"| S2U
    end
  end

  %% =========================
  %% Click Events (from component_mapping)
  %% =========================
  click A1 "https://github.com/andersona7/task-manager/blob/main/app.js"
  click DB1 "https://github.com/andersona7/task-manager/blob/main/config/db.js"
  click EM1 "https://github.com/andersona7/task-manager/blob/main/config/email.js"
  click AUTHZ1 "https://github.com/andersona7/task-manager/blob/main/middleware/isLogged.js"
  click UM1 "https://github.com/andersona7/task-manager/blob/main/models/user.js"
  click TM1 "https://github.com/andersona7/task-manager/blob/main/models/Task.js"
  click AR1 "https://github.com/andersona7/task-manager/blob/main/routes/authRoutes.js"
  click TR1 "https://github.com/andersona7/task-manager/blob/main/routes/taskRoutes.js"
  click PR1 "https://github.com/andersona7/task-manager/blob/main/routes/pageRouters.js"
  click V0 "https://github.com/andersona7/task-manager/tree/main/views/"
  click VA "https://github.com/andersona7/task-manager/tree/main/views/auth/"
  click VT "https://github.com/andersona7/task-manager/tree/main/views/tasks/"
  click VP "https://github.com/andersona7/task-manager/tree/main/views/pages/"
  click VPAR "https://github.com/andersona7/task-manager/tree/main/views/partials/"
  click P0 "https://github.com/andersona7/task-manager/tree/main/public/"
  click CSS1 "https://github.com/andersona7/task-manager/blob/main/public/css/style.css"
  click JS1 "https://github.com/andersona7/task-manager/blob/main/public/js/script.js"
  click UP1 "https://github.com/andersona7/task-manager/tree/main/public/images/uploads/dp"

  %% =========================
  %% Styles
  %% =========================
  classDef external fill:#ffffff,stroke:#111827,stroke-width:1.5px,color:#111827
  classDef host fill:#e0f2fe,stroke:#0284c7,stroke-width:1.5px,color:#0c4a6e
  classDef app fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a8a
  classDef routes fill:#bfdbfe,stroke:#1d4ed8,stroke-width:1.5px,color:#1e3a8a
  classDef middleware fill:#c7d2fe,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
  classDef config fill:#bae6fd,stroke:#0ea5e9,stroke-width:1.5px,color:#075985
  classDef model fill:#bbf7d0,stroke:#16a34a,stroke-width:1.5px,color:#14532d
  classDef db fill:#86efac,stroke:#15803d,stroke-width:2px,color:#052e16
  classDef externalSvc fill:#fed7aa,stroke:#f97316,stroke-width:1.5px,color:#7c2d12
  classDef views fill:#fde68a,stroke:#f59e0b,stroke-width:1.5px,color:#78350f
  classDef static fill:#e5e7eb,stroke:#6b7280,stroke-width:1.5px,color:#111827
  classDef storage fill:#d1d5db,stroke:#374151,stroke-width:1.5px,color:#111827
```
