# arinjay-srivastava/notepad_project_web architecture

> Architecture diagram of the GitHub repository arinjay-srivastava/notepad_project_web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arinjay-srivastava/notepad_project_web
- Repository: https://github.com/arinjay-srivastava/notepad_project_web

## Overview

##### Project Type and Purpose
- NotePad is a full-stack web application for user-authenticated note management.
- Frontend: static HTML/CSS/JS in `public/`.
- Backend: Node.js with Express.js in the project root (`index.js`), routing logic under `server/routes/`, data models under `server/models/`.
- Persistence: MySQL database accessed via the MySQL2 driver and configured by dotenv.

##### Key Architectural Patterns
- MVC-like separation:
- Model layer in `server/models/` (ORM-style objects for `User` and `Note`).
- Controller layer in `server/routes/` (Express routers for user and note endpoints).
- View layer as static assets in `public/`.
- RESTful API: CRUD endpoints for notes and authentication.
- Soft-delete pattern for notes and user accounts (business rule).

- Client Browser
- Static UI pages: Login.html, Register.html, notes.html, index.html.
- Frontend JS modules: `user.js`, `note.js`, `note.js` (public/note.js), CSS styling.
- HTTP/API Layer
- Express.js server (`index.js`) listening on `PORT`.
- Middleware: body-parsing, session/auth (if used).
- Route Handlers
- `/api/user` router (register, login, soft-delete).
- `/api/note` router (create, read, update, soft-delete).
- Model/Data Access
- `db_connect.js` establishes connection pool to MySQL.
- `user.js` and `note.js` define methods for CRUD plus soft-delete logic.
- MySQL Database
- Tables: `users`, `notes` with one-to-many relationship (user_id foreign key).
- External Configuration
- `.env` for host, user, password, database name, port.
- Development Tools
- Nodemon for auto-restarts, dotenv for env loading, MySQL2 driver.

##### Relationships and Data Flow
- Browser → HTTP(S) requests → Express server
- Express middleware → route-specific controllers → model methods → MySQL queries
- Query results returned up chain → controller → JSON → browser → DOM updates

- Clear labels on each component (e.g., “Login Page”, “User Router”, “Note Model”).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Static Assets)"
        direction TB
        Login["Login Page"]:::frontend
        Register["Register Page"]:::frontend
        NotesPage["Notes Page"]:::frontend
        Home["Home Page"]:::frontend
        UserJS["User Logic (user.js)"]:::frontend
        NoteJS["Note Logic (note.js)"]:::frontend
        StyleCSS["CSS Styling (style.css)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express & Models)"
        direction TB
        Server["Express Server (index.js)"]:::backend
        UserRouter["User Router (/api/user)"]:::backend
        NoteRouter["Note Router (/api/note)"]:::backend
        DBConnect["DB Connection (db_connect.js)"]:::backend
        UserModel["User Model (user.js)"]:::backend
        NoteModel["Note Model (note.js)"]:::backend
        Package["Configuration (package.json)"]:::docs
        README["README & ER Diagram (README.md)"]:::docs
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        MySQL["MySQL Database"]:::database
    end

    %% Frontend to Server (Static)
    Login -->|GET /login.html| Server
    Register -->|GET /register.html| Server
    NotesPage -->|GET /notes.html| Server
    Home -->|GET /index.html| Server
    StyleCSS -->|GET /style.css| Server
    UserJS -->|GET /user.js| Server
    NoteJS -->|GET /note.js| Server

    %% API Requests
    UserJS -->|POST /api/user/login| UserRouter
    UserJS -->|POST /api/user/register| UserRouter
    UserJS -->|DELETE /api/user| UserRouter

    NoteJS -->|POST /api/note| NoteRouter
    NoteJS -->|GET /api/note| NoteRouter
    NoteJS -->|PUT /api/note| NoteRouter
    NoteJS -->|DELETE /api/note| NoteRouter

    %% Routing to Models
    UserRouter -->|calls| UserModel
    NoteRouter -->|calls| NoteModel

    %% Models to DB
    UserModel -->|SQL Queries| DBConnect
    NoteModel -->|SQL Queries| DBConnect
    DBConnect -->|connection pool| MySQL

    %% Docs and Config
    Server -->|uses| Package
    Server -->|references| README

    %% Legend
    subgraph "Legend"
        direction LR
        UI["Rectangle: UI Component"]:::frontend
        SRV["Rounded: Server Module"]:::backend
        DB["Cylinder: Database"]:::database
        DOC["Document: Config/Docs"]:::docs
    end

    %% Click Events
    click Login "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/Login.html"
    click Register "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/Register.html"
    click NotesPage "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/notes.html"
    click Home "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/index.html"
    click UserJS "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/user.js"
    click NoteJS "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/note.js"
    click StyleCSS "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/public/style.css"
    click Server "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/index.js"
    click UserRouter "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/server/routes/user.js"
    click NoteRouter "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/server/routes/note.js"
    click DBConnect "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/server/models/db_connect.js"
    click UserModel "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/server/models/user.js"
    click NoteModel "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/server/models/note.js"
    click Package "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/package.json"
    click README "https://github.com/arinjay-srivastava/notepad_project_web/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef database fill:#FFA500,stroke:#000,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#000,stroke-width:1px
```
