# aathilfelix/simple-currency-converter architecture

> Architecture diagram of the GitHub repository aathilfelix/simple-currency-converter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aathilfelix/simple-currency-converter
- Repository: https://github.com/aathilfelix/simple-currency-converter

## Overview

##### Main Components
- Backend Server: The Flask application (contained in app.py) is the heart of this project. It handles incoming HTTP GET and POST requests.
- Helper Functions: The helper.py file encapsulates the core business logic, including functions to interact with the external currency conversion API (get_currency_exchange), retrieve available currencies (get_currencies), and generate error messages using the Memegen API (apology).
- Frontend Templates: The templates directory houses multiple HTML files (index.html, layout.html, apology.html) that form the presentation layer, including the use of Bootstrap in layout.html.
- Static Assets: The static directory contains CSS files (e.g., styles.css) for styling the frontend.
- External Services: There are two external APIs integrated into the system:
- Fawaz Ahmed's API for real-time currency conversion data.
- Memegen API for generating custom error messages.

##### Relationships and Interactions
- The Flask Server (app.py) receives user requests, distinguishes between GET and POST requests, and directs the flow.
- For GET requests, the server renders index.html (using the layout.html foundation) and serves static assets like the CSS file.
- For POST requests, the server receives form submissions, then calls helper functions to process currency conversion (via get_currency_exchange) and to fetch a list of valid currencies (via get_currencies) for dynamic content rendering.
- When an error occurs, the apology function in helper.py utilizes the Memegen API to return a tailored error message via apology.html.
- The external API calls represent outbound connections from the backend to third-party services.

##### Architectural Patterns and Design Principles
- MVC-like Pattern: Although simple, the project separates concerns:
- The Controllers: Managed in app.py by routing and handling HTTP methods.
- The View: Handled by the HTML templates which render the user interface.
- The Model/Business Logic: Encapsulated in helper.py.
- RESTful Communication: The Flask routes support RESTful behavior, processing GET and POST requests.
- Separation of Concerns: Clear division between static content (CSS and static assets), templates, business logic, and the web server.

##### Relevant Technologies and Libraries
- Python/Flask for the backend server.
- Fawaz Ahmed's open-source currency conversion API for real-time data.
- Memegen API for generating custom error messages.
- Bootstrap (indirectly referenced via layout.html) for styling and UI components.
- HTML/CSS for the frontend presentation layer.

##### Elements
- From the Browser to the Flask Application (indicating user inputs and form submissions).
- From the Flask Application to Helper Modules (for business logic processing).
- From the Flask Application to the External APIs (for currency conversion and error generation).
- Flow from the Flask Application to the Templates (rendering views) and Static Assets (CSS loading).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser("Client Browser"):::client

    subgraph "Backend Layer"
        Flask("Flask Application (app.py)"):::backend
        Helper("Helper Functions (helpers.py)"):::backend
    end

    subgraph "Frontend Layer"
        Frontend("Templates (index.html, layout.html, apology.html)"):::frontend
        Assets("Static Assets (styles.css)"):::frontend
    end

    Fawaz("Fawaz Ahmed's API"):::external
    Memegen("Memegen API"):::external

    Browser -->|"HTTP_GET_POST"| Flask
    Flask -->|"calls_Helper"| Helper
    Helper -->|"calls_Fawaz_API"| Fawaz
    Fawaz -->|"returns_exchange"| Helper
    Helper -->|"calls_Memegen_API"| Memegen
    Memegen -->|"returns_error"| Helper
    Flask -->|"renders_view"| Frontend
    Flask -->|"serves_static"| Assets

    click Flask "https://github.com/aathilfelix/simple-currency-converter/blob/master/app.py"
    click Helper "https://github.com/aathilfelix/simple-currency-converter/blob/master/helpers.py"
    click Frontend "https://github.com/aathilfelix/simple-currency-converter/tree/master/templates/"
    click Assets "https://github.com/aathilfelix/simple-currency-converter/tree/master/static/"

    classDef client fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffdd99,stroke:#333,stroke-width:2px;
```
