# alexbs01/brightbills architecture

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

- Interactive diagram: https://gitdiagram.com/alexbs01/brightbills
- Repository: https://github.com/alexbs01/brightbills

## Overview

##### Project type and purpose
- BrightBills is an open-source, static web application for optimizing residential electricity bills.
- It is implemented entirely in native HTML, CSS and JavaScript with no back-end or external dependencies.
- The user opens index.html in a browser, enters form data and gets two calculations: “Fijo” power estimation and “Tarifa” comparison across three distributors.

##### File structure
- Top level:
- .gitignore, code of conduct, licenses, readme
- src/
- src/ folder:
- index.html → single HTML entry point
- script.js → core business logic (form handling, calculation functions)
- styles.css → visual styling
- No build or deployment scripts—straightforward static hosting.

##### Key architectural observations
- It’s a single-page application (SPA) pattern but without a framework.
- Separation of concerns:
- Presentation layer: index.html + styles.css
- Logic layer: script.js
- No data persistence, no API calls, all data and tariff rates are hard-coded or entered by user.

a. Browser (client)
b. Presentation layer
– index.html (DOM structure)
– styles.css (UI styling)
c. Logic layer
– script.js
· Form input handler
· Fijo calculation module
· Tarifa comparison module
· DOM update/output module
d. Data elements
– User input (form fields)
– Internal tariff rate data
– Computation output

##### Relationships and interactions
- Browser loads index.html → includes script.js and styles.css
- User interacts with UI form → events fire in script.js
- script.js reads form values → executes the “Fijo” module or “Tarifa” module
- Calculation result → script.js writes output back to the DOM
- Styles.css ensures consistent look & feel

##### Architectural patterns and principles
- Single-page static app (no back-end)
- Modular JS functions for separate calculation concerns
- Clear UI–logic separation: HTML/CSS vs. JavaScript
- Data flow sequence: Input → Compute → Render

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser (Client)"]:::external

    subgraph "src"
        subgraph "Presentation Layer"
            index["index.html"]:::presentation
            styles["styles.css"]:::presentation
        end

        subgraph "Logic Layer"
            script["script.js"]:::logic
            subgraph "Script Components"
                formHandler["Form Input Handler"]:::logic
                fijoCalc["“Fijo” Calculation Module"]:::logic
                tarifaCalc["“Tarifa” Comparison Module"]:::logic
                domUpdate["DOM Update / Output Module"]:::logic
            end
        end

        subgraph "Data Elements"
            UserInput[(User Input Form Fields)]:::data
            TariffData[(Internal Tariff Rate Data)]:::data
            ComputationOutput[(Computation Output Containers)]:::data
        end
    end

    Browser -->|"loads"| index
    Browser -->|"loads"| styles
    Browser -->|"loads"| script

    index -->|"contains form fields"| UserInput
    index -->|"contains output containers"| ComputationOutput
    script -->|"implements"| formHandler
    script -->|"implements"| fijoCalc
    script -->|"implements"| tarifaCalc
    script -->|"implements"| domUpdate

    UserInput -->|"triggers event"| formHandler
    formHandler -->|"calls"| fijoCalc
    formHandler -->|"calls"| tarifaCalc
    tarifaCalc -->|"uses rates"| TariffData
    fijoCalc -->|"outputs"| domUpdate
    tarifaCalc -->|"outputs"| domUpdate
    domUpdate -->|"updates DOM"| ComputationOutput
    styles -->|"styles UI"| index

    %% Click Events
    click index "https://github.com/alexbs01/brightbills/blob/main/src/index.html"
    click styles "https://github.com/alexbs01/brightbills/blob/main/src/styles.css"
    click script "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click formHandler "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click fijoCalc "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click tarifaCalc "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click domUpdate "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click UserInput "https://github.com/alexbs01/brightbills/blob/main/src/index.html"
    click TariffData "https://github.com/alexbs01/brightbills/blob/main/src/script.js"
    click ComputationOutput "https://github.com/alexbs01/brightbills/blob/main/src/index.html"

    %% Styles
    classDef presentation fill:#cfe2f3,stroke:#0366d6,stroke-width:1px
    classDef logic fill:#d9ead3,stroke:#38761d,stroke-width:1px
    classDef data fill:#fff2cc,stroke:#b45f06,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#999999,stroke-width:1px,stroke-dasharray: 5 5
```
