Core Components - edgeof8/tIRC GitHub Wiki
tIRC is designed with a modular architecture, where distinct components handle specific aspects of the client's functionality. This separation of concerns promotes maintainability, testability, and extensibility. This page provides an overview of the primary components.
For a higher-level view of how these components interact, see the Architecture page. For a detailed file structure, refer to the Codebase Overview.
Key Architectural Components
The README.md
and existing architecture documents highlight several key components:
-
IRCClient_Logic
:- Role: The central orchestrator of the application. It initializes and coordinates all other major components and manages the main application lifecycle and event loop.
- Responsibilities:
- Setting up and running the main
asyncio
event loop. - Coordinating the startup and shutdown sequences (delegating to
ClientShutdownCoordinator
). - Initiating connections (delegating to
ConnectionOrchestrator
). - Managing high-level UI state and interactions (delegating to
ClientViewManager
andUIManager
). - Serving as a central point of access for shared components like
StateManager
,EventManager
, andScriptManager
.
- Setting up and running the main
- Found in:
tirc_core/client/irc_client_logic.py
-
ConnectionOrchestrator
:- Role: Manages the entire lifecycle of a server connection, abstracting away complex connection details.
- Responsibilities:
- Establishing the TCP/SSL socket connection (via
NetworkHandler
). - Performing IRCv3 capability negotiation (coordinating with
CapNegotiator
). - Handling SASL authentication (coordinating with
SaslAuthenticator
). - Managing NICK/USER registration (coordinating with
RegistrationHandler
). - Handling connection state transitions, error recovery, and timeouts for each phase.
- Establishing the TCP/SSL socket connection (via
- Found in:
tirc_core/client/connection_orchestrator.py
-
ClientShutdownCoordinator
:- Role: Ensures a graceful and orderly shutdown of all client components.
- Responsibilities:
- Signaling active asynchronous tasks to terminate.
- Disconnecting cleanly from the IRC server.
- Releasing UI resources (e.g., closing Curses).
- Unloading scripts and saving final state via
StateManager
.
- Found in:
tirc_core/client/client_shutdown_coordinator.py
-
ClientViewManager
:- Role: Manages UI-specific logic related to different views (e.g., single pane, split-screen) and active context switching.
- Responsibilities:
- Maintaining the state of available views.
- Tracking the currently focused context (channel, query, status window).
- Orchestrating UI updates when the active context changes.
- Handling user commands related to window navigation and view manipulation (e.g.,
/split
,/nextwindow
).
- Found in:
tirc_core/client/client_view_manager.py
-
IPCManager
:- Role: Manages the Inter-Process Communication (IPC) server for receiving remote commands.
- Responsibilities:
- Starting and stopping a local TCP socket server.
- Listening for incoming connections from external processes (e.g.,
tirc.py --send-raw
). - Reading raw command strings from connected clients.
- Injecting received commands into the
CommandHandler
for processing.
- Found in:
tirc_core/ipc_manager.py
-
NetworkHandler
:- Role: Handles all low-level asynchronous network I/O for the IRC protocol.
- Responsibilities:
- Managing
asyncio.StreamReader
andStreamWriter
for a connection. - Sending raw IRC messages to the server.
- Receiving raw IRC messages, buffering, and splitting them into complete lines.
- Passing complete lines to the
IRCProtocol
parser.
- Managing
- Found in:
tirc_core/network_handler.py
-
StateManager
:- Role: The exclusive source of truth for all connection, session, and client-specific runtime state.
- Responsibilities:
- Providing thread-safe access to state data.
- Persisting state to disk (e.g.,
state.json
) and restoring it on startup. - Managing connection details, authentication state, channel states, user preferences, message history, etc.
- Notifying other components of state changes.
- Found in:
tirc_core/state_manager.py
(See also State Management)
-
EventManager
:- Role: Manages the dispatching of events throughout the application, enabling loose coupling between components.
- Responsibilities:
- Allowing components and scripts to subscribe to specific events (e.g.,
PRIVMSG
,JOIN
,CLIENT_CONNECTED
). - Dispatching events asynchronously to all registered handlers.
- Preparing and formatting event data.
- Allowing components and scripts to subscribe to specific events (e.g.,
- Found in:
tirc_core/event_manager.py
-
CommandHandler
:- Role: Discovers, registers, and dispatches all built-in and script-defined commands.
- Responsibilities:
- Dynamically loading command definitions from modules in the
tirc_core/commands/
directory usingpkgutil.walk_packages
. - Parsing user input to identify commands and arguments.
- Executing the appropriate command handler.
- Managing command aliases and help text.
- Dynamically loading command definitions from modules in the
- Found in:
tirc_core/commands/command_handler.py
(See also Command System)
-
UIManager
and UI Sub-components:- Role: Orchestrates the terminal-based user interface.
- Responsibilities (UIManager as orchestrator):
- Coordinating updates and refreshes for all UI elements.
- Managing overall UI layout and drawing cycles.
- Key UI Sub-components:
CursesManager
: Low-level Curses initialization, teardown, and color management.WindowLayoutManager
: Calculates sizes and positions of UI windows.MessagePanelRenderer
: Displays chat messages for the active context.SidebarPanelRenderer
: Renders the channel/user list.StatusBarRenderer
: Displays status information.InputLineRenderer
: Handles the input prompt and text entry.InputHandler
: Processes user input from the keyboard.SafeCursesUtils
: Provides safe, utility functions forcurses
drawing operations.
- Found in:
tirc_core/ui/
andtirc_core/client/
(for some renderers and managers) (See also UI System)
-
ScriptManager
:- Role: Discovers, loads, manages, and unloads all user-provided Python scripts.
- Responsibilities:
- Scanning the
scripts/
directory for valid scripts. - Providing scripts with the
ScriptAPIHandler
for client interaction. - Managing script lifecycles (
load
,unload
). - Handling script dependencies and dispatching events to script handlers.
- Scanning the
- Found in:
tirc_core/script_manager.py
(See also Scripting and Script API Reference)
-
AppConfig
:- Role: Centralized management of all application and server settings.
- Responsibilities:
- Loading configuration from
config/tirc_config.ini
. - Providing access to configuration values throughout the application.
- Handling dynamic updates and saving of configuration.
- Loading configuration from
- Found in:
tirc_core/app_config.py
These components work in concert, primarily orchestrated by IRCClient_Logic
and communicating via the EventManager
and StateManager
, to provide the full functionality of tIRC.