How gopi514-chand/power-bill-management-system works
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 Express server · billing_reports.js Filters, pagination & CSV · billing_calculator.html Calculator UI · index.html Landing / navigation
Components 16
Browser client
- Landing / navigation
index.html - Calculator UI
billing_calculator.html - Bill calculation · Derives usage, charges, tax, and final bill.
billing_calculator.js - Calculator styles
billing_calculator.css - Calculated bill payload · Transfers calculated bill fields to persistence.
- LocalStorage backup · Retains saves when the API is unavailable.
- Reports UI
billing_reports.html - Filters, pagination & CSV · Renders records and exports the filtered dataset.
billing_reports.js
Node service
- Express server · Serves browser assets and exposes the bill API.
server.js - Bill resource API · Creates, lists, retrieves, updates, and deletes bills.
server.js - Report summary API · Returns overall and monthly billing aggregates.
server.js - Validation & database access · Validates requests, handles API errors, and queries MySQL.
server.js - Environment configuration · Supplies HTTP port and MySQL connection settings.
.env.example - npm startup scripts · Starts the Node server runtime.
package.json
Persistence
- MySQL system of record
- Bills schema · Stores meter, calculation, date, and payment fields for bills.
database_setup.sql
Connections 18
- 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