Skip to content

Instantly share code, notes, and snippets.

@rubenhortas
Created March 14, 2026 11:53
Show Gist options
  • Select an option

  • Save rubenhortas/ad985a1fc6cbbfea982ed8c989d83e52 to your computer and use it in GitHub Desktop.

Select an option

Save rubenhortas/ad985a1fc6cbbfea982ed8c989d83e52 to your computer and use it in GitHub Desktop.
N-Layer architecture overview

N-Layer architecture overview

N-Layer (or Multi-Tier) architecture is a software architectural pattern where responsibilities are separated into distinct logical layers. This promotes separation of concerns, making the application easier to maintain, scale, and test.

1. Presentation Layer (UI)

The top-most level of the application. Its primary responsibility is to handle the interaction between the user and the software.

  • What goes here:
  • User Interface components: HTML/CSS/JavaScript, Mobile views, or WinForms.
  • Controllers/Presenters: Logic that handles HTTP requests and returns views (in MVC).
  • Input Validation: Basic client-side or surface-level server-side validation (e.g., "Is this field empty?").
  • Models for Display: Often referred to as ViewModels or DTOs (Data Transfer Objects) formatted specifically for the UI.

2. Business Logic Layer (BLL / Service Layer)

This is the "heart" of the application. It acts as an intermediary between the Presentation and Data layers, containing the core functionality and business rules.

  • What goes here:
  • Business Rules: Calculations, workflows, and state transitions (e.g., "A discount is applied only if the user is a premium member").
  • Domain Entities: Objects representing business concepts (e.g., Invoice, Customer).
  • Service Classes: Coordination of tasks and delegation to the Data Access Layer.
  • Complex Validation: Checks that require database state (e.g., "Does this username already exist?").

3. Data Access Layer (DAL / Persistence Layer)

This layer provides an interface for the application to interact with databases or external data sources.

  • What goes here:
  • Repositories: Classes that abstract the logic required to access data sources.
  • ORMs: Tools like Entity Framework, Hibernate, or Dapper.
  • Data Models: Objects that map directly to database tables.
  • Connection Strings: Configuration for connecting to SQL/NoSQL databases or external APIs.

4. Common / Infrastructure Layer (Cross-Cutting)

While not always counted as a "layer" in the vertical stack, this contains utilities used by all other layers.

  • What goes here:
  • Logging: Centralized error and activity tracking.
  • Security: Authentication and authorization logic.
  • Dependency Injection: Container configurations.
  • Utilities: Date formatters, string extensions, or encryption helpers.

Key benefits of this structure

Feature Description
Maintainability You can change the Database (DAL) without touching the UI (Presentation).
Scalability Layers can be deployed on different servers to handle high traffic.
Testability You can test Business Logic independently by mocking the Data Access Layer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment