# ft-ali/ft_irc architecture

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

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

## Overview

##### Main Components

a. Entry Point & Core Server Engine
— main.cpp is the entry point where the application starts.
— The core server functionalities reside in Server.cpp (and its header in inc/Server.hpp). This is the central hub managing connections, processing commands, and overseeing sessions.

b. Client & Channel Modules
— The Client component (Client.cpp and Client.hpp) likely represents individual client connections and the logic for managing them.
— The Channel component (Channel.cpp and Channel.hpp) handles the grouping of clients into chat rooms or channels.

c. Command Handlers
— Under srcs/Command, each file (Invit.cpp, Join.cpp, Kick.cpp, Mode.cpp, Part.cpp, Quit.cpp, Topic.cpp) maps to a specific IRC-like command. These components are responsible for handling client requests and interacting with the Server, Client, and Channel modules.
– This suggests a Command Pattern where each command is ideally encapsulated as its own unit.

d. Bot Module
— The Bot folder (srcs/Bot) contains Bot.cpp, Bot.hpp, and mainBot.cpp along with a quotes.txt file. This module is likely an automated client providing additional interactive or administrative functionalities.

##### Relationships and Interactions

- main.cpp launches the application and initializes the Server component.
- The Server component (Server.cpp) accepts client connections (handled by Client.cpp) and orchestrates communication.
- Clients communicate with the Server by sending commands. The Server then delegates each command to the appropriate command handler (from the files in srcs/Command).
- Channel management (via Channel.cpp) keeps track of which clients are in which channels and handles broadcasting messages.
- The Bot module interacts with the Server similar to a client, automating responses or actions based on predefined logic (possibly leveraging text resources like quotes.txt).

##### Architectural Patterns & Design Principles

- Modular Design: The separation into inc, srcs, and further into subdirectories (Command and Bot) emphasizes separation of concerns, with each module handling a dedicated aspect of the system.
- Command Pattern: With each command (JOIN, PART, etc.) implemented as a separate module, the design encourages scalability and ease of addition for new commands.
- Object-Oriented Principles: The use of header files and corresponding source files (for Server, Client, Channel, Bot) suggests an object-oriented approach to encapsulate behaviors.

##### Technology and Tools

- C++ (indicated by .cpp and .hpp files)
- Build and Compilation: Managed via a Makefile, integrating into your system design for build automation.
- Version Control: .gitignore indicates the use of git.
- Editor Configuration: .vscode directory for editor-specific settings.
- Documentation and NOTES: Provide context on development plans (NOTES folder), which could be referenced but are not part of the runtime architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    mainApp["Main Application"]:::main
    external["External Clients"]:::external
    server["Server Engine"]:::server
    client["Client Manager"]:::client
    channel["Channel Manager"]:::channel
    bot["Bot Module"]:::bot

    subgraph "Command Handlers"
        CMD1["INVIT"]:::command
        CMD2["JOIN"]:::command
        CMD3["KICK"]:::command
        CMD4["MODE"]:::command
        CMD5["PART"]:::command
        CMD6["QUIT"]:::command
        CMD7["TOPIC"]:::command
    end

    mainApp -->|"launches"| server
    external -->|"connects_to"| server
    server -->|"handles"| client
    server -->|"manages"| channel
    server -->|"delegates_to"| CMD1
    server -->|"delegates_to"| CMD2
    server -->|"delegates_to"| CMD3
    server -->|"delegates_to"| CMD4
    server -->|"delegates_to"| CMD5
    server -->|"delegates_to"| CMD6
    server -->|"delegates_to"| CMD7
    server -->|"interacts_with"| bot

    click mainApp "https://github.com/ft-ali/ft_irc/blob/main/main.cpp"
    click server "https://github.com/ft-ali/ft_irc/blob/main/inc/Server.hpp"
    click server "https://github.com/ft-ali/ft_irc/blob/main/srcs/Server.cpp"
    click client "https://github.com/ft-ali/ft_irc/blob/main/inc/Client.hpp"
    click client "https://github.com/ft-ali/ft_irc/blob/main/srcs/Client.cpp"
    click channel "https://github.com/ft-ali/ft_irc/blob/main/inc/Channel.hpp"
    click channel "https://github.com/ft-ali/ft_irc/blob/main/srcs/Channel.cpp"
    click CMD1 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD2 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD3 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD4 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD5 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD6 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click CMD7 "https://github.com/ft-ali/ft_irc/tree/main/srcs/Command"
    click bot "https://github.com/ft-ali/ft_irc/tree/main/srcs/Bot"

    classDef main fill:#f8c471,stroke:#333,stroke-width:2px;
    classDef server fill:#82e0aa,stroke:#333,stroke-width:2px;
    classDef client fill:#85c1e9,stroke:#333,stroke-width:2px;
    classDef channel fill:#bb8fce,stroke:#333,stroke-width:2px;
    classDef command fill:#f1948a,stroke:#333,stroke-width:2px;
    classDef bot fill:#f7dc6f,stroke:#333,stroke-width:2px;
    classDef external fill:#d7bde2,stroke:#333,stroke-width:2px;
```
