# jeswanthjohn/vanilla-js-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/jeswanthjohn/vanilla-js-calculator
- Repository: https://github.com/jeswanthjohn/vanilla-js-calculator

## Overview

##### Project type and purpose
- This is a single-page, frontend-only “Vanilla JS Calculator” built with plain HTML, CSS, and JavaScript.
- Its purpose is to demonstrate DOM manipulation, input validation, keyboard accessibility, and user feedback without any external frameworks.

##### File structure
- Top-level files:
- index.html – Defines the calculator’s UI structure (buttons, inputs, result display).
- styles.css – Contains layout rules, responsive breakpoints, and interaction feedback styles.
- app.js – Houses the event listeners, input validation logic, arithmetic operations, edge-case handling, and DOM updates.
- README.md – Project overview, features, tech stack, and potential enhancements.
- No backend, no database, no external service integrations—this is a pure client-side widget.

##### README for additional insights
- Emphasizes clear separation of concerns (HTML for structure, CSS for style, JS for logic).
- Lists supported operations, keyboard shortcuts, and error-handling features.
- Mentions responsive design and potential future enhancements (history, themes, scientific ops).

##### Main components and interactions
a. User (Browser)
b. UI Layer (index.html + styles.css)
– Input fields & buttons
– Result / error display
c. JavaScript Logic Layer (app.js)
– Event Handlers (click, keypress)
– Validation Module (NaN, Infinity, divide-by-zero)
– Calculation Module (add, subtract, multiply, divide)
– Formatter (rounding decimals)
– DOM Updater (inject result or error messages)

Relationships / data flow:
User Action → UI Layer → Event Handlers → Validation → Calculation → Formatter → DOM Updater → UI Layer → User Feedback

##### Architectural patterns and design principles
- Separation of concerns: UI vs. styling vs. logic.
- Modular functions in app.js (validation, calculation, formatting).
- Unidirectional data flow: user input → processing → UI update.
- Progressive enhancement: keyboard support layered on top of click events.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entities and Layers
    User["User / Browser"]:::external

    subgraph "UI Layer"
        HTML["HTML Structure\n(index.html)"]:::ui
        CSS["Styles/CSS\n(styles.css)"]:::ui
    end

    subgraph "JavaScript Logic Layer"
        EH["Event Handlers\n(app.js)"]:::logic
        VM["Validation Module\n(app.js)"]:::logic
        CM["Calculation Module\n(app.js)"]:::logic
        FM["Formatter\n(app.js)"]:::logic
        DU["DOM Updater\n(app.js)"]:::logic
    end

    Cloud["Hosting (Static Site)"]:::external
    Doc["Documentation\n(README.md)"]:::external

    %% Data Flow
    User -->|interacts with| HTML
    HTML -->|triggers| EH
    EH -->|validates input| VM
    VM -->|performs operations| CM
    CM -->|formats result| FM
    FM -->|updates DOM| DU
    DU -->|renders output| HTML

    CSS -.->|styles| HTML

    Cloud -->|serves| HTML
    Cloud -->|serves| CSS
    Cloud -->|serves| EH
    Cloud -->|hosts| Doc

    %% Click Events
    click HTML "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/index.html"
    click CSS "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/styles.css"
    click EH "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/app.js"
    click VM "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/app.js"
    click CM "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/app.js"
    click FM "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/app.js"
    click DU "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/app.js"
    click Doc "https://github.com/jeswanthjohn/vanilla-js-calculator/blob/main/README.md"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085;
    classDef logic fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
