# harshalal02/todo-app architecture

> Architecture diagram of the GitHub repository harshalal02/todo-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshalal02/todo-app
- Repository: https://github.com/harshalal02/todo-app

## Overview

##### Project Type and Purpose
- This is a small full-stack, monolithic Todo application built on Node.js and Express.
- It follows a simple MVC-inspired pattern: Express routes in app.js act as controllers, views/ holds EJS templates for the presentation layer, and a MySQL database stores task data.

##### High-Level Component Breakdown
a. Client / Browser
- Renders HTML/CSS/JS in the user’s browser.
- Sends HTTP requests (GET for index, POST for adding tasks, POST/DELETE for removing tasks).
b. Web Server (Node.js + Express)
- app.js:
– Configures Express, middleware (bodyParser/static).
– Defines route handlers for “/” (render index.ejs with current tasks) and “/add” or “/delete” actions.
– Manages the MySQL connection (using a driver in app.js).
- Static content middleware serves public/styles.css.
c. View Engine (EJS Templates)
- views/index.ejs: loops through tasks array and renders them as HTML.
d. MySQL Database
- Table “todos” holds id, task, created_at.
- app.js performs CRUD operations via SQL queries.

##### Architectural Patterns & Design Principles
- MVC-like separation:
- Model: MySQL schema and queries.
- Controller: app.js route handlers.
- View: EJS templates.
- Single-process, single-repo monolith—no microservices.
- Static assets separated under public/ for caching and CDN suitability.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["User Interface\n(HTML/CSS via EJS)"]:::client
        StylesCSS["styles.css"]:::file
    end

    %% Server Layer
    subgraph "Server Layer"
        Route["Routes & Controllers\n(app.js)"]:::server
        StaticNode["Static File Server\n(public/)"]:::server
        ViewEngine["EJS View Engine\n(views/)"]:::server
        PackageJSON["package.json"]:::file
        PackageLock["package-lock.json"]:::file
        Readme["README.md"]:::file
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MySQL Server\n(todos table)"]:::db
        Schema["nodejs.session.sql"]:::file
    end

    %% Connections: HTTP flows
    Browser -->|"GET /"| Route
    Browser -->|"GET /styles.css"| StaticNode
    StaticNode -->|"serves CSS"| Browser

    Browser -->|"POST /add"| Route
    Browser -->|"POST /delete"| Route

    %% Server to DB
    Route -->|"SELECT * FROM todos"| DB
    DB -->|"rows"| Route
    Route -->|"INSERT INTO todos"| DB
    Route -->|"DELETE FROM todos"| DB

    %% Rendering and Response
    Route -->|"render index.ejs"| ViewEngine
    ViewEngine -->|"HTML response"| Browser
    Route -->|"redirect GET /"| Browser

    %% File and Schema references (docs)
    Route -.-> Schema
    Route -.-> PackageJSON
    Route -.-> PackageLock
    Route -.-> Readme

    %% Click Events
    click StylesCSS "https://github.com/harshalal02/todo-app/blob/main/public/styles.css"
    click ViewEngine "https://github.com/harshalal02/todo-app/blob/main/views/index.ejs"
    click Route "https://github.com/harshalal02/todo-app/blob/main/app.js"
    click StaticNode "https://github.com/harshalal02/todo-app/tree/main/public/"
    click Schema "https://github.com/harshalal02/todo-app/blob/main/nodejs.session.sql"
    click PackageJSON "https://github.com/harshalal02/todo-app/blob/main/package.json"
    click PackageLock "https://github.com/harshalal02/todo-app/blob/main/package-lock.json"
    click Readme "https://github.com/harshalal02/todo-app/blob/main/README.md"

    %% Styles
    classDef client fill:#ffa500,stroke:#333,color:#fff
    classDef server fill:#00bfff,stroke:#333,color:#fff
    classDef db fill:#32cd32,stroke:#333,color:#fff
    classDef file fill:#f9f,stroke:#333,color:#000
```
