How actionsdemos/calculator works
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