# iamvatsal/book-notes-webapp architecture

> Architecture diagram of the GitHub repository iamvatsal/book-notes-webapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iamvatsal/book-notes-webapp
- Repository: https://github.com/iamvatsal/book-notes-webapp

## Overview

##### Project Overview
- This is a full-stack web application designed to manage book notes. It uses Node.js with Express on the backend, EJS for templating on the frontend, PostgreSQL as its database, and integrates authentication (both local and Google OAuth) using Passport.js.
- The application follows a loosely MVC-like pattern with clear separation between routing, controller (business logic), view (EJS templates), and static assets.

##### Main Components
a. Client/Browser Layer:
- Web Browser (User Interface): Representing how users interact with the application via HTML/CSS/JavaScript and EJS-rendered pages.

b. Server/Application Layer:
- Main Server (index.js): The central entry point for the Node.js/Express application.
- Controller Layer: Represent the controllers (books.controller.js, login.controller.js, etc.) that process the business logic and interact with both views and the database.
- Views Layer: Indicate the EJS templates in the views folder, outlining the rendering of pages for the client.
- Authentication Module: Highlight Passport.js usage for both local strategy and Google OAuth integration. This can be depicted as a subcomponent that intercepts requests (particularly those routed for login, signup, and logout).

c. Data/Database Layer:
- SQL Queries: A note or smaller component showing that queries.sql is used for the initial setup of these tables.

##### Relationships and Interactions
- The Routing Layer to the Controller Layer, which handles the logic.
- The Controllers to the Database Layer to perform CRUD operations.
- Also, illustrate that the Views are rendered by the controllers before sending HTML back to the client.

##### Architectural Patterns and Design Principles
- Separation of concerns (routing, control logic, presentation).
- Layered architecture where the presentation layer (views and static assets) is kept distinct from application logic (controllers/routes) and data access (PostgreSQL via db.js).
- Authentication as a cross-cutting concern managed via Passport.js.

##### Technologies and Frameworks
- Node.js with Express.js on the backend.
- PostgreSQL as the relational database.
- EJS templating for dynamic HTML.
- Static assets managed under the public directory.
- Passport.js for authentication.
- Additional libraries like Bootstrap for UI enhancement can also be indicated in the frontend section.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/Browser Layer
    subgraph "Client/Browser Layer"
        Browser["Web Browser (UI)"]:::frontend
        EJS["EJS Templates & Views"]:::frontend
        Assets["Static Assets"]:::frontend
    end

    %% Server/Application Layer
    subgraph "Server/Application Layer"
        Server["Main Server (index.js)"]:::backend
        subgraph "Routing Layer"
            Routes["Route Handlers"]:::backend
        end
        subgraph "Controller Layer"
            Controllers["Controllers"]:::backend
            Auth["Authentication Module (Passport.js)"]:::backend
        end
    end

    %% Data/Database Layer
    subgraph "Data/Database Layer"
        DBConnect["Database Connection (db.js)"]:::database
        Queries["SQL Setup (queries.sql)"]:::database
        DB["PostgreSQL Database"]:::database
    end

    %% Relationships and Interactions
    Browser -->|"HTTP_Request"| Server
    Server -->|"Delegate_to_Routes"| Routes
    Routes -->|"Invoke_Controller"| Controllers
    Controllers -->|"Call_Authentication"| Auth
    Controllers -->|"Query_DB"| DBConnect
    DBConnect -->|"Run_Queries"| Queries
    DBConnect -->|"ConnectsTo_DB"| DB
    Controllers -->|"Render_View"| EJS
    Assets -->|"Served_To"| Browser

    %% Click Events for Component Mapping
    click EJS "https://github.com/iamvatsal/book-notes-webapp/tree/main/App/views"
    click Assets "https://github.com/iamvatsal/book-notes-webapp/tree/main/App/public"
    click Server "https://github.com/iamvatsal/book-notes-webapp/blob/main/App/index.js"
    click Routes "https://github.com/iamvatsal/book-notes-webapp/tree/main/App/routes"
    click Controllers "https://github.com/iamvatsal/book-notes-webapp/tree/main/App/controller"
    click DBConnect "https://github.com/iamvatsal/book-notes-webapp/blob/main/App/db.js"
    click Queries "https://github.com/iamvatsal/book-notes-webapp/blob/main/App/queries.sql"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
