Introduction
Canchas Deportivas is built using a three-tier architecture (also known as n-tier or layered architecture), a well-established software design pattern that separates concerns into three distinct layers. This architectural pattern promotes maintainability, scalability, and separation of concerns.Three-Tier Architecture Pattern
The application is organized into three logical layers, each with specific responsibilities:Presentation Layer
User interface and controllers that handle HTTP requests
Business Layer
Business logic and rules that orchestrate operations
Data Layer
Data access and database communication
Layer Structure
The codebase is physically organized into separate namespaces that correspond to each layer:How Layers Interact
The layers follow a strict hierarchical communication pattern where each layer only communicates with the layer directly below it:Data Flow Example
Let’s trace how a request to list all soccer fields flows through the system:-
User Request: Browser sends GET request to
/Canchas/ListarCanchas -
Presentation Layer:
CanchasControllerreceives the request -
Business Layer:
CN_Canchasprocesses the request -
Data Layer:
CD_Canchasexecutes database query - Response: Data flows back up through the layers to the view
Entity Classes (Domain Models)
Thecapa_entidad namespace contains entity classes that represent domain objects. These classes are shared across all layers:
Key Architectural Benefits
Separation of Concerns
Separation of Concerns
Each layer has a single, well-defined responsibility. The presentation layer handles UI concerns, business layer contains logic, and data layer manages persistence.
Maintainability
Maintainability
Changes to one layer typically don’t require changes to other layers. For example, you can modify the database structure without affecting controllers.
Testability
Testability
Each layer can be tested independently. Business logic can be tested without requiring a database or UI.
Reusability
Reusability
Business logic can be reused across different presentation layers (Web, API, Mobile, etc.).
Scalability
Scalability
Layers can be deployed on different servers. For example, the data layer can be on a dedicated database server.
Naming Conventions
The project follows consistent naming conventions:- Presentation Layer: Controllers and ViewModels
- Business Layer:
CN_prefix (Capa Negocio) - Data Layer:
CD_prefix (Capa Dato) - Entity Classes:
CE_prefix (Capa Entidad)
Database Communication
All database operations use:- SQL Server as the database engine
- Stored Procedures for all CRUD operations
- ADO.NET with
SqlCommandandSqlConnection - Centralized Connection Management via
CD_conexionclass
Next Steps
Data Layer
Learn about database access and connection management
Business Layer
Understand business logic and orchestration
Presentation Layer
Explore controllers and user interface handling