The application core is the part of a system that holds its business entities and rules. Think of it as a clean room: the important work happens inside, while databases, user interfaces, APIs, and frameworks stay outside. section 5.2.2 section 5.2.3
A layered system can leave business logic anchored to a database. Hexagonal architecture changes the question from “What sits on top?” to “What belongs inside?” The core defines interfaces called ports; outside adapters connect technologies to those ports. Dependencies point inward: adapters know the core, but the core does not depend on them. section 5.1 section 5.11
Requests and results can cross the boundary in both directions:
- A driving adapter, such as an HTTP controller, translates a request and calls a primary port to start an action in the core. section 5.3.3
- The core calls a driven port when it needs something done; an adapter implements that interface and handles the technology, such as saving an order with SQL. section 5.3.3 section 5.4.1
Data may flow outward while the dependency still points inward: the database adapter references the core’s interface, not the other way around. This allows an adapter to be replaced without changing the business logic, as long as the replacement honors the port. section 5.3.3 section 5.3.4
A server monitor with interchangeable alerts
A server monitor keeps its logic in the core and defines an alert port. Console, Twilio, and Kafka adapters provide different ways to send alerts. A fake adapter can collect messages in a list, letting a test check that an overheating server sends one alert without contacting an external service. section 5.5.3 section 5.5.4
/5.4-Port-Adapter-Example/After/ │ ├── /Core/ <-- THE INSIDE (Pure Business Logic) │ ├── /Domain/ │ │ └── ServerMonitor.cs # The Logic (The "Clean Room") │ │ │ └── /Ports/ <-- THE BOUNDARY │ └── IAlertPort.cs # The Interface (The Contract) │ ├── /Infrastructure/ <-- THE OUTSIDE (The Tech Stack) │ ├── /Adapters/ │ │ ├── ConsoleAdapter.cs # Implements IAlertPort │ │ ├── TwilioAdapter.cs # Implements IAlertPort │ │ └── KafkaAlertAdapter.cs # Implements IAlertPort │ │ │ └── /ExternalLibs/ # (3rd Party SDKs live here) │ ├── FakeTwilioClient.cs │ └── FakeKafkaTypes.cs │ ├── Program.cs # Composition Root (The Wiring) └── After.csproj
See how the project places domain logic and ports inside the core while grouping adapters under infrastructure. section 5.5.3
Keep the boundary clean: a port that exposes SQL types leaks infrastructure into the core, while business rules placed in a controller or repository leak logic out. Design ports around what the application needs to do, and keep adapters focused on translation. section 5.3.5

