# andrewagain/calculator architecture

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

- Interactive diagram: https://gitdiagram.com/andrewagain/calculator
- Repository: https://github.com/andrewagain/calculator

## Overview

##### Project type and purpose
- This is a single-page web application built with React (created via create-react-app).
- Its sole purpose is to provide a client-side calculator UI and perform arithmetic operations in the browser.

##### File structure
Top-level:
- package.json / package-lock.json – build scripts, dependencies, start/test commands
- public/ – static assets served as-is (index.html, manifest.json)
- src/
– component/ – React presentation components (App, Display, ButtonPanel, Button)
– logic/ – pure JS modules implementing calculator behavior (calculate, operate, isNumber)
– index.js, index.css – entry point and global styles

##### README
- Confirms it’s a create-react-app project, published to GitHub Pages.
- No backend or external API dependencies—pure front-end code.

a. Main components to show
- Browser (user agent)
- Static server / CDN (serving public assets and bundled app)
- React application
– Component layer (App → Display, ButtonPanel → Button)
– Logic layer (calculate.js, operate.js, isNumber.js)
- Build tools (Webpack under the hood via react-scripts)

b. Relationships & interactions
- User clicks Button → ButtonPanel handler → calls calculate()
- calculate() orchestrates calls to isNumber() or operate()
- Result returned to App state → Display updates
- index.js mounts App into root div in public/index.html
- package.json scripts drive build, start, and deploy

c. Architectural patterns & principles
- Component-Based Architecture: UI split into reusable, stateless and stateful React components
- Separation of Concerns: view logic (component/) vs. business logic (logic/)
- Single Source of Truth: App holds calculator state, passed down via props
- Modular code: pure functions for arithmetic operations for easy testing

d. Key technologies & frameworks
- React.js (with Hooks or class components)
- JavaScript ES6 modules
- CSS modules or plain CSS for styling
- create-react-app (Webpack, Babel, react-scripts)
- Jest & React Testing Library for tests

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Infrastructure Layer
    subgraph "Infrastructure" 
        direction TB
        Browser["User's Browser"]:::infra
        CDN["Static Server / CDN"]:::infra
    end

    %% Public Assets
    subgraph "Public Assets" 
        direction TB
        HTML["public/index.html"]:::infra
        Manifest["public/manifest.json"]:::infra
    end

    %% Build and Deployment
    subgraph "Build & CI/CD" 
        direction TB
        PackageJSON["package.json"]:::build
        ReactScripts["react-scripts\n(Webpack/Babel)"]:::build
        Jest["Jest & Testing Library"]:::build
    end

    %% React Application Bundle
    subgraph "React App Bundle" 
        direction TB
        Entry["src/index.js\n(App Entry Point)"]:::infra
        subgraph "Styles" 
            direction TB
            GlobalCSS["src/index.css"]:::styles
            AppCSS["src/component/App.css"]:::styles
            DisplayCSS["src/component/Display.css"]:::styles
            PanelCSS["src/component/ButtonPanel.css"]:::styles
            ButtonCSS["src/component/Button.css"]:::styles
        end
        subgraph "Logic Layer" 
            direction TB
            Calculate["src/logic/calculate.js"]:::logic
            Operate["src/logic/operate.js"]:::logic
            IsNumber["src/logic/isNumber.js"]:::logic
        end
        subgraph "Component Layer" 
            direction TB
            AppComp["App\n(src/component/App.js)"]:::ui
            DisplayComp["Display\n(src/component/Display.js)"]:::ui
            PanelComp["ButtonPanel\n(src/component/ButtonPanel.js)"]:::ui
            ButtonComp["Button\n(src/component/Button.js)"]:::ui
        end
    end

    %% Relationships
    User["User"]:::infra -->|"navigates to"| Browser
    Browser -->|"requests bundle"| CDN
    CDN -->|"serves index.html & assets"| Browser
    Browser -->|"loads JS bundle"| Entry
    Entry --> AppComp
    Entry --> GlobalCSS

    %% Component interactions
    User -->|"clicks button"| ButtonComp
    ButtonComp -->|"onClick calls calculate()"| Calculate
    Calculate -->|"uses isNumber()"| IsNumber
    Calculate -->|"uses operate()"| Operate
    Calculate -->|"returns result"| AppComp
    AppComp -->|"updates state / passes props"| DisplayComp

    %% Build flow
    PackageJSON --> ReactScripts
    ReactScripts -->|"builds bundle"| Entry
    ReactScripts --> GlobalCSS
    Jest -->|"runs tests on"| AppComp
    Jest -->|"runs tests on"| Calculate

    %% Click Events
    click AppComp "https://github.com/andrewagain/calculator/blob/master/src/component/App.js"
    click DisplayComp "https://github.com/andrewagain/calculator/blob/master/src/component/Display.js"
    click PanelComp "https://github.com/andrewagain/calculator/blob/master/src/component/ButtonPanel.js"
    click ButtonComp "https://github.com/andrewagain/calculator/blob/master/src/component/Button.js"
    click Calculate "https://github.com/andrewagain/calculator/blob/master/src/logic/calculate.js"
    click Operate "https://github.com/andrewagain/calculator/blob/master/src/logic/operate.js"
    click IsNumber "https://github.com/andrewagain/calculator/blob/master/src/logic/isNumber.js"
    click Entry "https://github.com/andrewagain/calculator/blob/master/src/index.js"
    click GlobalCSS "https://github.com/andrewagain/calculator/blob/master/src/index.css"
    click AppCSS "https://github.com/andrewagain/calculator/blob/master/src/component/App.css"
    click DisplayCSS "https://github.com/andrewagain/calculator/blob/master/src/component/Display.css"
    click PanelCSS "https://github.com/andrewagain/calculator/blob/master/src/component/ButtonPanel.css"
    click ButtonCSS "https://github.com/andrewagain/calculator/blob/master/src/component/Button.css"
    click HTML "https://github.com/andrewagain/calculator/blob/master/public/index.html"
    click Manifest "https://github.com/andrewagain/calculator/blob/master/public/manifest.json"
    click PackageJSON "https://github.com/andrewagain/calculator/blob/master/package.json"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef logic fill:#DFFFD0,stroke:#333,stroke-width:1px
    classDef infra fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef build fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef styles fill:#FFF2CC,stroke:#333,stroke-width:1px
```
