# haskell/network architecture

> Architecture diagram of the GitHub repository haskell/network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haskell/network
- Repository: https://github.com/haskell/network

## Overview

`network` is a Haskell library for creating and using network sockets. Its user-facing workflow is to resolve or construct an address, create and configure a socket, then exchange data through socket, `Handle`, or `ByteString` APIs. The tree also shows platform-specific POSIX and Windows support, ancillary-message handling, and STM operations. The README describes package support and coding conventions, not runtime wiring; most Haskell sources were not excerpted, so uncertain links are shown as unverified rather than asserted calls.

Main entry points: [`include/HsNet.h`](https://github.com/haskell/network/blob/master/include/HsNet.h) (Native declarations), [`Network/Socket.hs`](https://github.com/haskell/network/blob/master/Network/Socket.hs) (Socket operations), [`cbits/cmsg.c`](https://github.com/haskell/network/blob/master/cbits/cmsg.c) (Control messages), [`Network/Socket/Posix/MsgHdr.hsc`](https://github.com/haskell/network/blob/master/Network/Socket/Posix/MsgHdr.hsc) (POSIX messages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Socket APIs"]
  node_socket["Socket operations<br/>[Socket.hs]"]
  node_handles["Socket handles<br/>[Handle.hs]"]
  node_strict["Strict bytes<br/>[IO.hsc]"]
  node_lazy["Lazy bytes<br/>[Lazy.hs]"]
  node_stm["STM operations<br/>[STM.hs]"]
  node_shutdown["Shutdown<br/>[Shutdown.hs]"]
end

subgraph group_address["Addressing"]
  node_address_api["Address types<br/>[Address.hs]"]
  node_sockaddr["Socket addresses<br/>[SockAddr.hs]"]
  node_name["Name services<br/>[Name.hs]"]
  node_interfaces["Interfaces<br/>[If.hs]"]
end

subgraph group_platform["Platform Support"]
  node_options["Socket options<br/>[Options.hsc]"]
  node_unix["Unix sockets<br/>[Unix.hsc]"]
  node_posixmsg["POSIX messages<br/>[MsgHdr.hsc]"]
  node_winmsg["Windows messages<br/>[MsgHdr.hsc]"]
  node_winsock["Winsock setup<br/>[initWinSock.c]"]
end

subgraph group_native["Native Interop"]
  node_accept["Async accept shim<br/>[asyncAccept.c]"]
  node_cmsg["Control messages<br/>[cmsg.c]"]
  node_header["Native declarations<br/>[HsNet.h]"]
  node_definitions["Platform definitions<br/>[HsNetDef.h]"]
  node_unixcompat["Unix compatibility<br/>[afunix_compat.h]"]
end

node_caller(("Haskell application"))

node_caller -.->|"uses"| node_socket
node_caller -.->|"resolves names"| node_name
node_caller -.->|"uses"| node_handles
node_caller -.->|"exchanges bytes"| node_strict
node_caller -.->|"exchanges bytes"| node_lazy
node_caller -.->|"uses"| node_stm
node_caller -.->|"shuts down"| node_shutdown
node_caller -.->|"configures"| node_options
node_caller -.->|"queries"| node_interfaces
node_caller -.->|"uses"| node_unix
node_caller -.->|"uses"| node_posixmsg
node_caller -.->|"uses"| node_winmsg
node_address_api -.->|"uses"| node_sockaddr
node_socket -.->|"delegates"| node_accept
node_socket -.->|"initializes"| node_winsock
node_posixmsg -.->|"uses"| node_cmsg
node_winmsg -.->|"uses"| node_cmsg
node_header -->|"includes"| node_definitions
node_header -->|"includes"| node_unixcompat
node_accept -->|"includes"| node_header
node_cmsg -->|"includes"| node_header
node_winsock -->|"includes"| node_header

click node_socket "https://github.com/haskell/network/blob/master/Network/Socket.hs"
click node_handles "https://github.com/haskell/network/blob/master/Network/Socket/Handle.hs"
click node_strict "https://github.com/haskell/network/blob/master/Network/Socket/ByteString/IO.hsc"
click node_lazy "https://github.com/haskell/network/blob/master/Network/Socket/ByteString/Lazy.hs"
click node_stm "https://github.com/haskell/network/blob/master/Network/Socket/STM.hs"
click node_shutdown "https://github.com/haskell/network/blob/master/Network/Socket/Shutdown.hs"
click node_address_api "https://github.com/haskell/network/blob/master/Network/Socket/Address.hs"
click node_sockaddr "https://github.com/haskell/network/blob/master/Network/Socket/SockAddr.hs"
click node_name "https://github.com/haskell/network/blob/master/Network/Socket/Name.hs"
click node_interfaces "https://github.com/haskell/network/blob/master/Network/Socket/If.hs"
click node_options "https://github.com/haskell/network/blob/master/Network/Socket/Options.hsc"
click node_unix "https://github.com/haskell/network/blob/master/Network/Socket/Unix.hsc"
click node_posixmsg "https://github.com/haskell/network/blob/master/Network/Socket/Posix/MsgHdr.hsc"
click node_winmsg "https://github.com/haskell/network/blob/master/Network/Socket/Win32/MsgHdr.hsc"
click node_winsock "https://github.com/haskell/network/blob/master/cbits/initWinSock.c"
click node_accept "https://github.com/haskell/network/blob/master/cbits/asyncAccept.c"
click node_cmsg "https://github.com/haskell/network/blob/master/cbits/cmsg.c"
click node_header "https://github.com/haskell/network/blob/master/include/HsNet.h"
click node_definitions "https://github.com/haskell/network/blob/master/include/HsNetDef.h"
click node_unixcompat "https://github.com/haskell/network/blob/master/include/afunix_compat.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_socket,node_handles,node_strict,node_lazy,node_stm,node_shutdown toneBlue
class node_address_api,node_sockaddr,node_name,node_interfaces toneAmber
class node_options,node_unix,node_posixmsg,node_winmsg,node_winsock toneMint
class node_accept,node_cmsg,node_header,node_definitions,node_unixcompat toneRose
class node_caller toneIndigo
```

## Components

### Socket APIs

- [Socket operations](https://github.com/haskell/network/blob/master/Network/Socket.hs): `Network/Socket.hs`
- [Socket handles](https://github.com/haskell/network/blob/master/Network/Socket/Handle.hs): `Network/Socket/Handle.hs`
- [Strict bytes](https://github.com/haskell/network/blob/master/Network/Socket/ByteString/IO.hsc): `Network/Socket/ByteString/IO.hsc`
- [Lazy bytes](https://github.com/haskell/network/blob/master/Network/Socket/ByteString/Lazy.hs): `Network/Socket/ByteString/Lazy.hs`
- [STM operations](https://github.com/haskell/network/blob/master/Network/Socket/STM.hs): `Network/Socket/STM.hs`
- [Shutdown](https://github.com/haskell/network/blob/master/Network/Socket/Shutdown.hs): `Network/Socket/Shutdown.hs`

### Addressing

- [Address types](https://github.com/haskell/network/blob/master/Network/Socket/Address.hs): `Network/Socket/Address.hs`
- [Socket addresses](https://github.com/haskell/network/blob/master/Network/Socket/SockAddr.hs): `Network/Socket/SockAddr.hs`
- [Name services](https://github.com/haskell/network/blob/master/Network/Socket/Name.hs): `Network/Socket/Name.hs`
- [Interfaces](https://github.com/haskell/network/blob/master/Network/Socket/If.hs): `Network/Socket/If.hs`

### Platform Support

- [Socket options](https://github.com/haskell/network/blob/master/Network/Socket/Options.hsc): `Network/Socket/Options.hsc`
- [Unix sockets](https://github.com/haskell/network/blob/master/Network/Socket/Unix.hsc): `Network/Socket/Unix.hsc`
- [POSIX messages](https://github.com/haskell/network/blob/master/Network/Socket/Posix/MsgHdr.hsc): `Network/Socket/Posix/MsgHdr.hsc`
- [Windows messages](https://github.com/haskell/network/blob/master/Network/Socket/Win32/MsgHdr.hsc): `Network/Socket/Win32/MsgHdr.hsc`
- [Winsock setup](https://github.com/haskell/network/blob/master/cbits/initWinSock.c): `cbits/initWinSock.c`

### Native Interop

- [Async accept shim](https://github.com/haskell/network/blob/master/cbits/asyncAccept.c): `cbits/asyncAccept.c`
- [Control messages](https://github.com/haskell/network/blob/master/cbits/cmsg.c): `cbits/cmsg.c`
- [Native declarations](https://github.com/haskell/network/blob/master/include/HsNet.h): `include/HsNet.h`
- [Platform definitions](https://github.com/haskell/network/blob/master/include/HsNetDef.h): `include/HsNetDef.h`
- [Unix compatibility](https://github.com/haskell/network/blob/master/include/afunix_compat.h): `include/afunix_compat.h`

### Other components

- **Haskell application**

## Connections

- Haskell application → Socket operations: uses
- Haskell application → Name services: resolves names
- Haskell application → Socket handles: uses
- Haskell application → Strict bytes: exchanges bytes
- Haskell application → Lazy bytes: exchanges bytes
- Haskell application → STM operations: uses
- Haskell application → Shutdown: shuts down
- Haskell application → Socket options: configures
- Haskell application → Interfaces: queries
- Haskell application → Unix sockets: uses
- Haskell application → POSIX messages: uses
- Haskell application → Windows messages: uses
- Address types → Socket addresses: uses
- Socket operations → Async accept shim: delegates
- Socket operations → Winsock setup: initializes
- POSIX messages → Control messages: uses
- Windows messages → Control messages: uses
- Native declarations → Platform definitions: includes (evidence: `include/HsNet.h`)
- Native declarations → Unix compatibility: includes (evidence: `include/HsNet.h`)
- Async accept shim → Native declarations: includes (evidence: `cbits/asyncAccept.c`)
- Control messages → Native declarations: includes (evidence: `cbits/cmsg.c`)
- Winsock setup → Native declarations: includes (evidence: `cbits/initWinSock.c`)
