How aathilfelix/simple-currency-converter works
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).