How nipunadodan/salary-lk works
Project Type & Purpose
• This is a client-side, single-page web application (no backend API) for calculating and visualizing Sri Lankan salary details.
• Its core functions are: take-home salary calculation, reverse gross-salary lookup, and deduction-based calculations, all rendered in a responsive UI with light/dark themes and shareable URLs.
Main Architectural Components
A. Static Asset Server (or CDN)
• Hosts: index.html, css/styles.css, all js/*.js
• Delivers resources over HTTP/HTTPS
B. Browser Client
1. UI Layer
– HTML (index.html)
– CSS (styles.css with media queries & theme classes)
2. Application Logic (JavaScript Modules)
• main.js (initializes app, wires up event listeners)
• Calculator Modules
– calculator-basic.js
– calculator-reverse.js
– calculator-deduction.js
• Core Engine
– tax-calculator.js (progressive bracket logic)
• Performance Utilities
– cache.js (LRU memoization wrapper)
– utils.js (formatting, debouncing, DOM helpers)
• Visualization
– chart-handler.js (prepares data, calls Chart.js)
– External: Chart.js library (loaded via CDN)
• UI Enhancements
– theme-handler.js (reads/writes localStorage, toggles CSS classes)
– share-handler.js (encodes/decodes URL state, clipboard API)
C. Browser Storage & APIs
– localStorage (theme persistence)
– Clipboard & URL APIs (share functionality)
Relationships & Data Flow
1. User interacts with a form in the UI → event listener in main.js
2. main.js dispatches to the appropriate calculator module
3. Calculator module calls tax-calculator.js → result is memoized via cache.js
4. Result flows back to main.js → updates the DOM via utils.js
5. For chart views: main.js passes result data to chart-handler.js → config passed to Chart.js → rendered canvas
6. Theme toggles invoke theme-handler.js → updates CSS classes + localStorage
7. Share button invokes share-handler.js → serializes current form state into URL, writes to clipboard
Key Architectural Patterns & Principles
• Module Pattern: Each JS file exposes a clear public API.
• Event-Driven: main.js orchestrates modules through DOM events.
• Memoization (LRU): cache.js wraps expensive tax computations.
• Binary Search: Efficient reverse calculation embedded in calculator-reverse.js.
• Responsive Design: CSS adapts layout at breakpoints.