# dumbwareio/dumbpad architecture

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

- Interactive diagram: https://gitdiagram.com/dumbwareio/dumbpad
- Repository: https://github.com/dumbwareio/dumbpad

## Overview

##### Main Components
- Client (Frontend): Represented by the files in the “public” directory. This includes HTML pages (index.html, login.html), CSS (styles.css), vanilla JavaScript (app.js and various manager scripts like operations.js, cursor-manager.js, etc.), and the service-worker.js for PWA support.
- Server (Backend): The central Node.js/Express application defined in server.js. This component handles routing, API endpoints, auto-saving logic, PIN verification, and middleware for CORS, cookie parsing, and rate limiting.
- File-based Storage: The "data" directory (mentioned in the README) where notes’ content (stored in .txt files) and metadata (notepads.json) are persisted. Emphasize that this is critical for data persistence and must not be deleted during updates.
- Docker & Deployment Infrastructure: Incorporate Dockerfile, docker-compose.yml, and related configuration files (e.g., .env.example, nodemon.json) indicating containerized deployment and environment-specific configurations.
- Supplemental Scripts: Include additional scripts (found in the “scripts” directory) that are used for tasks such as generating PNGs, creating a PWA manifest, and managing CORS settings.

##### Relationships and Interactions
- If using Docker, illustrate the containerization: a Docker container running the Node.js application, with a volume mapping to the “data” directory to persist notes.
- Optionally, represent external services such as rate limiting middleware and security (e.g., Express security middleware) within the backend component.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Emphasize that the client (static assets and browser-side logic) is kept distinctly separate from the server’s API logic.
- Service Containerization: Illustrate how Docker encapsulates the entire application and ensures environment consistency across deployments.
- File-based Persistence: Unlike traditional relational databases, the architecture relies on simple file I/O for note storage, which should be clearly noted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Client["Client (Browser / Public Assets)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Backend["Backend (Node.js / Express Server)"]:::backend
        Storage(("File Storage (Data Directory)")):::storage
        Scripts["Supplemental Scripts"]:::scripts
    end

    %% Docker & Deployment Infrastructure
    subgraph "Docker & Deployment Infrastructure"
        Dockerfile["Dockerfile"]:::docker
        DockerCompose["docker-compose.yml"]:::docker
        Env[".env.example"]:::docker
        Nodemon["nodemon.json"]:::docker
    end

    %% Relationships between layers
    Client -->|"HTTPcalls"| Backend
    Backend -->|"Read/Write"| Storage
    Backend -->|"Utilizes"| Scripts

    %% Docker files interactions with Backend and Storage
    Dockerfile -->|"Builds"| Backend
    DockerCompose -->|"Deploys"| Backend
    DockerCompose -->|"VolumeMapping"| Storage
    Env -->|"Configures"| Backend
    Nodemon -->|"Monitors"| Backend

    %% Click events for mapped components
    click Client "https://github.com/dumbwareio/dumbpad/tree/main/public/"
    click Backend "https://github.com/dumbwareio/dumbpad/blob/main/server.js"
    click Dockerfile "https://github.com/dumbwareio/dumbpad/tree/main/Dockerfile"
    click DockerCompose "https://github.com/dumbwareio/dumbpad/blob/main/docker-compose.yml"
    click Env "https://github.com/dumbwareio/dumbpad/blob/main/.env.example"
    click Nodemon "https://github.com/dumbwareio/dumbpad/blob/main/nodemon.json"
    click Scripts "https://github.com/dumbwareio/dumbpad/tree/main/scripts/"

    %% Styles
    classDef frontend fill:#a2d9ce,stroke:#000,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#000,stroke-width:2px;
    classDef storage fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef docker fill:#d2b4de,stroke:#000,stroke-width:2px;
    classDef scripts fill:#f5b7b1,stroke:#000,stroke-width:2px;
```
