# hek3er/irc-serv architecture

> Architecture diagram of the GitHub repository hek3er/irc-serv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hek3er/irc-serv
- Repository: https://github.com/hek3er/irc-serv

## Overview

##### Project Type and Purpose
- FT_IRC is a standalone C++ server application implementing the IRC protocol (RFC 2812).
- It provides a non‐blocking, event‐driven chat server that handles multiple concurrent clients, channels, and basic IRC commands (JOIN, PRIVMSG, KICK, INVITE, TOPIC, MODE, PASS, USER, NICK), plus DCC file transfers.

##### File Structure Analysis
- Top‐level source files grouped by responsibility:
- Channel.cpp/.hpp – channel state and management
- Client.cpp/.hpp – per‐connection client state
- Server.cpp/.hpp – listens on socket, accepts new connections, drives the event loop
- invite.cpp, join.cpp, kick.cpp, mode.cpp, topic.cpp – one module per IRC command/response logic
- replies.hpp – constant definitions for numeric reply codes
- main.cpp – parses CLI args (port, password), instantiates Server and starts it
- Build artifacts: Makefile; no external libraries beyond the C++ standard library and POSIX sockets.

##### Key Architectural Insights from README
- Non‐blocking I/O / Reactor pattern: single threaded event loop (select/poll)
- In‐memory data stores: containers mapping client fds → Client objects and channel names → Channel objects
- Modular command handlers invoked by a central dispatcher
- RFC compliance drives error codes and protocol parsing

##### Main Components
a. Network Layer (Server)
- Listener socket
- Event loop / Reactor (select, poll, or epoll)
b. Connection Manager (Client Manager)
- Accept new connections, track active client fds, client state (nick, user, modes)
c. Parser & Dispatcher
- Reads raw TCP data, parses IRC messages, routes to the appropriate command handler
d. Command Handlers
- JOIN, PRIVMSG, KICK, INVITE, TOPIC, MODE, PASS, USER, NICK, DCC module
e. Channel Manager
- Creates/tracks Channel objects, operator lists, topics, mode settings, password protection
f. Message Routing & Broadcast
- Delivers messages to single clients or all channel members
g. In‐Memory Data Stores
- <socket_fd, Client>
- <channel_name, Channel>
h. External Interfaces
- Reference IRC client (e.g., LimeChat or netcat)
- DCC file‐transfer peer‐to‐peer data channel

##### Relationships and Data Flows
- Listener → accept() → Connection Manager → register fd in Reactor
- Reactor signals “readable” → Server reads raw bytes → Parser → Dispatcher
- Dispatcher invokes specific Command Handler → Handler updates Client or Channel state → may generate outgoing messages
- Router sends replies via socket fds back to clients or broadcasts to channel members

##### Architectural Patterns & Design Principles
- Reactor Pattern for non‐blocking I/O
- Single Responsibility: each .cpp module handles one IRC command
- Inversion of Control: central dispatcher calls handlers based on command type
- Encapsulation of state: Client and Channel classes hold protocol state

##### Technologies & Frameworks
- C++98, STL containers (std::map, std::string)
- POSIX sockets API (socket, bind, listen, accept, fcntl, select/poll)
- Makefile build system

## Diagram (Mermaid)

```mermaid
flowchart TB
    client["IRC Client (netcat/LimeChat)"]:::external
    main["Application Startup\n(main.cpp)"]:::core
    listener["Listener Socket"]:::network
    reactor["Reactor/Event Loop"]:::core
    parser["Parser"]:::core
    dispatcher["Dispatcher"]:::core

    subgraph "Command Handlers"
        join["JOIN Handler"]:::logic
        invite["INVITE Handler"]:::logic
        kick["KICK Handler"]:::logic
        mode["MODE Handler"]:::logic
        topic["TOPIC Handler"]:::logic
        pass["PASS Handler"]:::logic
        user["USER/NICK Handler"]:::logic
        dcc["DCC Transfer Module"]:::logic
    end

    subgraph "Data Stores"
        clientMgr["Connection Manager\n(Client objects)"]:::datastore
        channelMgr["Channel Manager\n(Channel objects)"]:::datastore
        replies["Numeric Reply Codes"]:::datastore
    end

    client -->|connects| listener
    main --> listener
    main --> reactor
    listener -->|register fd| reactor
    reactor -->|read data| parser
    parser -->|parse message| dispatcher
    dispatcher -->|invoke| join
    dispatcher -->|invoke| invite
    dispatcher -->|invoke| kick
    dispatcher -->|invoke| mode
    dispatcher -->|invoke| topic
    dispatcher -->|invoke| pass
    dispatcher -->|invoke| user
    dispatcher -->|invoke| dcc
    join -->|update state| channelMgr
    invite -->|update state| channelMgr
    kick -->|update state| channelMgr
    mode -->|update state| channelMgr
    topic -->|update state| channelMgr
    pass -->|auth| clientMgr
    user -->|set identity| clientMgr
    dcc -->|peer transfer| clientMgr
    join -->|use codes| replies
    invite -->|use codes| replies
    kick -->|use codes| replies
    mode -->|use codes| replies
    topic -->|use codes| replies
    pass -->|use codes| replies
    user -->|use codes| replies
    dcc -->|use codes| replies
    join --> client
    invite --> client
    kick --> client
    mode --> client
    topic --> client
    pass --> client
    user --> client
    dcc --> client

    click listener "https://github.com/hek3er/irc-serv/blob/main/Server.cpp"
    click reactor "https://github.com/hek3er/irc-serv/blob/main/Server.cpp"
    click clientMgr "https://github.com/hek3er/irc-serv/blob/main/Client.cpp"
    click channelMgr "https://github.com/hek3er/irc-serv/blob/main/Channel.cpp"
    click parser "https://github.com/hek3er/irc-serv/blob/main/Server.cpp"
    click dispatcher "https://github.com/hek3er/irc-serv/blob/main/Server.cpp"
    click join "https://github.com/hek3er/irc-serv/blob/main/join.cpp"
    click invite "https://github.com/hek3er/irc-serv/blob/main/invite.cpp"
    click kick "https://github.com/hek3er/irc-serv/blob/main/kick.cpp"
    click mode "https://github.com/hek3er/irc-serv/blob/main/mode.cpp"
    click topic "https://github.com/hek3er/irc-serv/blob/main/topic.cpp"
    click replies "https://github.com/hek3er/irc-serv/blob/main/replies.hpp"
    click main "https://github.com/hek3er/irc-serv/blob/main/main.cpp"

    classDef external fill:#E0F7FA,stroke:#006064;
    classDef network fill:#B3E5FC,stroke:#0288D1;
    classDef core fill:#FFE0B2,stroke:#FB8C00;
    classDef logic fill:#C8E6C9,stroke:#2E7D32;
    classDef datastore fill:#FFF9C4,stroke:#F9A825;
```
