# gopi514-chand/power-bill-management-system architecture

> Architecture diagram of the GitHub repository gopi514-chand/power-bill-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gopi514-chand/power-bill-management-system
- Repository: https://github.com/gopi514-chand/power-bill-management-system

## Overview

#### Purpose and Entry Points
PowerBill is a browser-based electricity-billing system: users calculate bills from meter readings, persist them, and review/export billing history. Primary UI entry points are `billing_calculator.html` and `billing_reports.html`; `index.html` may serve as a landing/navigation page. The backend starts from `server.js` via npm scripts in `package.json`.

#### Calculator Workflow
The calculator UI and client logic collect consumer, meter, tariff, fee, and GST inputs. It derives consumed units, energy charges, subtotal, tax, and final bill, then supports print/save actions.
- `billing_calculator.html`
- `billing_calculator.js`
- `billing_calculator.css`

The calculated bill payload is the boundary between browser-side computation/display and persistent storage. If the API is unavailable, the intended resilience path is browser LocalStorage backup.

#### Reports and Record Management
The reporting UI retrieves stored bills, applies consumer/meter/date filters, presents paginated records and aggregate metrics, exposes details/deletion, and creates CSV exports.
- `billing_reports.html`
- `billing_reports.js`

This is the operational read-management surface over the same bill record model produced by the calculator.

#### API and Server Boundary
`server.js` is the Node.js/Express service boundary between static/browser clients and MySQL. Its documented resource API supports bill creation, list/detail/consumer retrieval, update/delete, plus overall and monthly report summaries. The server should own request validation, database access, and API error handling rather than trusting client-calculated values.
- `server.js`
- `package.json`
- `.env.example`

#### Persistence Model
MySQL is the primary system of record. Schema setup, indexes/sample data, and the central `bills` entity are defined in `database_setup.sql`. A bill stores identity and meter metadata, calculation inputs and derived monetary fields, dates, and payment status; this enables both invoice reconstruction and report aggregation.
- `database_setup.sql`
- `.env.example`

#### Runtime and Infrastructure
The deployed runtime is Node.js (README requires v14+) with Express and a MySQL 5.7+ server. Database host, user, password, database name, and HTTP port are environment-provided through `.env` based on `.env.example`. Bootstrap 5 is the stated UI framework; LocalStorage is a browser-only fallback rather than authoritative persistence.

#### Key Flow
1. Browser loads calculator and calculates a bill locally.
2. Save sends the bill to `POST /api/bills/save` in `server.js`; successful writes enter MySQL, while failures may be retained in LocalStorage.
3. Reports requests query APIs for filtered bill data and summary/monthly aggregates.
4. `billing_reports.js` renders results and transforms the current filtered dataset into downloadable CSV.

Main entry points: [`server.js`](https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js) (Express server), [`billing_reports.js`](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_reports.js) (Filters, pagination & CSV), [`billing_calculator.html`](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.html) (Calculator UI), [`index.html`](https://github.com/gopi514-chand/power-bill-management-system/blob/main/index.html) (Landing / navigation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser client"]
  node_landing["Landing / navigation<br/>static page<br/>[index.html]"]
  node_calculator_page["Calculator UI<br/>billing page"]
  node_calculator_logic["Bill calculation<br/>client logic"]
  node_calculator_styles["Calculator styles<br/>CSS"]
  node_bill_payload["Calculated bill payload<br/>record boundary"]
  node_local_storage[("LocalStorage backup<br/>browser fallback")]
  node_reports_page["Reports UI<br/>reporting page"]
  node_reports_logic["Filters, pagination &amp; CSV<br/>client logic<br/>[billing_reports.js]"]
end

subgraph group_server["Node service"]
  node_express_runtime{{"Express server<br/>Node entry point<br/>[server.js]"}}
  node_bill_api["Bill resource API<br/>REST routes<br/>[server.js]"]
  node_report_api["Report summary API<br/>REST routes<br/>[server.js]"]
  node_validation_access["Validation &amp; database access<br/>server layer<br/>[server.js]"]
  node_runtime_config["Environment configuration<br/>runtime settings<br/>[.env.example]"]
  node_npm_scripts["npm startup scripts<br/>package manifest<br/>[package.json]"]
end

subgraph group_data["Persistence"]
  node_mysql[("MySQL system of record<br/>database")]
  node_bills_schema["Bills schema<br/>database schema<br/>[database_setup.sql]"]
end

node_landing -->|"navigate"| node_calculator_page
node_landing -->|"navigate"| node_reports_page
node_calculator_page -->|"loads"| node_calculator_logic
node_calculator_styles -->|"styles"| node_calculator_page
node_calculator_logic -->|"calculates"| node_bill_payload
node_bill_payload -->|"POST /api/bills/save"| node_bill_api
node_bill_payload -.->|"save failure fallback"| node_local_storage
node_reports_page -->|"loads"| node_reports_logic
node_reports_logic -->|"filtered records and details"| node_bill_api
node_reports_logic -->|"overall and monthly summaries"| node_report_api
node_express_runtime -->|"hosts"| node_bill_api
node_express_runtime -->|"hosts"| node_report_api
node_bill_api -->|"validate and persist"| node_validation_access
node_report_api -->|"aggregate queries"| node_validation_access
node_validation_access -->|"queries"| node_mysql
node_bills_schema -->|"defines bills table and indexes"| node_mysql
node_runtime_config -.->|"configures"| node_express_runtime
node_npm_scripts -->|"starts"| node_express_runtime

click node_landing "https://github.com/gopi514-chand/power-bill-management-system/blob/main/index.html"
click node_calculator_page "https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.html"
click node_calculator_logic "https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.js"
click node_calculator_styles "https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.css"
click node_reports_page "https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_reports.html"
click node_reports_logic "https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_reports.js"
click node_express_runtime "https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js"
click node_bill_api "https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js"
click node_report_api "https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js"
click node_validation_access "https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js"
click node_runtime_config "https://github.com/gopi514-chand/power-bill-management-system/blob/main/.env.example"
click node_bills_schema "https://github.com/gopi514-chand/power-bill-management-system/blob/main/database_setup.sql"
click node_npm_scripts "https://github.com/gopi514-chand/power-bill-management-system/blob/main/package.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_landing,node_calculator_page,node_calculator_logic,node_calculator_styles,node_bill_payload,node_local_storage,node_reports_page,node_reports_logic toneBlue
class node_express_runtime,node_bill_api,node_report_api,node_validation_access,node_runtime_config,node_npm_scripts toneAmber
class node_mysql,node_bills_schema toneMint
```

## Components

### Browser client

- [Landing / navigation](https://github.com/gopi514-chand/power-bill-management-system/blob/main/index.html): static page · `index.html`
- [Calculator UI](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.html): billing page · `billing_calculator.html`
- [Bill calculation](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.js): client logic · Derives usage, charges, tax, and final bill. · `billing_calculator.js`
- [Calculator styles](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_calculator.css): CSS · `billing_calculator.css`
- **Calculated bill payload**: record boundary · Transfers calculated bill fields to persistence.
- **LocalStorage backup**: browser fallback · Retains saves when the API is unavailable.
- [Reports UI](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_reports.html): reporting page · `billing_reports.html`
- [Filters, pagination & CSV](https://github.com/gopi514-chand/power-bill-management-system/blob/main/billing_reports.js): client logic · Renders records and exports the filtered dataset. · `billing_reports.js`

### Node service

- [Express server](https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js): Node entry point · Serves browser assets and exposes the bill API. · `server.js`
- [Bill resource API](https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js): REST routes · Creates, lists, retrieves, updates, and deletes bills. · `server.js`
- [Report summary API](https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js): REST routes · Returns overall and monthly billing aggregates. · `server.js`
- [Validation & database access](https://github.com/gopi514-chand/power-bill-management-system/blob/main/server.js): server layer · Validates requests, handles API errors, and queries MySQL. · `server.js`
- [Environment configuration](https://github.com/gopi514-chand/power-bill-management-system/blob/main/.env.example): runtime settings · Supplies HTTP port and MySQL connection settings. · `.env.example`
- [npm startup scripts](https://github.com/gopi514-chand/power-bill-management-system/blob/main/package.json): package manifest · Starts the Node server runtime. · `package.json`

### Persistence

- **MySQL system of record**: database
- [Bills schema](https://github.com/gopi514-chand/power-bill-management-system/blob/main/database_setup.sql): database schema · Stores meter, calculation, date, and payment fields for bills. · `database_setup.sql`

## Connections

- Landing / navigation → Calculator UI: navigate
- Landing / navigation → Reports UI: navigate
- Calculator UI → Bill calculation: loads
- Calculator styles → Calculator UI: styles
- Bill calculation → Calculated bill payload: calculates
- Calculated bill payload → Bill resource API: POST /api/bills/save
- Calculated bill payload → LocalStorage backup: save failure fallback
- Reports UI → Filters, pagination & CSV: loads
- Filters, pagination & CSV → Bill resource API: filtered records and details
- Filters, pagination & CSV → Report summary API: overall and monthly summaries
- Express server → Bill resource API: hosts
- Express server → Report summary API: hosts
- Bill resource API → Validation & database access: validate and persist
- Report summary API → Validation & database access: aggregate queries
- Validation & database access → MySQL system of record: queries
- Bills schema → MySQL system of record: defines bills table and indexes
- Environment configuration → Express server: configures
- npm startup scripts → Express server: starts
