How infgonza/final_practicas_profesionalizantes_2024 works
Project Type and Purpose
• This is a full-stack e-commerce solution built as a REST API in Java with Spring Boot.
• The system supports selling CDs and vinyl, handles user authentication (with JWT and Spring Security), integrates with a MySQL database, delivers static web pages (leveraging HTML, CSS, JavaScript, and Bootstrap), and interacts with an external payment API (Mercado Pago).
Main Components
a. Frontend/Presentation Layer:
– Located in src/main/resources/static and src/main/resources/templates.
– Contains HTML, CSS, and JavaScript files for pages such as login, product display, shopping cart, contact, and user profile.
b. API/Backend Layer:
– Controllers (e.g., AuthController, ProductoController, CarritoDeComprasController, etc.) handle HTTP requests.
– Configuration classes (e.g., CorsConfig, JwtAuthFilter, SecurityConfig) set up cross-origin policies, JWT-based authentication, and security policies.
c. Business Logic Layer:
– Services (e.g., CarritoDeComprasService, ClienteService, CompraService, etc.) encapsulate business rules and processes.
– DTOs in the dto package aid in data transfer between the client and backend layers.
d. Data Access Layer:
– Repositories (e.g., ClienteRepository, ProductoRepository, UsuarioRepository, etc.) provide database interaction using Spring Data.
– Entities (e.g., Cliente, Producto, Compra, Factura, etc.) represent the underlying data model persisted in MySQL.
e. Persistence/Database:
– The MySQL database (indicated by the disqueria_db.sql file) stores application data.
f. External Integration:
• Mercado Pago API integration is managed through a designated controller (MercadoPagoController) and possibly supported by additional service classes.
• Also, there is an S3Service, which likely handles file or image storage.
Determining Relationships and Interactions
• The Frontend communicates with the RESTful API endpoints exposed by the Controllers.
• Controllers translate HTTP requests into calls on the Business Logic (Services), which then use DTOs to pass data.
• The Services interact with the repository layer for CRUD operations, read/write transactions with the MySQL database.
• Security is applied at multiple layers via Spring Security, JWT handling, and custom authentication services.
• External communication is showcased with dedicated controllers and services (e.g., MercadoPagoController for payment processes, S3Service for storage).
• The configuration classes (like CorsConfig and SecurityConfig) are cross-cutting concerns that affect request filtering and authorization.
Architectural Patterns & Design Principles
• Layered Architecture: Clear separation into presentation, API, business logic, and data access layers.
• Use of DTOs: To decouple API models from internal entities.
• Dependency Injection: Spring Boot’s inherent pattern that wires controllers, services, and repositories.
• RESTful Design: Controllers serve as endpoints for standard HTTP methods.
• Security via JWT and Spring Security: Ensuring stateless, token-based authentication.