# aberkach/ft_irc architecture

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

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

## Overview

##### Project type and purpose
- This is a C++98–based network server project (“Mandatory”) implementing a standards-compliant IRC server, plus an optional IRC bot client (“Bonus”).
- Purpose: handle multiple concurrent IRC clients over TCP/IP (IPv4/IPv6), authenticate them, manage channels/users, parse IRC commands, broadcast messages, and optionally run an automated bot for channel assistance.

##### File structure
Top-level:
- .gitignore, Makefile, README.md
- Mandatory/ – IRC server code
– Inc/define.hpp, irc.hpp (central definitions and protocol constants)
– src/
· server/ (server socket setup, poll-based event loop, connection acceptance)
· client/ (per-client session state, read/write buffers)
· channel/ (channel data structures, member lists, topics)
· commands/ (implementations of IRC commands: JOIN, PRIVMSG, MODE, etc.)
· tools/ (parsing utilities, helper functions)
- Bonus/ – standalone IRC bot client (defines, main, bot logic and commands)
- tests/ – Python test script to simulate client commands

##### Review insights from the README
- Architecture: single-threaded, event-driven using poll()
- Core subsystems: connection management, protocol parser, command dispatcher, channel/user managers
- Compliance with RFC 1459/2812, plus additional bot features

##### Main components
a. External Clients & Bot
- “IRC Client(s)” (e.g., HexChat)
- “IRC Bot” (Bonus executable)
b. Network Layer
- TCP/IP Listener (IPv4/IPv6 socket)
- Event Loop (poll-based I/O multiplexer)
c. Core Server Modules
- Connection Manager: accepts new sockets, tracks client sessions
- Protocol Parser: tokenizes incoming messages into verbs/params
- Command Dispatcher: routes parsed commands to specific handlers
- Authentication Module: PASS, NICK, USER validation
- Channel Manager: create/join/leave channels, store channel metadata
- User Manager: track nicknames, modes, privileges
- Message Broadcaster: fan-out messages to channel members or specific user
d. Utility Subsystems
- Parsing Tools (parsers for message format, numeric replies)
- Server Utils (error handling, logging)
e. Data Stores (in-memory)
- Client State Objects
- Channel State Objects

##### Relationships and interactions
- “Listener” → “Event Loop” → “Connection Manager” → “Protocol Parser”
- “Parser” → “Command Dispatcher” → (Authentication / Channel Manager / User Manager / Message Broadcaster)
- Responses flow back: e.g., “Message Broadcaster” → “Connection Manager” → “Event Loop” → “Client”
- Bonus: “IRC Bot” behaves like another external client interacting through the same path

##### Architectural patterns and design principles
- Event-driven Reactor pattern (poll() drives dispatching)
- Modular separation: each command group in its own “commands/” module
- Single responsibility: Connection vs. Parsing vs. Business logic
- In-memory data model; no persistence layer

##### Technologies, frameworks, libraries
- C++98, POSIX sockets, poll() syscall
- Makefile build system
- Python for test harness (tests/testing_script.py)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actors
    IRCClient["IRC Client(s)"]:::external
    IRCBotExt["IRC Bot"]:::external

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        Listener["TCP/IP Listener"]:::network
        EventLoop["Event Loop\n(poll-based)"]:::network
    end

    %% Core Server Modules
    subgraph "Core Server Modules"
        direction TB
        ConnManager["Connection Manager"]:::core
        ProtoParser["Protocol Parser"]:::core
        CmdDispatcher["Command Dispatcher"]:::core
        AuthModule["Authentication Module"]:::core
        ChanManager["Channel Manager"]:::core
        UserManager["User Manager"]:::core
        MsgBroadcaster["Message Broadcaster"]:::core
    end

    %% Utility Subsystems
    subgraph "Utility Subsystems"
        direction TB
        ParsingTools["Parsing Tools"]:::util
        ServerUtils["Server Utilities"]:::util
    end

    %% In-memory Data Stores
    subgraph "In-Memory Data Stores"
        direction TB
        DataClientState["Client State Objects"]:::datastore
        DataChannelState["Channel State Objects"]:::datastore
    end

    %% Bonus IRC Bot Components
    subgraph "Bonus IRC Bot Client"
        direction TB
        BotDefs["Bot Definitions"]:::bot
        BotMain["Bot Main Exec"]:::bot
        BotLogic["Bot Logic"]:::bot
        BotCommands["Bot Commands"]:::bot
        BotUtils["Bot Utilities"]:::bot
    end

    %% Relationships
    IRCClient --> Listener
    IRCBotExt --> Listener

    Listener --> EventLoop
    EventLoop --> ConnManager
    ConnManager --> ProtoParser
    ProtoParser --> CmdDispatcher
    CmdDispatcher --> AuthModule
    CmdDispatcher --> ChanManager
    CmdDispatcher --> UserManager
    CmdDispatcher --> MsgBroadcaster

    MsgBroadcaster --> ConnManager
    ConnManager --> EventLoop
    EventLoop --> IRCClient
    EventLoop --> IRCBotExt

    ParsingTools --> ProtoParser
    ServerUtils --> ConnManager
    ServerUtils --> CmdDispatcher

    DataClientState -.-> ConnManager
    DataClientState -.-> UserManager
    DataChannelState -.-> ChanManager

    %% Bonus Bot flow
    BotDefs --> BotMain
    BotMain --> BotLogic
    BotLogic --> BotCommands
    BotLogic --> BotUtils
    BotMain --> Listener

    %% Click Events
    click Listener "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/server/server.cpp"
    click EventLoop "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/server/server.cpp"
    click ConnManager "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/server/server.cpp"
    click ProtoParser "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/tools/parse.cpp"
    click CmdDispatcher "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/server/utils.cpp"
    click AuthModule "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/commands/authenticationCommands.cpp"
    click ChanManager "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/channel/channel.cpp"
    click UserManager "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/client/client.cpp"
    click MsgBroadcaster "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/commands/channelOpsCommands.cpp"
    click ParsingTools "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/tools/utils.cpp"
    click ServerUtils "https://github.com/aberkach/ft_irc/blob/master/Mandatory/src/server/utils.cpp"
    click BotDefs "https://github.com/aberkach/ft_irc/blob/master/Bonus/Inc/defines.hpp"
    click BotMain "https://github.com/aberkach/ft_irc/blob/master/Bonus/main.cpp"
    click BotLogic "https://github.com/aberkach/ft_irc/blob/master/Bonus/src/bot.cpp"
    click BotCommands "https://github.com/aberkach/ft_irc/blob/master/Bonus/src/commands.cpp"
    click BotUtils "https://github.com/aberkach/ft_irc/blob/master/Bonus/src/tools.cpp"

    %% Styles
    classDef external fill:#cccccc,stroke:#888888,color:#000000,stroke-width:1px;
    classDef network fill:#cce5ff,stroke:#3399ff,color:#000000,stroke-width:1px;
    classDef core fill:#ccffcc,stroke:#33cc33,color:#000000,stroke-width:1px;
    classDef util fill:#ffe5b4,stroke:#ff9933,color:#000000,stroke-width:1px;
    classDef datastore fill:#ffffcc,stroke:#cccc33,color:#000000,stroke-width:1px;
    classDef bot fill:#e6ccff,stroke:#9933ff,color:#000000,stroke-width:1px;
```
