Hexagonal architecture(aka ports & adapters) makes the business logic the centerpiece of the architecture. The core idea is that all inputs(eg UI) and outputs (eg database )  to business logic loosely coupled using (ports or interfaces) and hence swappable . The core application does not know the nature of the input device . (eg UI/ command line test tool) The focus is on identifying what is inside the core and what is outside the core (ui, infractsture (database, email, sms , messaging)

In doing so, you isolate the central logic (the core) of your application from outside concerns. Because of loose coupling the input to business logic could be 

this makes hexgonal architecuture very well suited for testing / staging environments.

the output like

can be swappable eg in staging environment you would not want to actually send eamils, hence there could be a dummy email service.

Imagine a hexagon shape with another, larger hexagon shape around it.  The center hexagon is the core of the application (the business and application logic).  And each side of the inner hexagon represents the ports/interface. The layer between the core and the outer hexagon is the adapter layer. Hence for supporting a new input communication method a new adapter has to be written which uses the interface api  . The core business logic was not touched. Hence in some sense the system is core surrounded by interfaces to the outside world. For input the interfaces /ports are implemented by the core and for output the interfaces/ports are implemented by the adapter. 

 

Image reference : https://vaadin.com/learn/tutorials/ddd/ddd_and_hexagonal

ie

Note that hexagon has no special meaning per se. the only point is that there will be multiple interfaces/ports and adapters. one edge of the hexagon(port/interface) represents one reason to talk to the external world. in other words the hexagon is not a hexagon because the number six is important, but rather to allow the people doing the drawing to have room to insert ports and adapters as they need, not being constrained by a one-dimensional layered drawing. There may be port/interface for 

Layered architecture

In the Layered architecture application is split into at least three distinct areas of code: 

Each layer has well defined responsibilities , separation of concerns is a key advantage of this approach. The different layers can be handled by different teams (front end team typically handles presentation layer, back end team handles business logic and persistence layer).  How ever it does have the disadvantage that it does not represent the fact that app is likely to be used by more than one user interface/database and typically the coupling between the layers is tight. so testing with a differnt input (like testing from commandline) becomes difficult.

Advantage of hexgonal architecture 

The advatnage of hexagonal architecture over n layer / tier architecture is that hexagonal architecture has a very strong emphasis on decoupling of external inputs/outputs from the core business logic hence 

Note that since frameworks by definition want to be in control hence use of frameworks as much as possible should be in the adapter so that domain model is clean. Libraries are less intrusive so they can be used.