Overview
Sistema Venta follows a clean, layered architecture pattern that separates concerns and promotes maintainability. The system is divided into a backend API built with .NET 7.0 and a frontend application built with Angular 14.
Technology Stack
Backend
- .NET 7.0: Core framework
- ASP.NET Core Web API: RESTful API
- Entity Framework Core: ORM
- SQL Server: Database
- AutoMapper: Object mapping
- Swagger/OpenAPI: API documentation
Frontend
- Angular 14: Frontend framework
- Angular Material: UI components
- RxJS: Reactive programming
- Chart.js: Data visualization
- SweetAlert2: User notifications
- XLSX: Excel export functionality
Backend Architecture
The backend follows a 6-layer architecture that ensures separation of concerns and maintainability:1. API Layer (SistemaVenta.API)
The presentation layer that exposes RESTful endpoints to the frontend. Key Components:- Controllers: Handle HTTP requests and responses
- Program.cs: Application entry point and middleware configuration
- Response Utility: Standardized API response format
Program.cs
VentaController.cs
2. Business Logic Layer (SistemaVenta.BLL)
Contains the business rules and application logic. Responsibilities:- Implement business rules and validation
- Orchestrate data flow between layers
- Transform entities to DTOs using AutoMapper
- Handle complex business operations
VentaService.cs
Services Available
3. Data Access Layer (SistemaVenta.DAL)
Handles all database operations through repositories. Key Components:- DbContext: Entity Framework context
- Generic Repository: CRUD operations for all entities
- Specialized Repositories: Custom queries for complex operations
GenericRepository.cs
DbventaContext.cs
4. Model Layer (SistemaVenta.Model)
Contains Entity Framework Core entity classes that map to database tables. Core Entities:Entity Examples
5. DTO Layer (SistemaVenta.DTO)
Data Transfer Objects used for communication between layers and with the frontend. DTO Purpose:- Decouple internal models from API contracts
- Control data exposure to clients
- Add computed properties
- Format data for display (e.g., decimal to string with culture)
DTO Examples
6. IOC Layer (SistemaVenta.IOC)
Inversion of Control container configuration for dependency injection.Dependencia.cs
7. Utility Layer (SistemaVenta.Utility)
Shared utilities and cross-cutting concerns. AutoMapper Configuration:AutoMapperProfile.cs
Frontend Architecture
The Angular application follows a modular, component-based architecture:Project Structure
Key Technologies
Angular Material: Provides a comprehensive UI component library following Material Design principles. RxJS: Used for reactive programming with Observables for async operations:Example Service
Data Flow
A typical request flows through the system as follows:Security Considerations
Design Patterns
Sistema Venta implements several design patterns:Repository Pattern
Abstracts data access logic with
IGenericRepository<T> and specialized repositoriesDependency Injection
All dependencies are injected through constructors, configured in the IOC layer
Service Layer Pattern
Business logic is encapsulated in service classes, keeping controllers thin
DTO Pattern
Separates internal models from API contracts using Data Transfer Objects
Database Schema
The database uses a relational model with the following key relationships: Key Relationships:- Users belong to Roles (many-to-one)
- Products belong to Categories (many-to-one)
- Sales contain multiple DetalleVenta (one-to-many)
- DetalleVenta references Products (many-to-one)
- Roles have access to Menus through MenuRol (many-to-many)
Performance Considerations
Optimization Strategies:
- Async/Await: All database operations use async methods
- IQueryable: Queries are built and executed efficiently with deferred execution
- Include/ThenInclude: Eager loading to prevent N+1 query problems
- Generic Repository: Reusable data access patterns reduce code duplication
- AutoMapper: Efficient object mapping with cached reflection
- Connection Pooling: SQL Server connection pooling is enabled by default
Scalability
The layered architecture supports horizontal and vertical scaling:- Stateless API: Controllers are stateless, enabling load balancing
- Repository Pattern: Easy to swap implementations (e.g., caching layer)
- Service Layer: Business logic can be extracted to separate microservices
- Angular SPA: Frontend is decoupled and can be hosted separately
Next Steps
API Endpoints
Explore detailed API documentation for all endpoints
Database Schema
View complete database schema and entity relationships
Frontend Setup
Learn about Angular components and services
Deployment
Deploy Sistema Venta to production environments