# oliveira7/pour-water-challenge architecture

> Architecture diagram of the GitHub repository oliveira7/pour-water-challenge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oliveira7/pour-water-challenge
- Repository: https://github.com/oliveira7/pour-water-challenge

## Overview

##### Project Type Analysis
This is a web application following the MVC (Model-View-Controller) architectural pattern, containerized with Docker, and includes unit testing. The project's main purpose is to calculate water accumulation in reservoirs based on input from a text file.

##### Main Components

A. Client Layer:
- Web Browser interface
- Bootstrap 5 UI components
- Twig templating engine for views

B. Infrastructure Layer:
- Nginx web server (running in Docker)
- PHP-FPM container
- Docker compose orchestration

C. Application Layer (MVC Structure):
- Controllers (ErrorController, ReservoirController)
- Models (Reservoir)
- Services (FileService, ReservoirService)
- Router
- Views (create.html, template.html, water.html)

**┌─────────────────┐**
- Client Layer   │
- ┬────────┘
- ↓
**┌─────────────────┐**
- Nginx (Docker) │
- ┬────────┘
- ↓
**┌─────────────────┐**
- Application     │
- ┌─────────────┐ │
- Router     │ │
- ┬──────┘ │
- ↓        │
- ┌─────────────┐ │
- Controllers  │ │
- ┬──────┘ │
- ↓        │
- ┌─────────────┐ │
- Services    │ │
- ┬──────┘ │
- ↓        │
- ┌─────────────┐ │
- Models     │ │
- ┘ │
- ┘

##### Key Interactions to Highlight

a) Request Flow:
**Browser → Nginx → Router → Controller → Service → Model**

b) Response Flow:
**Model → Service → Controller → View (Twig) → Browser**

c) File Operations:
**FileService ←→ input.txt**

##### Additional Elements

a) Docker Container Boundary:
- Both Nginx and PHP-FPM containers

b) Testing Components:
- A separate testing layer showing PHPUnit tests
- It to the Services layer where most business logic resides

##### Important Details

- Version information (PHP 7.2)
- External dependencies (Composer packages)
- File input/output mechanisms
- Error handling flow through ErrorController
- Twig template rendering process

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]:::client
        Bootstrap["Bootstrap 5 UI"]:::client
    end

    subgraph Docker["Docker Environment"]
        Nginx["Nginx Web Server"]:::infrastructure
        click Nginx "https://github.com/oliveira7/pour-water-challenge/blob/master/docker/nginx/nginx.conf"
        
        subgraph Application["Application Layer"]
            EntryPoint["Index.php"]:::app
            click EntryPoint "https://github.com/oliveira7/pour-water-challenge/blob/master/src/index.php"
            
            Router["Router"]:::router
            click Router "https://github.com/oliveira7/pour-water-challenge/blob/master/src/router/Router.php"
            
            subgraph Controllers
                ErrorController["Error Controller"]:::controller
                click ErrorController "https://github.com/oliveira7/pour-water-challenge/blob/master/src/controller/ErroController.php"
                ReservoirController["Reservoir Controller"]:::controller
                click ReservoirController "https://github.com/oliveira7/pour-water-challenge/blob/master/src/controller/ReservoirController.php"
            end
            
            subgraph Services
                FileService["File Service"]:::service
                click FileService "https://github.com/oliveira7/pour-water-challenge/blob/master/src/service/FileService.php"
                ReservoirService["Reservoir Service"]:::service
                click ReservoirService "https://github.com/oliveira7/pour-water-challenge/blob/master/src/service/ReservoirService.php"
            end
            
            subgraph Models
                Reservoir["Reservoir Model"]:::model
                click Reservoir "https://github.com/oliveira7/pour-water-challenge/blob/master/src/model/Reservoir.php"
            end
            
            subgraph Views
                Template["Template View"]:::view
                click Template "https://github.com/oliveira7/pour-water-challenge/blob/master/src/public/view/template.html"
                CreateView["Create View"]:::view
                click CreateView "https://github.com/oliveira7/pour-water-challenge/blob/master/src/public/view/create.html"
                WaterView["Water View"]:::view
                click WaterView "https://github.com/oliveira7/pour-water-challenge/blob/master/src/public/view/water.html"
            end
        end
    end

    subgraph Testing
        PHPUnit["PHPUnit Tests"]:::test
        click PHPUnit "https://github.com/oliveira7/pour-water-challenge/blob/master/tests/ReservoirServiceTest.php"
    end

    subgraph Data
        InputFile["Input File"]:::data
        click InputFile "https://github.com/oliveira7/pour-water-challenge/blob/master/input.txt"
    end

    %% Relationships
    Browser --> Nginx
    Nginx --> EntryPoint
    EntryPoint --> Router
    Router --> ErrorController
    Router --> ReservoirController
    ReservoirController --> ReservoirService
    ReservoirController --> FileService
    ReservoirService --> Reservoir
    FileService --> InputFile
    ReservoirController --> Template
    ReservoirController --> CreateView
    ReservoirController --> WaterView
    PHPUnit -.-> ReservoirService

    %% Styles
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef infrastructure fill:#2ecc71,stroke:#27ae60,color:white
    classDef app fill:#e67e22,stroke:#d35400,color:white
    classDef router fill:#e74c3c,stroke:#c0392b,color:white
    classDef controller fill:#9b59b6,stroke:#8e44ad,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef model fill:#1abc9c,stroke:#16a085,color:white
    classDef view fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef test fill:#34495e,stroke:#2c3e50,color:white
    classDef data fill:#e84393,stroke:#d81b60,color:white

    %% Legend
    subgraph Legend
        Client1["Client Component"]:::client
        Infra1["Infrastructure"]:::infrastructure
        App1["Application"]:::app
        Router1["Router"]:::router
        Controller1["Controller"]:::controller
        Service1["Service"]:::service
        Model1["Model"]:::model
        View1["View"]:::view
        Test1["Test"]:::test
        Data1["Data"]:::data
    end
```
