# actionsdemos/calculator architecture

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

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

## Overview

##### Project type and purpose
- This is a simple full-stack Node.js demonstration project (“Calculator.js”) that exposes REST APIs for integer arithmetic and serves a static HTML/CSS frontend.
- It includes a Mocha/Chai test suite (with JUnit-style reporters for CI), and is containerizable via Docker.

##### File structure
- Top-level files:
- server.js – the entry point that configures Express, static serving, and routing
- Dockerfile/.dockerignore – containerization assets
- package.json / package-lock.json – dependency and script definitions
- api/
- routes.js – defines HTTP endpoints (e.g. GET/POST /add, /subtract, etc.)
- controllers/arithmeticController.js – request handlers that parse inputs and call the model
- models/arithmeticModel.js – pure arithmetic logic
- public/
- index.html + default.css – static UI delivered by Express
- test/
- arithmetic.js + helpers.js + config.json – Mocha test cases and environment configs

##### README for additional insights
- REST API footprint only supports integer arithmetic
- Test suite is wired to produce JUnit-style XML for Azure DevOps or any CI
- No external database or third-party arithmetic service; all computation is in-process

a. Main components
1. Client (Browser/UI)
2. Node.js / Express Server
– Static File Server (public/)
– REST API Layer (routes.js)
– Controller Layer (arithmeticController)
– Business Logic Layer (arithmeticModel)
3. Test Harness & CI
4. Container / Deployment (Docker)

b. Relationships & interactions
- Client → HTTP GET / → Express serves index.html + default.css
- Client → AJAX/HTTP POST /add (or other endpoints) → routes.js
- routes.js → arithmeticController → arithmeticModel → return result
- Controller → JSON response → Client renders result
- `npm test` → Mocha/Chai executes test/arithmetic.js → outputs JUnit XML
- Docker build → bundles server.js, public/, api/, package.json → deploy container

c. Architectural patterns & principles
- Layered architecture (Presentation → API → Controller → Model)
- Single Node.js process (no microservices)
- Clear separation of concerns: static assets vs. API code vs. business logic vs. tests

d. Key technologies
- Node.js + Express
- Mocha, Chai, mocha-junit-reporters for testing
- Docker for containerization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Browser UI\n(index.html, default.css)"]:::client

    %% Docker Container Boundary
    subgraph "Docker Container"
        direction TB

        %% Node.js Server Components
        subgraph "Node.js Server"
            direction TB
            Entry["Entry Point\n(server.js)"]:::server
            Static["Static File Handler\n(public/)"]:::server
            Routing["Routing Module\n(api/routes.js)"]:::server
            Controller["Controller Layer\n(arithmeticController.js)"]:::server
            Model["Business Logic Layer\n(arithmeticModel.js)"]:::server
            DockerAssets["Containerization Assets\n(Dockerfile, .dockerignore)"]:::server
            Package["Dependency & Script Definitions\n(package.json, package-lock.json)"]:::server
        end
    end

    %% Test & CI
    Test["Test Suite & CI\n(arithmetic.js, helpers.js, config.json)"]:::test
    Reporter["JUnit XML Output"]:::test

    %% Interactions
    Client -->|GET /| Static
    Client -->|POST /add etc| Routing
    Routing -->|calls| Controller
    Controller -->|calls| Model
    Model -->|returns result| Controller
    Controller -->|res.json| Client

    Test -->|npm test| Entry
    Test -->|requires| Model
    Test -->|reports| Reporter

    DockerAssets -->|build context| Entry
    Package -->|defines deps/scripts| Entry

    %% Click Events
    click Client "https://github.com/actionsdemos/calculator/blob/master/public/index.html"
    click Entry "https://github.com/actionsdemos/calculator/blob/master/server.js"
    click Routing "https://github.com/actionsdemos/calculator/blob/master/api/routes.js"
    click Controller "https://github.com/actionsdemos/calculator/blob/master/api/controllers/arithmeticController.js"
    click Model "https://github.com/actionsdemos/calculator/blob/master/api/models/arithmeticModel.js"
    click Test "https://github.com/actionsdemos/calculator/blob/master/test/arithmetic.js"
    click DockerAssets "https://github.com/actionsdemos/calculator/tree/master/Dockerfile"
    click Package "https://github.com/actionsdemos/calculator/blob/master/package.json"

    %% Styles
    classDef client fill:#D0E1FF,stroke:#333,stroke-width:1px
    classDef server fill:#DFF2BF,stroke:#333,stroke-width:1px
    classDef test fill:#FFE4B5,stroke:#333,stroke-width:1px
    class Client client
    class Entry,Static,Routing,Controller,Model,DockerAssets,Package server
    class Test,Reporter test
```
