# sdp-io/c-irc-server architecture

> Architecture diagram of the GitHub repository sdp-io/c-irc-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sdp-io/c-irc-server
- Repository: https://github.com/sdp-io/c-irc-server

## Overview

#### Purpose and Entry Point
This repository implements a minimal IRC server in C. Process startup and the main event loop are rooted in `src/main.c`; networking setup and socket/event handling are delegated to `src/network.c` through interfaces in `include/network.h`.

#### Core Server State
Shared IRC-domain structures are defined in `include/structs.h`, with user and channel APIs split by responsibility:
- Users: `include/user.h`, `src/user.c`
- Channels and membership: `include/channel.h`, `src/channel.c`
- Protocol messages/constants: `include/messages.h`

These structures form the in-memory authority for connected clients, identities, channels, and routing relationships.

#### Network Acceptance and I/O Boundary
`src/network.c` owns the transport-facing boundary: server socket setup, client connection lifecycle, reads, and writes. It isolates TCP/socket concerns from IRC command semantics via `include/network.h`.

Control flow is broadly: initialize server → accept client connections → receive IRC text lines → dispatch command processing → emit replies or broadcasts through the network layer.

#### Command Parsing and Protocol Dispatch
`src/command.c` implements IRC command handling behind `include/command.h`. It is the boundary between untrusted client input and state mutations in user/channel components.

Command processing consumes network input, identifies protocol commands, validates client/session state, updates server state, and generates IRC-format responses using definitions in `include/messages.h`.

#### User Lifecycle and Identity
`src/user.c` manages client-associated IRC user state, including registration/identity and lookup-oriented operations. Its public contract is `include/user.h`; common server data types are shared through `include/structs.h`.

This layer is invoked by command handling and network disconnect/error paths, rather than directly exposing socket mechanics.

#### Channels and Message Fan-Out
`src/channel.c` manages channels, membership, and channel-scoped operations exposed by `include/channel.h`. Commands such as joining, leaving, or sending channel messages flow from `src/command.c` into this layer, which determines recipients and relies on the network/message path for delivery.

#### Supporting Runtime Dependencies
The server is a native C process built via `Makefile`. It uses the local hashmap implementation in `lib/hashmap.h` for indexed in-memory state where needed. `motd.txt` is runtime server content for IRC message-of-the-day behavior. The project has no indicated database, web runtime, cloud service, or external broker dependency.

Main entry points: [`src/command.c`](https://github.com/sdp-io/c-irc-server/blob/main/src/command.c) (Command dispatch), [`src/channel.c`](https://github.com/sdp-io/c-irc-server/blob/main/src/channel.c) (Channel membership), [`src/network.c`](https://github.com/sdp-io/c-irc-server/blob/main/src/network.c) (Network I/O), [`src/user.c`](https://github.com/sdp-io/c-irc-server/blob/main/src/user.c) (User lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server Runtime"]
  node_build["Makefile<br/>build"]
  node_main["Server entry point<br/>C process<br/>[main.c]"]
  node_network["Network I/O<br/>transport layer<br/>[network.c]"]
  node_network_api["Network API<br/>C header<br/>[network.h]"]
  node_motd["MOTD content<br/>runtime content<br/>[motd.txt]"]
end

subgraph group_protocol["IRC Protocol &amp; State"]
  node_command["Command dispatch<br/>protocol parser<br/>[command.c]"]
  node_command_api["Command API<br/>C header<br/>[command.h]"]
  node_messages["IRC messages<br/>protocol definitions<br/>[messages.h]"]
  node_state[("Shared server state<br/>in-memory domain model<br/>[structs.h]")]
  node_users["User lifecycle<br/>identity service<br/>[user.c]"]
  node_user_api["User API<br/>C header<br/>[user.h]"]
  node_channels["Channel membership<br/>channel service<br/>[channel.c]"]
  node_channel_api["Channel API<br/>C header<br/>[channel.h]"]
  node_hashmap[("Hashmap<br/>in-memory index<br/>[hashmap.h]")]
end

node_build -->|"builds"| node_main
node_main -->|"initializes event loop"| node_network
node_network -.->|"implements"| node_network_api
node_network -->|"received IRC lines"| node_command
node_command -.->|"implements"| node_command_api
node_command -->|"registration and identity"| node_users
node_command -->|"join, leave, message"| node_channels
node_command -->|"formats replies"| node_messages
node_command -->|"validates session state"| node_state
node_users -.->|"implements"| node_user_api
node_users -->|"manages identities"| node_state
node_channels -.->|"implements"| node_channel_api
node_channels -->|"manages membership"| node_state
node_channels -->|"recipient delivery"| node_network
node_network -->|"disconnect cleanup"| node_users
node_users -->|"indexed lookup"| node_hashmap
node_channels -->|"indexed lookup"| node_hashmap
node_command -->|"MOTD response"| node_motd

click node_build "https://github.com/sdp-io/c-irc-server/tree/main/Makefile"
click node_main "https://github.com/sdp-io/c-irc-server/blob/main/src/main.c"
click node_network "https://github.com/sdp-io/c-irc-server/blob/main/src/network.c"
click node_network_api "https://github.com/sdp-io/c-irc-server/blob/main/include/network.h"
click node_motd "https://github.com/sdp-io/c-irc-server/blob/main/motd.txt"
click node_command "https://github.com/sdp-io/c-irc-server/blob/main/src/command.c"
click node_command_api "https://github.com/sdp-io/c-irc-server/blob/main/include/command.h"
click node_messages "https://github.com/sdp-io/c-irc-server/blob/main/include/messages.h"
click node_state "https://github.com/sdp-io/c-irc-server/blob/main/include/structs.h"
click node_users "https://github.com/sdp-io/c-irc-server/blob/main/src/user.c"
click node_user_api "https://github.com/sdp-io/c-irc-server/blob/main/include/user.h"
click node_channels "https://github.com/sdp-io/c-irc-server/blob/main/src/channel.c"
click node_channel_api "https://github.com/sdp-io/c-irc-server/blob/main/include/channel.h"
click node_hashmap "https://github.com/sdp-io/c-irc-server/blob/main/lib/hashmap.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_build,node_main,node_network,node_network_api,node_motd toneBlue
class node_command,node_command_api,node_messages,node_state,node_users,node_user_api,node_channels,node_channel_api,node_hashmap toneAmber
```

## Components

### Server Runtime

- [Makefile](https://github.com/sdp-io/c-irc-server/tree/main/Makefile): build · Builds the native C server. · `Makefile`
- [Server entry point](https://github.com/sdp-io/c-irc-server/blob/main/src/main.c): C process · Initializes the server and runs the event loop. · `src/main.c`
- [Network I/O](https://github.com/sdp-io/c-irc-server/blob/main/src/network.c): transport layer · Owns sockets, client lifecycle, reads, and writes. · `src/network.c`
- [Network API](https://github.com/sdp-io/c-irc-server/blob/main/include/network.h): C header · `include/network.h`
- [MOTD content](https://github.com/sdp-io/c-irc-server/blob/main/motd.txt): runtime content · Message-of-the-day text served by IRC behavior. · `motd.txt`

### IRC Protocol & State

- [Command dispatch](https://github.com/sdp-io/c-irc-server/blob/main/src/command.c): protocol parser · Validates IRC input and coordinates state mutations and replies. · `src/command.c`
- [Command API](https://github.com/sdp-io/c-irc-server/blob/main/include/command.h): C header · `include/command.h`
- [IRC messages](https://github.com/sdp-io/c-irc-server/blob/main/include/messages.h): protocol definitions · IRC message formats and constants. · `include/messages.h`
- [Shared server state](https://github.com/sdp-io/c-irc-server/blob/main/include/structs.h): in-memory domain model · Authority for clients, identities, channels, and routing relationships. · `include/structs.h`
- [User lifecycle](https://github.com/sdp-io/c-irc-server/blob/main/src/user.c): identity service · Manages registration, identity, and user lookup. · `src/user.c`
- [User API](https://github.com/sdp-io/c-irc-server/blob/main/include/user.h): C header · `include/user.h`
- [Channel membership](https://github.com/sdp-io/c-irc-server/blob/main/src/channel.c): channel service · Manages channels, membership, and recipient selection. · `src/channel.c`
- [Channel API](https://github.com/sdp-io/c-irc-server/blob/main/include/channel.h): C header · `include/channel.h`
- [Hashmap](https://github.com/sdp-io/c-irc-server/blob/main/lib/hashmap.h): in-memory index · Local indexed-state dependency. · `lib/hashmap.h`

## Connections

- Makefile → Server entry point: builds
- Server entry point → Network I/O: initializes event loop
- Network I/O → Network API: implements
- Network I/O → Command dispatch: received IRC lines
- Command dispatch → Command API: implements
- Command dispatch → User lifecycle: registration and identity
- Command dispatch → Channel membership: join, leave, message
- Command dispatch → IRC messages: formats replies
- Command dispatch → Shared server state: validates session state
- User lifecycle → User API: implements
- User lifecycle → Shared server state: manages identities
- Channel membership → Channel API: implements
- Channel membership → Shared server state: manages membership
- Channel membership → Network I/O: recipient delivery
- Network I/O → User lifecycle: disconnect cleanup
- User lifecycle → Hashmap: indexed lookup
- Channel membership → Hashmap: indexed lookup
- Command dispatch → MOTD content: MOTD response
