# danilotc/calculo-inss architecture

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

- Interactive diagram: https://gitdiagram.com/danilotc/calculo-inss
- Repository: https://github.com/danilotc/calculo-inss

## Overview

##### Project type and purpose
- This is a small, single‐purpose, command-line Python application whose sole responsibility is to calculate the INSS contribution for a given year (2021 or 2022) and a salary base.
- There is no frontend web UI, no network calls or database. It’s a monolithic CLI tool structured into reusable modules.

##### File structure
- Top‐level files only, no nested directories.
- main.py ‑ the entry point for the CLI
- calculo_inss_2021_2022.py ‑ implements the core calculation logic
- tabela.py ‑ holds the contribution table definitions and lookup logic
- trata_numero.py ‑ utility for numeric input handling, decimal truncation
- README.md ‑ documentation
- No external configuration files, no build scripts, no deployment artifacts—just Python modules.

##### README for additional insights
- Confirms a CLI workflow: user runs main.py, enters year and salary, sees output.
- Describes the mathematical formula, the tranche logic, and the decimal-truncation utility.
- No reference to external services or databases.

##### Components
a. CLI Interface (main.py)
­– Reads user input (year, salary base).
­– Displays prompts and final result on the console.
b. Input Validation & Conversion (trata_numero.py)
­– Parses strings to floats, truncates decimals without rounding.
c. Contribution Table Module (tabela.py)
­– Defines salary ranges, rates, “valor a agregar.”
­– Exposes a lookup function to choose the correct tranche.
d. Calculation Engine (calculo_inss_2021_2022.py)
­– Applies the business rule: selects tranche, computes (salary – lowerBound)*rate + accumulatedValue.
e. Output Formatter (could be part of main.py or Calculation Engine)
­– Formats numeric result to two decimal places for console output.

##### Relationships and interactions
- The user triggers main.py.
- main.py calls trata_numero.py to parse and sanitize inputs.
- main.py invokes tabela.py to retrieve tranche parameters for the given year and salary.
- main.py passes sanitized inputs and tranche parameters into calculo_inss_2021_2022.py.
- calculo_inss returns a float result.
- main.py prints the formatted result back to the user.

##### Architectural patterns & design principles
- Single Responsibility: each module has one job (I/O, parsing, lookup, calculation).
- Modular layering: CLI → Utilities → Business Logic.
- No external dependencies—pure Python standard library.

##### Technologies and frameworks
- Language: Python 3.x
- No frameworks, just standard library (argparse or input(), plus built-in math/decimal if used).

##### Detail
- Don’t omit the decimal-truncation step—it’s a critical utility affecting correctness.
- Formula in a callout to make the core algorithm instantly recognizable.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actor
    User["User (Console)"]:::actor

    %% I/O Layer
    Main["main.py\n- CLI Interface\n- Reads inputs & displays output"]:::io

    %% Utilities and Data Layer
    Trata["trata_numero.py\n- Parses & truncates decimals"]:::util
    Tabela["tabela.py\n- Defines salary ranges & lookup"]:::util

    %% Business Logic Layer
    Calculo["calculo_inss_2021_2022.py\n- Selects tranche\n- Computes (salary−lowerBound)*rate+accum\n- Handles faixa4 (14% rate)"]:::logic

    %% Data Flow
    User -->|"year, salaryString"| Main
    Main -->|"salaryString"| Trata
    Trata -->|"sanitizedSalary"| Main
    Main -->|"year, sanitizedSalary"| Tabela
    Tabela -->|"trancheData"| Main
    Main -->|"sanitizedSalary, trancheData"| Calculo
    Calculo -->|"discountValue"| Main
    Main -->|"discountValue printed"| User

    %% Click Events
    click Main "https://github.com/danilotc/calculo-inss/blob/main/main.py"
    click Trata "https://github.com/danilotc/calculo-inss/blob/main/trata_numero.py"
    click Tabela "https://github.com/danilotc/calculo-inss/blob/main/tabela.py"
    click Calculo "https://github.com/danilotc/calculo-inss/blob/main/calculo_inss_2021_2022.py"

    %% Styles
    classDef actor fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef io fill:#B3D4FC,stroke:#333,stroke-width:1px
    classDef util fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef logic fill:#FFCC80,stroke:#333,stroke-width:1px
```
