== Lightning Network Architecture

In the first part of this book we introduced the main concepts of the Lightning Network, worked through a comprehensive example of routing a payment and set up the tools we can use to explore further. In the second part of the book we will explore the Lightning Network in a lot more technical detail, dissecting each of the building blocks.

In this section we will outline the components of the Lightning Network in more detail and provide a "big picture" perspective to guide you through the following chapters.

=== The Lightning Network Protocol Suite

The Lightning Network is composed of a complex collection of protocols that run on top of the internet. We can broadly classify these protocols into five distinct layers that make up a _protocol stack_, where each layer build upon and uses the protocols in the layer below. Also, each protocol layer abstracts the underlying layers and "hides" some of the complexity.

The architecture diagram shown in <<lightning_network_protocol_suite>> provides an overview of these layers and their component protocols:

[[lightning_network_protocol_suite]]
.The Lightning Network Protocol Suite
image::images/lightning-network-protocol-suite.png[]

The five layers of the Lightning Network, from the bottom up, are:

Network Connection Layer:: This contains the protocols that interact directly with the internet core protocols (TCP/IP), overlay protocols (Tor v2/v3), and internet services (DNS). This layer also contains the cryptographic transport protocols that protect Lightning messages.

Messaging Layer:: This layer contains the protocols that nodes use to negotiate features, format messages, and encode message fields.

Peer-2-Peer (P2P) Layer:: This layer is primary protocol layer for communication between Lightning nodes and contains all the different messages exchanged between nodes.

Routing Layer:: This layer contains the protocols used to route payments between nodes, end-to-end and atomically. This layer contains the "core" functionality of the Lightning Network: routed payments.

Payment Layer:: The highest layer of the network, which presents a reliable payment interface to applications.
