# raushani03/inotebook architecture

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

## Overview

##### Project type + purpose (from tree + README)
This is a **full-stack “notes” web application**:

- **Frontend:** Create React App (CRA) SPA in `/src` + `/public`, with routing (`react-router-dom`) and state management via **React Context** (`src/context/*`).
- **Backend:** Node.js + Express API in `/backend`, with **MongoDB** persistence via Mongoose models (`backend/models/User.js`, `backend/models/Note.js`).
- **Auth:** There is a dedicated auth route (`backend/routes/auth.js`) and an auth middleware (`backend/middleware/fetchUser.js`) which strongly implies **JWT-protected endpoints**.
- **Notes CRUD:** Dedicated notes route (`backend/routes/notes.js`).
- **Dev orchestration:** `concurrently` + `nodemon` mentioned in README to run frontend + backend together.

##### Frontend (CRA)
Key areas:
- `src/App.js` is the app shell (routing + layout).
- `src/Components/*` are UI + page-level components:
- Auth-related: `Login.js`, `Signup.js`
- Notes-related: `Notes.js`, `Noteitem.js`, `AddNote.js`, `Home.js`
- Other: `NavBar.js`, `About.js`, `Alert.js`
- `src/context/*` indicates app-wide state:
- `NoteContext.js` + `notes/NoteState.js` → global notes state, likely encapsulating API calls
- `AlertContext.js` + `Alerts/AlertState.js` → global alert/toast state

##### Backend (Express + Mongo)
Key areas:
- `backend/index.js` is the server entrypoint (Express app, route registration).
- `backend/db.js` handles DB connection (Mongo URI from `.env` typically).
- `backend/models/*` are Mongo/Mongoose schemas:
- `User.js` (users, password hash, etc.)
- `Note.js` (notes owned by user)
- `backend/routes/*` are HTTP API modules:
- `auth.js` (signup/login, token issuance)
- `notes.js` (CRUD endpoints; probably requires auth)
- `backend/middleware/fetchUser.js` is the security gate (extract/verify token, attach user to request).

##### React SPA (CRA)
- Router (`react-router-dom`)
- Context Providers
- NoteState (Notes domain)
- AlertState (UI notifications)
- Page components (Login/Signup/Notes)
##### Express API Server (Node.js)
- Middleware: `fetchUser` (JWT auth)
- DB layer: Mongoose models (`User`, `Note`)
##### Environment/Secrets
- `.env` supplying Mongo connection string + JWT secret (likely)

Optional but useful:
- **Static hosting / build artifact**
- CRA `build/` output served by a CDN/static host (in production)
- **Dev tooling**

##### User → React SPA
- UI events (login, create note, edit note)
##### React SPA → Express API
- REST calls (fetch/create/update/delete notes)
- Auth calls (signup/login)
- Header: `Authorization: Bearer <token>` (or whatever scheme is used)
##### Express API → Middleware (fetchUser)
- Notes endpoints pass through middleware to validate token
##### Express API → Mongoose Models → MongoDB
- Auth route uses `User` model
- Notes route uses `Note` model (and user ownership)
##### Express API → React SPA
- JSON responses (notes list, success/failure, auth token)
##### React SPA internal
- Components → Context state → Components
- Context state → API calls → Context state update
- AlertState triggered on success/failure

##### Architectural patterns to highlight
- **SPA + REST**: frontend is purely client-side; backend is JSON API.
- **Middleware-based security**: authentication is enforced centrally via `fetchUser`.
- **Domain separation**:
- Backend: routes (controller-like) + models (data) + middleware (cross-cutting)
- Frontend: components (views) + context/state (domain logic + side effects)

##### What to label precisely (so it’s “accurate”, not generic)
Use labels that map to real files/modules:

- **Frontend**
- “React SPA (Create React App)”
- “Routing: react-router-dom”
- “Notes state: src/context/notes/NoteState.js”
- “Alerts state: src/context/Alerts/AlertState.js”
- “UI: src/Components/* (Login, Signup, Notes, AddNote, Noteitem, Alert)”
- **Backend**
- “Express server: backend/index.js”
- “Mongo connection: backend/db.js”
- “Auth routes: backend/routes/auth.js”
- “Notes routes: backend/routes/notes.js”
- “JWT middleware: backend/middleware/fetchUser.js”
- “Mongoose models: backend/models/User.js, Note.js”
- **Data stores**
- “MongoDB (notes, users collections)”
- **Secrets**
- “.env (MONGO_URI, JWT_SECRET, etc.)” (name the variables once you confirm them)

- **Blue rectangles:** runtime containers (Browser SPA, API Server, MongoDB)
- `HTTPS JSON`
- `Authorization: Bearer JWT`
- `Mongoose queries`

- Left: **User/Browser**
- Inside Browser: **React SPA**
- App.js + Router
- NoteState/AlertState contexts
- Key pages (Login/Signup/Notes)
- Middle: **Express API (backend/index.js)**
- auth.js
- notes.js (protected by fetchUser)
- Right: **MongoDB**
- Users collection, Notes collection (or simply “users, notes”)
- Top/Bottom annotations:
- `.env` provides DB URI + JWT secret
- `concurrently` runs both servers in dev

##### Don’t overthink it: split into as many components as possible (practical checklist)

- `src/App.js`
- `src/Components/Login.js`
- `src/Components/Signup.js`
- `src/Components/Notes.js`
- `src/Components/AddNote.js`
- `src/context/notes/NoteState.js`
- `backend/index.js`
- `backend/routes/auth.js`
- `backend/routes/notes.js`
- `backend/middleware/fetchUser.js`
- `backend/models/User.js`
- `backend/models/Note.js`
- `backend/db.js`
- MongoDB

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% ============ External Actor ============
  User(("User\n(Browser)")):::actor

  %% ============ Frontend / Browser ============
  subgraph "Client (Browser Runtime)"
    direction TB

    PublicHTML["public/index.html\n(HTML shell, external scripts e.g. FontAwesome)"]:::static

    subgraph "React SPA (Create React App)"
      direction TB

      Entry["src/index.js\n(Bootstrap React app)"]:::frontend
      App["src/App.js\n(App shell: layout + routing)"]:::frontend

      Router["Routing\n(react-router-dom)"]:::frontend

      subgraph "Context Providers (Global State)"
        direction TB
        NoteCtx["Notes Context\n(src/context/NoteContext.js)"]:::state
        NoteState["Notes State Provider\n(src/context/notes/NoteState.js)"]:::state
        AlertCtx["Alerts Context\n(src/context/AlertContext.js)"]:::state
        AlertState["Alerts State Provider\n(src/context/Alerts/AlertState.js)"]:::state
      end

      subgraph "UI Components (src/Components/*)"
        direction TB
        ComponentsDir["Components Directory\n(src/Components/)"]:::ui

        NavBar["NavBar\n(src/Components/NavBar.js)"]:::ui
        Home["Home\n(src/Components/Home.js)"]:::ui
        About["About\n(src/Components/About.js)"]:::ui

        Login["Login\n(src/Components/Login.js)"]:::ui
        Signup["Signup\n(src/Components/Signup.js)"]:::ui

        Notes["Notes\n(src/Components/Notes.js)"]:::ui
        AddNote["AddNote\n(src/Components/AddNote.js)"]:::ui
        NoteItem["Noteitem\n(src/Components/Noteitem.js)"]:::ui

        AlertUI["Alert\n(src/Components/Alert.js)"]:::ui
      end
    end

    DevRunner["Dev Runner\n(concurrently + nodemon)"]:::dev
    RootPkg["Root package.json\n(scripts/deps)"]:::dev
  end

  %% ============ Backend / API ============
  subgraph "Server (Node.js / Express)"
    direction TB

    API["Express API Server\n(backend/index.js)"]:::api

    subgraph "Routes"
      direction TB
      AuthRoute["/api/auth\n(backend/routes/auth.js)"]:::api
      NotesRoute["/api/notes\n(backend/routes/notes.js)"]:::api
    end

    subgraph "Middleware"
      direction TB
      FetchUser["JWT Auth Middleware\n(backend/middleware/fetchUser.js)"]:::security
    end

    subgraph "Data Access (Mongoose)"
      direction TB
      DBConn["Mongo Connection\n(backend/db.js)"]:::data
      UserModel["User Model\n(backend/models/User.js)"]:::data
      NoteModel["Note Model\n(backend/models/Note.js)"]:::data
    end

    BackendPkg["backend/package.json\n(scripts/deps)"]:::dev
  end

  %% ============ Data Store ============
  subgraph "Persistence"
    direction TB
    Mongo[(MongoDB<br/>users, notes collections)]:::db
  end

  %% ============ Config / Secrets ============
  Env[".env\n(MONGO_URI, JWT_SECRET, etc.)"]:::config

  %% ============ Flows ============
  User -->|"UI_events"| PublicHTML
  PublicHTML -->|"loads_SPA_bundle"| Entry
  Entry -->|"renders"| App
  App -->|"uses"| Router

  %% Component usage (vertical)
  App -->|"layout"| NavBar
  Router -->|"route_to"| Home
  Router -->|"route_to"| About
  Router -->|"route_to"| Login
  Router -->|"route_to"| Signup
  Router -->|"route_to"| Notes

  Notes -->|"compose"| AddNote
  Notes -->|"render_list"| NoteItem
  App -->|"shows"| AlertUI

  %% Context wiring
  App -->|"wraps_with"| NoteState
  App -->|"wraps_with"| AlertState
  NoteState -->|"provides"| NoteCtx
  AlertState -->|"provides"| AlertCtx

  %% State/event signals (dotted)
  Login -.->|"dispatch_alert"| AlertState
  Signup -.->|"dispatch_alert"| AlertState
  Notes -.->|"dispatch_alert"| AlertState
  AddNote -.->|"mutate_notes_state"| NoteState
  NoteItem -.->|"mutate_notes_state"| NoteState

  %% API calls from state layer
  NoteState -->|"HTTPS_JSON\nCRUD_notes\nAuthorization:Bearer_JWT"| API
  Login -->|"HTTPS_JSON\nlogin"| API
  Signup -->|"HTTPS_JSON\nsignup"| API

  %% Server internal routing
  API -->|"routes"| AuthRoute
  API -->|"routes"| NotesRoute

  %% Auth path
  AuthRoute -->|"read/write"| UserModel

  %% Notes path (protected)
  NotesRoute -->|"guard"| FetchUser
  FetchUser -->|"attaches_user_to_req"| NotesRoute
  NotesRoute -->|"read/write"| NoteModel

  %% DB layer
  API -->|"init_db"| DBConn
  DBConn -->|"connect"| Mongo
  UserModel -->|"Mongoose_queries"| Mongo
  NoteModel -->|"Mongoose_queries"| Mongo

  %% Env dependencies
  Env -->|"provides_MONGO_URI"| DBConn
  Env -->|"provides_JWT_SECRET"| FetchUser

  %% Dev-only orchestration
  RootPkg -->|"scripts_run"| DevRunner
  DevRunner -.->|"starts"| Entry
  DevRunner -.->|"starts_with_nodemon"| API
  BackendPkg -.->|"deps_for"| API

  %% ============ Click Events (mapped paths) ============
  click App "https://github.com/raushani03/inotebook/blob/main/src/App.js"
  click Entry "https://github.com/raushani03/inotebook/blob/main/src/index.js"
  click PublicHTML "https://github.com/raushani03/inotebook/blob/main/public/index.html"
  click ComponentsDir "https://github.com/raushani03/inotebook/tree/main/src/Components/"
  click Login "https://github.com/raushani03/inotebook/blob/main/src/Components/Login.js"
  click Signup "https://github.com/raushani03/inotebook/blob/main/src/Components/Signup.js"
  click Notes "https://github.com/raushani03/inotebook/blob/main/src/Components/Notes.js"
  click AddNote "https://github.com/raushani03/inotebook/blob/main/src/Components/AddNote.js"
  click NoteItem "https://github.com/raushani03/inotebook/blob/main/src/Components/Noteitem.js"
  click Home "https://github.com/raushani03/inotebook/blob/main/src/Components/Home.js"
  click NavBar "https://github.com/raushani03/inotebook/blob/main/src/Components/NavBar.js"
  click About "https://github.com/raushani03/inotebook/blob/main/src/Components/About.js"
  click AlertUI "https://github.com/raushani03/inotebook/blob/main/src/Components/Alert.js"
  click NoteCtx "https://github.com/raushani03/inotebook/blob/main/src/context/NoteContext.js"
  click NoteState "https://github.com/raushani03/inotebook/blob/main/src/context/notes/NoteState.js"
  click AlertCtx "https://github.com/raushani03/inotebook/blob/main/src/context/AlertContext.js"
  click AlertState "https://github.com/raushani03/inotebook/blob/main/src/context/Alerts/AlertState.js"
  click API "https://github.com/raushani03/inotebook/blob/main/backend/index.js"
  click DBConn "https://github.com/raushani03/inotebook/blob/main/backend/db.js"
  click AuthRoute "https://github.com/raushani03/inotebook/blob/main/backend/routes/auth.js"
  click NotesRoute "https://github.com/raushani03/inotebook/blob/main/backend/routes/notes.js"
  click FetchUser "https://github.com/raushani03/inotebook/blob/main/backend/middleware/fetchUser.js"
  click UserModel "https://github.com/raushani03/inotebook/blob/main/backend/models/User.js"
  click NoteModel "https://github.com/raushani03/inotebook/blob/main/backend/models/Note.js"
  click Env "https://github.com/raushani03/inotebook/blob/main/.env"
  click RootPkg "https://github.com/raushani03/inotebook/blob/main/package.json"
  click BackendPkg "https://github.com/raushani03/inotebook/blob/main/backend/package.json"

  %% ============ Styles ============
  classDef actor fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#e2e8f0
  classDef frontend fill:#1d4ed8,stroke:#93c5fd,stroke-width:1.5px,color:#ffffff
  classDef ui fill:#2563eb,stroke:#bfdbfe,stroke-width:1px,color:#ffffff
  classDef state fill:#0ea5e9,stroke:#7dd3fc,stroke-width:1px,color:#03202b
  classDef api fill:#7c3aed,stroke:#c4b5fd,stroke-width:1.5px,color:#ffffff
  classDef security fill:#be123c,stroke:#fecdd3,stroke-width:1.5px,color:#ffffff
  classDef data fill:#334155,stroke:#cbd5e1,stroke-width:1px,color:#ffffff
  classDef db fill:#16a34a,stroke:#86efac,stroke-width:2px,color:#052e16
  classDef config fill:#f59e0b,stroke:#fde68a,stroke-width:1.5px,color:#1f2937
  classDef dev fill:#64748b,stroke:#e2e8f0,stroke-dasharray:4 3,stroke-width:1px,color:#0b1220
  classDef static fill:#0b7285,stroke:#99e9f2,stroke-width:1.2px,color:#e6fcff
```
