# blasferna/django-calculation architecture

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

- Interactive diagram: https://gitdiagram.com/blasferna/django-calculation
- Repository: https://github.com/blasferna/django-calculation

## Overview

##### Project type and purpose
- This is a reusable Django app (“django-calculation”) that augments Django forms with client-side calculated fields.
- It delivers two widget types (FormulaInput and SummaryInput) that derive their values via a JavaScript expression or aggregation when source fields change.

##### File structure
- Top-level files:
– README.md, LICENSE, CHANGELOG.md, MANIFEST.in, setup.py (packaging & metadata)
– .github/workflows/release.yml (CI/CD pipeline)
- calculation/ (the Django app):
– __init__.py, apps.py (Django app registration)
– widgets.py (widget classes: FormulaInput, SummaryInput, SumInput helper)
– static/calculation/js/calculation.js (front-end logic to parse expressions and update fields)

##### Insights from README
- Explains installation (pip + add to INSTALLED_APPS), usage within Django forms, two modes (FORMULA, SUMMARY), and the need to include form.media for static assets.
- No database models—primary functionality lives in form widgets and client-side JS.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side" 
        direction TB
        Browser["Browser (Client)"]:::client
        CalcJS["calculation.js\n(JS Engine)"]:::static
    end

    %% Server Side
    subgraph "Django Web Server" 
        direction TB
        DjangoServer["Django Server"]:::server
        DjangoForms["Django Forms\n(Form / ModelForm)"]:::server
        Widgets["Widgets\n(FormulaInput / SummaryInput)"]:::server
        Database["Database (optional)"]:::server
    end

    %% Static Assets
    subgraph "Static Assets" 
        direction TB
        StaticDir["/static/calculation/js/\n(calculation.js)"]:::static
    end

    %% Packaging & CI/CD
    subgraph "Packaging & CI/CD" 
        direction TB
        Setup["setup.py"]:::package
        Manifest["MANIFEST.in"]:::package
        Readme["README.md"]:::package
        License["LICENSE"]:::package
        Changelog["CHANGELOG.md"]:::package
        CI[".github/workflows/release.yml"]:::package
    end

    %% Reusable App Directory
    DjangoApp["django-calculation\n(calculation/)"]:::server

    %% Relationships
    Browser -->|"HTTP GET"| DjangoServer
    DjangoServer -->|"build form"| DjangoForms
    DjangoForms -->|"use widgets"| Widgets
    Widgets -->|"media includes"| StaticDir
    DjangoServer -->|"HTTP Response\n(HTML + <script>)"| Browser

    Browser -->|"on input change"| CalcJS
    CalcJS -->|"evaluate & update DOM"| Browser

    Browser -->|"Form Submit"| DjangoServer
    DjangoServer -->|"validate & process"| DjangoForms
    DjangoForms -->|"optional ORM"| Database

    %% Click Events
    click DjangoApp "https://github.com/blasferna/django-calculation/tree/main/calculation/"
    click AppConfig "https://github.com/blasferna/django-calculation/blob/main/calculation/apps.py"
    click Widgets "https://github.com/blasferna/django-calculation/blob/main/calculation/widgets.py"
    click CalcJS "https://github.com/blasferna/django-calculation/blob/main/calculation/static/calculation/js/calculation.js"
    click StaticDir "https://github.com/blasferna/django-calculation/tree/main/calculation/static/calculation/js/"
    click Setup "https://github.com/blasferna/django-calculation/blob/main/setup.py"
    click Manifest "https://github.com/blasferna/django-calculation/blob/main/MANIFEST.in"
    click Readme "https://github.com/blasferna/django-calculation/blob/main/README.md"
    click License "https://github.com/blasferna/django-calculation/tree/main/LICENSE"
    click Changelog "https://github.com/blasferna/django-calculation/blob/main/CHANGELOG.md"
    click CI "https://github.com/blasferna/django-calculation/blob/main/.github/workflows/release.yml"

    %% Styles
    classDef client fill:#E8F8F5,stroke:#1ABC9C,color:#0E6251
    classDef server fill:#FEF9E7,stroke:#F1C40F,color:#B9770E
    classDef static fill:#EBF5FB,stroke:#3498DB,color:#21618C
    classDef package fill:#FDEDEC,stroke:#E74C3C,color:#922B21
```
