How danilotc/calculo-inss works
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.