# impulsado/prac-pro2 architecture

> Architecture diagram of the GitHub repository impulsado/prac-pro2, 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/impulsado/prac-pro2
- Repository: https://github.com/impulsado/prac-pro2

## Overview

##### Main Components
- Domain Model:
◦ Classes such as City (Ciutat), Collection of Cities (Cjt_ciutats), and Collection of Products (Cjt_productes) are central.
◦ Other domain classes include the Ship (Vaixell) and Journey (Viatge).
◦ The “Llanxa” module is fundamental as it implements the algorithm for determining the optimal path.
- Input/Output Module:
◦ The project reads data from sample input files (located in the samples folder) and/or standard input.
◦ The output component returns the result of the simulation (for example, the computed best route, exchanged products, etc.).
- Control/Processing Flow:
◦ The main driver (program.cc) is responsible for orchestrating the sequence: reading inputs, setting up the cities tree, invoking the trade simulation, and calling the Llanxa algorithm.
◦ This overall algorithm determines the trade execution among cities and the ship’s journey.

##### Out Relationships and Interactions
- That the main program (controller) initializes and interacts with the core domain model.
- That "Cjt_ciutats" aggregates multiple "Ciutat" objects, each holding a "Cjt_productes" as its inventory.
- How the Llanxa module computes the “best route” (Viatge) for the ship based on criteria such as quantity and distance.
- Data flow from input (samples and command line) -> domain processing -> output (results/log).

##### Architectural Patterns / Design Principles
- The system uses clear modular separation:
◦ Domain Layer: Contains all the business logic and entities.
◦ Simulation/Processing Layer: Coordinates interactions among domain entities and implements the trading/route calculation algorithms.
◦ Interface Layer: Handles I/O (console-based or through sample files).
- Modularity and separation of concerns – each major component has a distinct role (e.g., trading mechanism vs. route calculation).

##### Technologies and Tools
- C++ as the implementation language.
- The Makefile for build automation.
- Git for version control.

##### Final Advice
- Be as detailed as possible: list every major module and its role, including supporting files like the Makefile or Doxygen documentation.
- Avoid over-cluttering, but remember that capturing the modular design precisely—even if it means having multiple sub-components—is preferred.
- Starting with a high-level view (domain vs. controller vs. I/O) and then drilling down to show interactions like how Llanxa interacts with Vaixell and the Viatge.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "I/O Layer"
        IO_Input["Input (Sample files)"]:::io
        IO_Output["Output (Console/Files)"]:::io
    end

    subgraph "Processing/Controller"
        CTRL["Main Controller (program.cc)"]:::controller
    end

    subgraph "Domain Layer"
        DC_CjtCiutats["Cjt_ciutats"]:::domain
        DC_Ciutat["Ciutat"]:::domain
        DC_CjtProductes["Cjt_productes"]:::domain
        DC_Vaixell["Vaixell"]:::domain
        DC_Viatge["Viatge"]:::domain
        DC_Llanxa["Llanxa"]:::domain
    end

    subgraph "Build & Documentation"
        BT_Makefile["Makefile"]:::tools
        BT_DOC["Documentation (DOC)"]:::tools
    end

    IO_Input -->|"reads"| CTRL
    CTRL -->|"initializes"| DC_CjtCiutats
    CTRL -->|"triggers"| DC_Vaixell
    CTRL -->|"calls"| DC_Llanxa
    CTRL -->|"outputs"| IO_Output
    DC_CjtCiutats -->|"aggregates"| DC_Ciutat
    DC_Ciutat -->|"hasInventory"| DC_CjtProductes
    DC_Llanxa -->|"computesRoute"| DC_Viatge
    DC_Vaixell -->|"executesTradeVia"| DC_Viatge

    classDef domain fill:#bbf,stroke:#333,stroke-width:2px,color:#000;
    classDef controller fill:#9f6,stroke:#333,stroke-width:2px,color:#000;
    classDef io fill:#ff9,stroke:#333,stroke-width:2px,color:#000;
    classDef tools fill:#f96,stroke:#333,stroke-width:2px,color:#000;

    click DC_Ciutat "https://github.com/impulsado/prac-pro2/blob/main/include/Ciutat.hh"
    click DC_CjtCiutats "https://github.com/impulsado/prac-pro2/blob/main/include/Cjt_ciutats.hh"
    click DC_CjtProductes "https://github.com/impulsado/prac-pro2/blob/main/include/Cjt_productes.hh"
    click DC_Vaixell "https://github.com/impulsado/prac-pro2/blob/main/include/Vaixell.hh"
    click DC_Viatge "https://github.com/impulsado/prac-pro2/blob/main/include/Viatge.hh"
    click DC_Llanxa "https://github.com/impulsado/prac-pro2/blob/main/include/Llanxa.hh"
    click CTRL "https://github.com/impulsado/prac-pro2/blob/main/src/program.cc"
    click IO_Input "https://github.com/impulsado/prac-pro2/tree/main/samples/"
    click BT_Makefile "https://github.com/impulsado/prac-pro2/tree/main/Makefile"
    click BT_DOC "https://github.com/impulsado/prac-pro2/tree/main/DOC/"
```
