# nipunadodan/salary-lk architecture

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

- Interactive diagram: https://gitdiagram.com/nipunadodan/salary-lk
- Repository: https://github.com/nipunadodan/salary-lk

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    BrowserBox["Browser"]
    subgraph "Static Asset Server (CDN)"
        AS["Static Asset Server (serves index.html, css/, js/)"]:::external
    end
    BrowserBox -->|"HTTP GET"| AS

    subgraph Browser
        direction TB
        subgraph "UI Layer"
            HTML["index.html"]:::ui
            CSS["css/styles.css"]:::ui
        end

        subgraph "Application Logic"
            MAIN["js/main.js"]:::logic
            subgraph "Calculator Modules"
                BASIC["js/calculator-basic.js"]:::logic
                REVERSE["js/calculator-reverse.js"]:::logic
                DEDUCTION["js/calculator-deduction.js"]:::logic
            end
            CORE["js/tax-calculator.js"]:::logic
            subgraph "Utilities"
                CACHE["js/cache.js (LRU)"]:::util
                UTILS["js/utils.js"]:::util
            end
            CHART["js/chart-handler.js"]:::logic
            THEME["js/theme-handler.js"]:::logic
            SHARE["js/share-handler.js"]:::logic
        end

        subgraph "Browser Storage & APIs"
            STORAGE[(localStorage)]:::storage
            URLAPI{{"URL & Clipboard APIs"}}:::storage
        end
    end

    CHARTJS["Chart.js CDN"]:::external

    %% Data Flows
    MAIN -->|"invoke calculate()"| BASIC
    MAIN -->|"invoke calculate()"| REVERSE
    MAIN -->|"invoke calculate()"| DEDUCTION
    BASIC -->|"calls tax logic"| CORE
    REVERSE -->|"calls tax logic"| CORE
    DEDUCTION -->|"calls tax logic"| CORE
    CORE -->|"memoized via"| CACHE
    MAIN -->|"update DOM"| UTILS
    MAIN -->|"prepare chart data"| CHART
    CHART -->|"render chart()"| CHARTJS
    MAIN -->|"toggle theme"| THEME
    THEME -->|"read/write"| STORAGE
    MAIN -->|"share action"| SHARE
    SHARE -->|"serialize state"| URLAPI

    %% Click Events
    click HTML "https://github.com/nipunadodan/salary-lk/blob/main/index.html"
    click CSS "https://github.com/nipunadodan/salary-lk/blob/main/css/styles.css"
    click MAIN "https://github.com/nipunadodan/salary-lk/blob/main/js/main.js"
    click BASIC "https://github.com/nipunadodan/salary-lk/blob/main/js/calculator-basic.js"
    click REVERSE "https://github.com/nipunadodan/salary-lk/blob/main/js/calculator-reverse.js"
    click DEDUCTION "https://github.com/nipunadodan/salary-lk/blob/main/js/calculator-deduction.js"
    click CORE "https://github.com/nipunadodan/salary-lk/blob/main/js/tax-calculator.js"
    click CACHE "https://github.com/nipunadodan/salary-lk/blob/main/js/cache.js"
    click UTILS "https://github.com/nipunadodan/salary-lk/blob/main/js/utils.js"
    click CHART "https://github.com/nipunadodan/salary-lk/blob/main/js/chart-handler.js"
    click THEME "https://github.com/nipunadodan/salary-lk/blob/main/js/theme-handler.js"
    click SHARE "https://github.com/nipunadodan/salary-lk/blob/main/js/share-handler.js"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,color:#000
    classDef logic fill:#90EE90,stroke:#000,color:#000
    classDef util fill:#FFA500,stroke:#000,color:#000
    classDef external fill:#D3D3D3,stroke:#000,color:#000
    classDef storage fill:#EEE8AA,stroke:#000,color:#000
```
