How nafery/apiferramas works
Project type and purpose
• This is a RESTful, full-stack backend API (no UI) for Ferramas hardware store. It exposes endpoints for product & user management, currency conversion, and Transbank payment integration.
• It follows a layered (n-tier) architecture: Routes → Services → Models → Database, with utility modules for shared configuration.
Main components
a. Flask Application (app.py) – the entry point that wires up routes, DB connection, and starts the server.
b. Routes Layer (api/routes) – HTTP controllers that define endpoints (/products, /users, /currency, /webpay).
c. Services Layer (api/services) – business logic orchestrating data flow and external integrations:
• product_service.py, user_service.py, category_services.py
• currency_service.py (calls external exchange-rate APIs via requests)
• webpay_service.py (calls Transbank SDK)
d. Models Layer (api/models) – data-access objects encapsulating SQL queries for products, users, categories.
e. Database Layer (api/db/database.py) – configuration and connection to MySQL.
f. Utils (api/utils/transbank_config.py) – shared config for payment SDK.
g. External Services – third-party currency-rate API and Transbank payment gateway.
h. MySQL Database (ferramas.sql schema).
Relationships and data flow
1. Client (Postman/browser) → HTTP Request
2. Flask app → Routes Layer
3. Routes calls Services
4. Services ↔ Models (SQL queries) → MySQL
5. Services → External APIs (currency, webpay)
6. Services returns processed data → Routes
7. Routes → HTTP Response to Client
Architectural patterns and principles
• Layered architecture (separation of concerns): controllers, business logic, data access, config.
• Single responsibility per module and clear dependency direction (Routes → Services → Models).
• Reusable utilities for config (e.g., Transbank credentials).
• External communication abstracted in service modules.
Essential elements
• Components: Flask App, Routes, Services, Models, Database, Utils, External APIs
• Clear labels: directory names, key classes/files
• Boundaries: show that models never call services or routes directly