# 512kbb/todo-list-sockets architecture

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

- Interactive diagram: https://gitdiagram.com/512kbb/todo-list-sockets
- Repository: https://github.com/512kbb/todo-list-sockets

## Overview

##### Project type and purpose
- This is a small full-stack Node.js application (“todo-list-sockets”) that serves a single-page HTML front end and provides a real-time to-do list API via Express.js and Socket.io, persisting data in a local SQLite database.

##### File structure
- Top-level:
- index.js – ENTRYPOINT: sets up Express HTTP server & Socket.io
- index.html – CLIENT UI: served as static file at route “/”
- package.json / package-lock.json – dependency & scripts
- db/ directory:
– db.js – database helper: initializes and queries SQLite
- todo.db – SQLite file storing tasks
- .gitignore, readme.md
- No separate “frontend” or “backend” folders; the code is a small monolith combining HTTP routes, WebSocket handlers, and database logic.

##### README for additional insights
- Confirms use of Node.js 22.x, Express, Socket.io, SQLite.
- Describes four REST endpoints (/tasks GET, POST, PUT, DELETE).
- Mentions that on client connect, the server sends the full task list over WebSocket for simplicity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Browser Client" 
        direction TB
        B["Browser Client (index.html)"]:::client
    end

    %% Server Layer
    subgraph "Server (Node.js)" 
        direction TB
        subgraph "REST API (Express)" 
            direction TB
            REST_GET["GET /tasks"] 
            REST_POST["POST /tasks"] 
            REST_PUT["PUT /tasks/:id"] 
            REST_DELETE["DELETE /tasks/:id"] 
        end
        subgraph "WebSocket (Socket.io)"
            direction TB
            WS_INIT["on 'tasks:init'"] 
            WS_UPDATE["on 'task:update' → broadcast"]
        end
        DB_MODULE["DB Access Module (db/db.js)"]:::dbmod
        METADATA["package.json"]:::metadata
    end

    %% Database Store
    DB["todo.db (SQLite)"]:::dbstore

    %% HTTP interactions
    B -->|"GET /tasks"| REST_GET
    B -->|"POST /tasks {title,desc}"| REST_POST
    B -->|"PUT /tasks/:id"| REST_PUT
    B -->|"DELETE /tasks/:id"| REST_DELETE

    REST_GET -->|"queryTasks() "| DB_MODULE
    REST_POST -->|"createTask() "| DB_MODULE
    REST_PUT -->|"updateTask() "| DB_MODULE
    REST_DELETE -->|"deleteTask() "| DB_MODULE

    DB_MODULE -->|"SQL queries"| DB

    %% WebSocket interactions
    B ---|<i>connect</i>| WS_INIT
    WS_INIT -->|"loadAllTasks() "| DB_MODULE
    DB_MODULE -->|"SELECT *"| DB
    DB -->|"taskList"| WS_INIT
    B ---|"emit task changes"| WS_UPDATE
    WS_UPDATE -->|"DB changes"| DB_MODULE
    DB_MODULE -->|"SQL updates"| DB
    WS_UPDATE -->|"broadcast update"| B

    %% Click events
    click B "https://github.com/512kbb/todo-list-sockets/blob/master/index.html"
    click REST_GET "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click REST_POST "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click REST_PUT "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click REST_DELETE "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click WS_INIT "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click WS_UPDATE "https://github.com/512kbb/todo-list-sockets/blob/master/index.js"
    click DB_MODULE "https://github.com/512kbb/todo-list-sockets/blob/master/db/db.js"
    click DB "https://github.com/512kbb/todo-list-sockets/blob/master/todo.db"
    click METADATA "https://github.com/512kbb/todo-list-sockets/blob/master/package.json"

    %% Styles
    classDef client fill:#e0f7e9,stroke:#2d7c4e,color:#2d7c4e;
    classDef server fill:#e8f1fa,stroke:#1a3c72,color:#1a3c72;
    classDef dbmod fill:#dfe7fd,stroke:#4a6fa5,color:#4a6fa5;
    classDef metadata fill:#f5f5f5,stroke:#999999,color:#555555;
    classDef dbstore fill:#eeeeee,stroke:#888888,color:#333333;
```
