Hello everyone !
Do you know about what is architecture and which are the different types ?
First of all, software architecture defines how a software is organized to remain maintainable, testable and adaptable over many years.
Layered Architecture
In a classic layered architecture, code is divided into horizontal levels :
- Presentation Layer which handles the user requests and displays results (web controllers, CLI commands).
- The domain layer which applies the core rules and calculations.
- The infrastructure layer which communicates with databases, email servers or external APIs.
How does it work : The dependencies flow form top to bottom. The presentation layer calls the domain layer and the domain layer depends directly on the infrastructure layer. But there are some limitations, because the logic depends on the technical code (like database), writing unit tests for rules without a real database is pretty difficult.
The Hexagonal Architecture
This one is created by Alistair Cockburn in 2005, this architecture places the logic at the center. External tools like database, web interfaces, email services and tests scripts are all outside the core.
The main principles are :
- All dependencies point inward toward the domain. The core logic depends on nothing technical.
- The ports are interfaces which are defined inside the domain that describe what the business needs or offers.
- The adapters are the code outside the domain that translates the technical protocols (SQL, HTTP, SMTP) into the domain ports.
- And the high testability, the logic can be tested in complete isolation using fast tests doubles (fakes/spies) without needing a database or mail server running.
Onion architecture & Clean architecture
These 2 patterns share the same fundamentals as Hexagonal architecture :
- The onion architecture & Clean architecture arrange software in concentric rings.
- The entities and business use cases stay in the middle, while frameworks, UI and databases occupy outer layers. The dependencies points strictly inward toward the center.
Modular Monolith vs Microservices
The applications can also be categorized by how their components are packaged and deployed :
- The modular monolith is a single application structured into independent, highly cohesive modules aligned with business contexts. This provides clear boudaries while remaining easier to setup and deploy than distributed systems.
- The microservices divide the system into multiple smaller independent services that runs as separate network applications. This allows independent deployments, microservices add operation complexity in networking, monitoring and data management.
CSRS
Also known as Command Query Responsibility Segregation, it separates operation that change data from operations that read data :
- The commands are operations that change stage (e.g., creating an account), run domain rules and invariant.
- The queries are operations that retrieve data bypass heavy domain logic to read optimized views directly for maximum speed.
Event sourcing
Rather than storing only the current state in a database, Event sourcing records the complete history as a chronological series of domain events (such as SeatsReserved, PaymentFailed). The current state is calculated by replaying past events which provides full audit trails.
Summary
- Layer architecture works well for smaller, simple applications.
- Hexagonal & Clean architecture protect long-lived, complex business rules from changing technologies and make testing easy.
- CQRS & Event sourcing help manage advanced scale, historical tracking and complex data reads.
If you read all this, I want to say thanks and this is my first post, so if you can give me tips or tell me if this is useful, I would be really grateful.
Have a good day !
Top comments (0)