# augustomelara-dev/sistema-gestion-inventario architecture

> Architecture diagram of the GitHub repository augustomelara-dev/sistema-gestion-inventario, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/augustomelara-dev/sistema-gestion-inventario
- Repository: https://github.com/augustomelara-dev/sistema-gestion-inventario

## Overview

1. **Repository shape**
   - This is a **single-file C application**: all application logic lives in `main.c`.
   - There are no separate libraries, services, or modules in the repo; the architecture is intentionally **monolithic**.

2. **Primary runtime**
   - The output is a **console executable** compiled with C99/GCC.
   - The app is designed for **Windows-style terminal usage**, using commands like `cls` and `pause` for screen control and flow.

3. **Core domain boundary: inventory management**
   - The main business object is a **product/inventory record** with fields implied by the README: code, name, quantity, price, and computed total value.
   - The in-memory inventory acts as the working set for all CRUD and reporting operations.

4. **User interaction layer**
   - All input and output are handled through the **command-line interface**.
   - The UI boundary is interactive and menu-driven, with user actions triggering add, modify, show, and search operations.

5. **CRUD subsystem**
   - The app supports the standard inventory lifecycle:
     - **Add** new products with unique code checks
     - **Modify** existing products
     - **Display** the full inventory in tabular form
     - **Search** by product code
   - These operations all update the same in-memory dataset.

6. **Reporting and analytics subsystem**
   - The program derives operational metrics from inventory data:
     - **Low-stock alerts** for items under 10 units
     - **Total inventory value** as a financial metric
     - **Counts and stock totals** for overall status
   - These are read-only views over the same central inventory state.

7. **Persistence boundary**
   - Data is persisted to a flat file named **`inventario.txt`** using **CSV-like comma-separated records**.
   - On startup, the program **loads existing data** if the file exists; otherwise it initializes an empty inventory.
   - On exit, it **auto-saves** the current state back to disk.

8. **Data integrity and file safety**
   - Names are **sanitized** before persistence by replacing commas with spaces so the file structure is not broken.
   - The README indicates the calculated **total** is recomputed dynamically, so stored and displayed values stay consistent.

9. **Input validation / defensive behavior**
   - The app includes explicit protections against bad user input:
     - bounded string reads
     - return-value checks on numeric input
     - buffer cleanup after invalid input
   - This makes the UI loop resilient to malformed keyboard input rather than crashing or hanging.

10. **External dependencies and infrastructure**
   - There are no network services, databases, or background daemons.
   - The only external dependency is the **local filesystem**, which serves as the persistence layer.

11. **Diagramming takeaway**
   - The clean architecture view is: **Console user → input validation/UI logic → inventory operations in memory → reporting and persistence → `inventario.txt`**.
   - Everything is contained in one process, with the file as the only durable boundary outside memory.

12. **Repository artifacts**
   - `.gitignore` likely excludes generated build artifacts and the runtime data file.
   - `README.md` documents behavior but does not add architectural components beyond what `main.c` already implements.

Main entry points: [`main.c`](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c) (Menu flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Monolithic app"]
  node_cli["Console UI<br/>interactive shell<br/>[main.c]"]
  node_input["Input guard<br/>validation<br/>[main.c]"]
  node_menu["Menu flow<br/>controller<br/>[main.c]"]
  node_crud["CRUD ops<br/>inventory workflow<br/>[main.c]"]
  node_reporting["Reports<br/>analytics<br/>[main.c]"]
  node_inventory[("Inventory state<br/>in-memory dataset<br/>[main.c]")]
  node_product["Product record<br/>domain model<br/>[main.c]"]
  node_persistence["Persistence<br/>flat-file storage<br/>[main.c]"]
  node_load["Startup load<br/>file import<br/>[main.c]"]
  node_save["Auto-save<br/>file export<br/>[main.c]"]
  node_sanitize["Sanitize names<br/>data hygiene<br/>[main.c]"]
  node_fs["inventario.txt<br/>local file"]
end

node_cli -->|"accepts"| node_input
node_input -->|"drives"| node_menu
node_menu -->|"routes"| node_crud
node_menu -->|"routes"| node_reporting
node_crud -->|"updates"| node_inventory
node_reporting -->|"reads"| node_inventory
node_crud -->|"manages"| node_product
node_inventory -->|"persists via"| node_persistence
node_persistence -->|"includes"| node_load
node_persistence -->|"includes"| node_save
node_load -->|"reads"| node_fs
node_save -->|"uses"| node_sanitize
node_sanitize -->|"writes"| node_fs

click node_cli "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_input "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_menu "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_crud "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_reporting "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_inventory "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_product "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_persistence "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_load "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_save "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"
click node_sanitize "https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_input,node_menu,node_crud,node_reporting,node_inventory,node_product,node_persistence,node_load,node_save,node_sanitize,node_fs toneBlue
```

## Components

### Monolithic app

Single-file console application in main.c

- [Console UI](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): interactive shell · Menu-driven terminal interaction for user commands · `main.c`
- [Input guard](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): validation · Bounds checks, numeric parsing, and buffer cleanup for malformed input · `main.c`
- [Menu flow](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): controller · Main command loop that routes user actions · `main.c`
- [CRUD ops](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): inventory workflow · Add, modify, display, and search products · `main.c`
- [Reports](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): analytics · Low-stock alerts, totals, counts, and inventory value · `main.c`
- [Inventory state](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): in-memory dataset · Working set of product records used by all operations · `main.c`
- [Product record](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): domain model · Code, name, quantity, price, and computed total value · `main.c`
- [Persistence](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): flat-file storage · Loads and saves inventory data as comma-separated records · `main.c`
- [Startup load](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): file import · Reads existing inventory state if the data file exists · `main.c`
- [Auto-save](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): file export · Writes current inventory state back on exit · `main.c`
- [Sanitize names](https://github.com/augustomelara-dev/sistema-gestion-inventario/blob/main/main.c): data hygiene · Replaces commas in names before persistence · `main.c`
- **inventario.txt**: local file · On-disk inventory data file

## Connections

- Console UI → Input guard: accepts · Terminal input is validated before use
- Input guard → Menu flow: drives · Validated commands enter the main loop
- Menu flow → CRUD ops: routes · Menu selections trigger inventory actions
- Menu flow → Reports: routes · Menu selections trigger read-only reports
- CRUD ops → Inventory state: updates · Mutating operations change the shared working set
- Reports → Inventory state: reads · Analytics are derived from current inventory state
- CRUD ops → Product record: manages · Operations create and update product records
- Inventory state → Persistence: persists via · Current state is serialized to disk
- Persistence → Startup load: includes · Startup path restores prior state
- Persistence → Auto-save: includes · Exit path stores current state
- Startup load → inventario.txt: reads · Loads data from the inventory file
- Auto-save → Sanitize names: uses · Names are cleaned before writing records
- Sanitize names → inventario.txt: writes · Sanitized records are written to disk
