How guille-nat/api_compras works
Project Type & Purpose
• This is a Django-based REST API backend for a purchasing system (compras) that handles products/inventory, purchases, payments (including installment/cuota logic), and user management.
• The README emphasizes key business rules (stock validation, installment calculations, discounts/recargos, and automated email notifications) and critical technical details like JWT authentication.
File Structure
• The root-level files include standard Django project files (manage.py, SistemaCompras as the main project folder with settings, URLs, and WSGI/ASGI configurations).
• The “api” folder holds application-specific logic. Within “api” you have submodules for:
• “payments” (contains models, serializers, views)
• “products” (models, serializers, tests, views)
• “purchases” (models, serializers, views)
• “users” (models, serializers, views)
• There is a “management/commands” folder for custom Django commands (e.g., actualizar_cuotas and prueba_email), indicating scheduled tasks or administrative operations.
• A separate “migrations” folder exists at the root to consolidate migration files, which reflects a decision to centralize schema changes.
README for More Insights
• The README details the API’s capabilities, endpoints (with links to Swagger and Redoc documentation), and how JWT is used for authentication via Bearer tokens.
• It also highlights business rules such as validation of stock, application of discounts or recargos on payments, and dynamic calculation of installment due dates.
• There is a clear emphasis on automated tasks (cron jobs) for updating installments and sending HTML email notifications, which are unique architectural aspects.
a. Client/Consumer:
• External clients, mobile apps, or web frontends making REST API calls.
• A block labeled “Client Application” (or multiple consumers) connecting to the system.
b. API Gateway / Security Layer:
• JWT Authentication mechanism (a block showing the “/api/token/” endpoint for token issuance).
c. Core Django Application Server:
• Main Django project (SistemaCompras) as the backbone.
• Users Module – managing user registration and login (with modifications for storing lowercase fields and custom user logic).
• Products Module – handling inventory control and product listings.
• Purchases Module – handling order creation, validating stock, applying business rules for purchase processing.
• Payments Module – managing installments, applying discounts and surcharges for early/late payments.
d. Database:
e. External Email Service:
• SMTP service that handles email notifications (using Django’s email backend and the email configuration from the README).
f. Scheduled/Management Commands:
• A “Scheduled Task Executor” (or “Cron Job Scheduler”) that triggers management commands (actualizar_cuotas, prueba_email) to ensure periodic operations.
Architectural Patterns & Design Principles
• Separation of concerns:
• Different “api” submodules for different business domains.
• Clear separation between authentication (JWT) and business logic.
• RESTful nature of the design:
• Clearly labeled API endpoints.
• Use of automation (management commands) and modular design (application division in apps like payments, products, purchases, users).