# mxcalll/ft_irc architecture

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

- Interactive diagram: https://gitdiagram.com/mxcalll/ft_irc
- Repository: https://github.com/mxcalll/ft_irc

## Overview

This repository is a C++ IRC server implementation. The codebase is organized around a central server process that manages connected clients, channels, and IRC command handling.

1. Core runtime
- `main.cpp` is the entry point and likely bootstraps the server, parses startup arguments, and starts the main server loop.
- The runtime appears to be a single native executable rather than a multi-service system.

2. Primary domain objects
- `Server` is the top-level coordinator.
- `Client` represents an IRC connection/user.
- `Channel` represents an IRC room and its membership/state.
- `Bot` suggests an automated participant or integration component that behaves like a client but with special logic.

3. Command handling boundary
- `src/cmd.cpp` is the command-processing layer.
- This is likely where incoming IRC protocol messages are parsed and dispatched to server actions such as join, part, nick changes, messaging, and admin commands.
- For architecture diagrams, this is the main boundary between protocol input and application state changes.

4. Server coordination responsibilities
- `Server` probably owns the collection of clients and channels, tracks the listening socket/accept loop, and routes messages between entities.
- It is the central hub for connection lifecycle management and message broadcast.

5. Client management flow
- `Client` likely stores per-connection state such as nickname, authentication status, user modes, and current channel memberships.
- Client actions are probably driven by parsed commands and then reflected back into server/channel state.

6. Channel membership and messaging
- `Channel` likely encapsulates a room’s name, member list, topic, modes, and broadcast behavior.
- Message delivery probably flows from `Server` or command handlers into `Channel`, which then distributes messages to its member clients.

7. Bot subsystem
- `Bot` is a distinct subsystem from regular users.
- It likely acts as an automated client or helper tied into the same server/channel model, useful for testing, moderation, or predefined responses.

8. Shared utilities
- `Utils` contains cross-cutting helpers used by multiple modules.
- This likely includes string handling, parsing helpers, validation, and other reusable logic that should not live inside domain classes.

9. Source/header structure
- Public interfaces live in `include/`, while implementations are in `src/`.
- That separation suggests a classic C++ modular design where each major subsystem has a dedicated class interface and implementation file.

10. Data flow at a high level
- External IRC client or bot connects to the server.
- `Server` accepts the connection and creates/updates a `Client`.
- Incoming text is parsed by command logic in `cmd.cpp`.
- Command handlers mutate `Client`/`Channel` state and trigger responses back through `Server`.
- Channels fan out messages to their member clients.

11. Architectural boundaries
- Network/protocol concerns sit at the server/command layer.
- User/session state lives in `Client`.
- Group state lives in `Channel`.
- Automation or special behavior is isolated in `Bot`.
- Common parsing and helper logic is isolated in `Utils`.

12. Likely deployment shape
- This is a single executable built from `main.cpp` and the `src/` files, probably with a simple Makefile-based build.
- There are no signs of external infrastructure or databases; state appears to be in-memory and managed by the server process.

Overall, the architecture is a compact, object-oriented IRC server with a central `Server` coordinator, per-connection `Client` state, per-room `Channel` state, command dispatch in `cmd.cpp`, and utility/bot support around that core.

Main entry points: [`include/Server.hpp`](https://github.com/mxcalll/ft_irc/blob/master/include/Server.hpp) (Server), [`src/cmd.cpp`](https://github.com/mxcalll/ft_irc/blob/master/src/cmd.cpp) (cmd.cpp), [`include/Client.hpp`](https://github.com/mxcalll/ft_irc/blob/master/include/Client.hpp) (Client), [`include/Channel.hpp`](https://github.com/mxcalll/ft_irc/blob/master/include/Channel.hpp) (Channel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["main.cpp<br/>entrypoint<br/>[main.cpp]"]
  node_impl["src/*.cpp<br/>implementations"]
end

subgraph group_server["Server core"]
  node_server_core["Server<br/>orchestrator<br/>[Server.hpp]"]
  node_acceptor(("Accept loop<br/>network ingress<br/>[Server.cpp]"))
  node_registry[("Session store<br/>state registry<br/>[Server.cpp]")]
  node_router["Message router<br/>broadcast routing<br/>[Server.cpp]"]
end

subgraph group_protocol["Protocol handling"]
  node_cmd["cmd.cpp<br/>command dispatcher<br/>[cmd.cpp]"]
end

subgraph group_domain["Domain model"]
  node_client["Client<br/>session model<br/>[Client.hpp]"]
  node_channel["Channel<br/>room model<br/>[Channel.hpp]"]
  node_bot["Bot<br/>automated client<br/>[Bot.hpp]"]
end

subgraph group_shared["Shared code"]
  node_utils["Utils<br/>shared helpers<br/>[Utils.hpp]"]
end

node_main -->|"starts"| node_server_core
node_server_core -->|"owns"| node_acceptor
node_server_core -->|"tracks"| node_registry
node_server_core -->|"routes"| node_router
node_acceptor -->|"creates"| node_client
node_registry -->|"stores"| node_client
node_registry -->|"stores"| node_channel
node_cmd -->|"invokes"| node_server_core
node_cmd -->|"mutates"| node_client
node_cmd -->|"mutates"| node_channel
node_router -->|"delivers"| node_client
node_router -->|"broadcasts"| node_channel
node_channel -->|"contains"| node_client
node_bot -->|"connects"| node_server_core
node_bot -->|"drives"| node_cmd
node_utils -->|"supports"| node_cmd
node_utils -->|"supports"| node_server_core
node_impl -.->|"implements"| node_server_core
node_impl -.->|"implements"| node_client
node_impl -.->|"implements"| node_channel
node_impl -.->|"implements"| node_bot
node_impl -.->|"implements"| node_utils
node_impl -.->|"implements"| node_cmd

click node_main "https://github.com/mxcalll/ft_irc/blob/master/main.cpp"
click node_server_core "https://github.com/mxcalll/ft_irc/blob/master/include/Server.hpp"
click node_acceptor "https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp"
click node_registry "https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp"
click node_router "https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp"
click node_cmd "https://github.com/mxcalll/ft_irc/blob/master/src/cmd.cpp"
click node_client "https://github.com/mxcalll/ft_irc/blob/master/include/Client.hpp"
click node_channel "https://github.com/mxcalll/ft_irc/blob/master/include/Channel.hpp"
click node_bot "https://github.com/mxcalll/ft_irc/blob/master/include/Bot.hpp"
click node_utils "https://github.com/mxcalll/ft_irc/blob/master/include/Utils.hpp"

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_main,node_impl toneBlue
class node_server_core,node_acceptor,node_registry,node_router toneAmber
class node_cmd toneMint
class node_client,node_channel,node_bot toneRose
class node_utils toneIndigo
```

## Components

### Runtime

Single native IRC server executable and startup entrypoint

- [main.cpp](https://github.com/mxcalll/ft_irc/blob/master/main.cpp): entrypoint · Program startup and server bootstrap · `main.cpp`
- **src/*.cpp**: implementations · Concrete implementations for the public IRC modules

### Server core

Central coordination of connections, state, and message flow

- [Server](https://github.com/mxcalll/ft_irc/blob/master/include/Server.hpp): orchestrator · Top-level coordinator for IRC state and execution · `include/Server.hpp`
- [Accept loop](https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp): network ingress · Listens for incoming connections and creates sessions · `src/Server.cpp`
- [Session store](https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp): state registry · Tracks connected clients and active channels · `src/Server.cpp`
- [Message router](https://github.com/mxcalll/ft_irc/blob/master/src/Server.cpp): broadcast routing · Routes protocol events between clients and channels · `src/Server.cpp`

### Protocol handling

IRC command parsing and dispatch boundary

- [cmd.cpp](https://github.com/mxcalll/ft_irc/blob/master/src/cmd.cpp): command dispatcher · Parses IRC commands and maps them to server actions · `src/cmd.cpp`

### Domain model

Per-client, per-channel, and bot behavior

- [Client](https://github.com/mxcalll/ft_irc/blob/master/include/Client.hpp): session model · Per-connection user state and memberships · `include/Client.hpp`
- [Channel](https://github.com/mxcalll/ft_irc/blob/master/include/Channel.hpp): room model · IRC room state, topic, modes, and membership · `include/Channel.hpp`
- [Bot](https://github.com/mxcalll/ft_irc/blob/master/include/Bot.hpp): automated client · Specialized automated participant or helper · `include/Bot.hpp`

### Shared code

Cross-cutting helpers used across the server

- [Utils](https://github.com/mxcalll/ft_irc/blob/master/include/Utils.hpp): shared helpers · Common parsing and string utilities · `include/Utils.hpp`

## Connections

- main.cpp → Server: starts · Bootstraps the server process
- Server → Accept loop: owns · Manages incoming connection handling
- Server → Session store: tracks · Maintains connected clients and channels
- Server → Message router: routes · Coordinates message delivery and state changes
- Accept loop → Client: creates · Converts connections into client sessions
- Session store → Client: stores · Keeps active client objects
- Session store → Channel: stores · Keeps active channel objects
- cmd.cpp → Server: invokes · Issues server actions from parsed commands
- cmd.cpp → Client: mutates · Updates user/session state
- cmd.cpp → Channel: mutates · Joins, parts, and message fanout update rooms
- Message router → Client: delivers · Sends replies and broadcasts to clients
- Message router → Channel: broadcasts · Fans messages out to channel members
- Channel → Client: contains · Channels maintain member sets
- Bot → Server: connects · Acts as a special participant over the same server model
- Bot → cmd.cpp: drives · Can trigger command flows like a client
- Utils → cmd.cpp: supports · Provides parsing and validation helpers
- Utils → Server: supports · Provides shared helper logic
- src/*.cpp → Server: implements · Concrete server logic lives in src/Server.cpp
- src/*.cpp → Client: implements · Concrete client logic lives in src/Client.cpp
- src/*.cpp → Channel: implements · Concrete channel logic lives in src/Channel.cpp
- src/*.cpp → Bot: implements · Concrete bot logic lives in src/Bot.cpp
- src/*.cpp → Utils: implements · Utility implementation lives in src/Utils.cpp
- src/*.cpp → cmd.cpp: implements · Command handling lives in src/cmd.cpp
