# bgreen39/ghg_calc architecture

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

- Interactive diagram: https://gitdiagram.com/bgreen39/ghg_calc
- Repository: https://github.com/bgreen39/ghg_calc

## Overview

##### Main Components
- Calculator Module (Backend): This contains the business logic for emissions calculation. It has separate files for calculating emissions from residential electricity (res_ele_emissions.py), residential gas (res_gas_emissions.py), transportation DSL (transport_dsl_emissions.py), and transportation gas (transport_gas_emissions.py).
- Testing Suite: Includes tests (e.g., tests/test_electricity_emissions.py) to verify that the calculations are correct.
- Website (Frontend): This is the user-facing component that includes HTML pages (index.html, contact.html, demo.html, documentation.html) and a set of assets (JavaScript files like demo.js, form_handler.js, main.js; and a CSS file) that handle user interactions and presentation.

##### Relationships and Interactions
- The website will interact with the calculator module. User inputs on the website likely trigger calculation requests, which are then processed using the logic in the calculator package.
- The backend (calculator module) could be exposed either as an API (if integrated into a web framework not directly seen here) or may be called directly in an environment where the interface interacts with Python code.
- There is a clear testing component ensuring the calculator's accuracy.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Calculation logic is isolated in the calculator directory, while user interface code is maintained under the website directory.
- Layered Architecture: The system has at least two layers—the calculation logic layer and the presentation layer.
- Modularity: Each GHG calculation type is modularized in its own file, making it easier to understand, maintain, or extend.

##### Relevant Technologies and Frameworks
- Python: For implementing the calculation logic.
- HTML/CSS/JavaScript: For the website’s frontend.
- Testing Framework: Although not explicitly mentioned, the tests directory implies that a testing framework like pytest could be used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend - Website Subgraph
    subgraph "Frontend - Website"
        direction TB
        UI_Input["User Input Forms"]:::frontend
        subgraph "HTML Pages"
            index["index.html"]:::frontend
            contact["contact.html"]:::frontend
            demo["demo.html"]:::frontend
            documentation["documentation.html"]:::frontend
        end
        subgraph "Assets"
            demoJS["demo.js"]:::frontend
            formHandler["form_handler.js"]:::frontend
            mainJS["main.js"]:::frontend
            styles["styles.css"]:::frontend
        end
        UIDisplay["Results Display (UI)"]:::frontend
    end

    %% Backend - Calculator Module Subgraph
    subgraph "Backend - Calculator Module"
        direction TB
        resEle["Residential Electricity Emissions Calculator"]:::backend
        resGas["Residential Gas Emissions Calculator"]:::backend
        transDSL["Transportation DSL Emissions Calculator"]:::backend
        transGas["Transportation Gas Emissions Calculator"]:::backend
    end

    %% Testing Suite Node
    testSuite["Testing Suite"]:::testing

    %% Data Flow: User action triggers calculations in each backend calculator module
    UI_Input -->|"submitForm"| resEle
    UI_Input -->|"submitForm"| resGas
    UI_Input -->|"submitForm"| transDSL
    UI_Input -->|"submitForm"| transGas

    %% Data Flow: Calculation results are returned to the UI display
    resEle -->|"result"| UIDisplay
    resGas -->|"result"| UIDisplay
    transDSL -->|"result"| UIDisplay
    transGas -->|"result"| UIDisplay

    %% Testing Suite Connection to Calculator Module (example with Residential Electricity)
    testSuite --- resEle

    %% Click Events for Component Mapping
    click resEle "https://github.com/bgreen39/ghg_calc/blob/main/calculator/res_ele_emissions.py"
    click resGas "https://github.com/bgreen39/ghg_calc/blob/main/calculator/res_gas_emissions.py"
    click transDSL "https://github.com/bgreen39/ghg_calc/blob/main/calculator/transport_dsl_emissions.py"
    click transGas "https://github.com/bgreen39/ghg_calc/blob/main/calculator/transport_gas_emissions.py"
    click testSuite "https://github.com/bgreen39/ghg_calc/blob/main/tests/test_electricity_emissions.py"
    click index "https://github.com/bgreen39/ghg_calc/blob/main/website/index.html"
    click contact "https://github.com/bgreen39/ghg_calc/blob/main/website/contact.html"
    click demo "https://github.com/bgreen39/ghg_calc/blob/main/website/demo.html"
    click documentation "https://github.com/bgreen39/ghg_calc/blob/main/website/documentation.html"
    click demoJS "https://github.com/bgreen39/ghg_calc/blob/main/website/assets/demo.js"
    click formHandler "https://github.com/bgreen39/ghg_calc/blob/main/website/assets/form_handler.js"
    click mainJS "https://github.com/bgreen39/ghg_calc/blob/main/website/assets/main.js"
    click styles "https://github.com/bgreen39/ghg_calc/blob/main/website/assets/styles.css"

    %% Styling Definitions
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef testing fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
