# carmc99/squadnet architecture

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

- Interactive diagram: https://gitdiagram.com/carmc99/squadnet
- Repository: https://github.com/carmc99/squadnet

## Overview

##### Project Type and Purpose
- SquadNet is a modular .NET framework focused on processing SquadGame logs, real-time event detection, and RCON command integration.
- Its core functionality includes log monitoring (via FTP, Tail, and SFTP), an event system that triggers custom logic, and an extensible plugin architecture.
- Additional components (like the REST API and CLI) are under development, which indicates the framework is being built toward a full-stack tool with both service and interface aspects.

##### Analyzing the File Structure
- Projects are organized into several directories that resemble discrete modules:
- SquadNET.API: Implements a REST API layer (controllers and endpoints for Squad-related operations).
- SquadNET.Application: Contains primary business logic, implemented largely following a CQRS pattern with separate Commands and Queries (reflecting administrative tasks, map handling, player management, etc.).
- SquadNET.Core: Provides the core models, events, parsers, and RCON client functionality.
- SquadNET.Extensions.Exceptions: Adds middleware for standardized exception handling.
- SquadNET.LogManagement: Manages different log reading strategies – FTP, SFTP, Tail – which form the basis for the event system.
- SquadNET.Plugins.Abstractions and SquadNET.Plugins: Define and implement the extensibility model for injecting custom event processing logic.
- SquadNET.Rcon: Contains logic to interface with Squad servers using RCON protocols.
- SquadNET.SquadMonitoringService: Acts as a background service continuously monitoring log changes and handling event processing.
- SquadNET.Test: Contains unit tests, ensuring the core parsing and log management functionality works as expected.
- The solution file (SquadNet.sln) ties these modules together in a multi-project solution.
- The naming in directories (e.g., “Squad”, “Admin”, “Player”, “Map”, etc.) points toward modular responsibilities and separation of concerns in handling Squad game-related events and commands.

a. Main Components:
- Log Monitoring Module: Represents SquadNET.LogManagement with its implementations (FtpLogReader, SftpLogReader, TailLogReader). It’s responsible for ingesting log data.
- Event Processing Engine: Built around the components located in SquadNET.Application and SquadNET.Core. This subsystem translates log entries into events (using parsers) and pushes them for further action.
- API Layer: Provided in SquadNET.API – responsible for exposing endpoints (via controllers) to trigger administrative commands or query event data.
- RCON Integration: Represented by SquadNET.Rcon and part of SquadNET.Core, which manages command execution on Squad servers.
- Plugin Framework: Encapsulated by SquadNET.Plugins.Abstractions and SquadNET.Plugins, which allows custom logic (e.g., ChatMessagePlugin) to hook into the event stream.
- Background Service: Shown in SquadNET.SquadMonitoringService – a continuously running service monitoring logs and processing events in real time.
- Exception Middleware: Provided by SquadNET.Extensions.Exceptions to manage error handling globally across components.
- Test Components: SquadNET.Test is used for unit testing and validating various parts of the system (especially parsers), although it is more of a development tool rather than a runtime component.

b. Relationships and Interactions:
- Log Monitoring initiates data flows by reading logs and passing the raw data to the Event Processing Engine.
- The Event Processing Engine parses log data (using parsers in SquadNET.Core/Squad/Parsers) and produces events.
- Events are then consumed by:
- The Plugin Framework: Custom plugins register to receive events, processing them as defined (e.g., logging chat messages).
- The Background Service: SquadMonitoringService processes real-time events and may forward specific events for further action.
- The API Layer: Which can query event states or trigger commands via controllers that use application services.
- RCON Integration: Issues commands to Squad servers based on processed event information.
- Exception Middleware intercepts errors from multiple components ensuring that exceptions are standardized across the system.

c. Architectural Patterns and Key Design Principles:
- Modular Architecture: Each major functionality is separated into its own project/module, promoting loose coupling.
- CQRS Pattern: Within SquadNET.Application, the separation of Commands and Queries enhances clarity in data processing.
- Extensibility: The plugin system allows custom event handling, making the framework readily extensible.
- Dependency Injection: The frequent use of ServiceCollectionExtensions across modules indicates heavy dependency injection for managing services.
- Real-time Processing: The design emphasizes continuous monitoring (background service) and immediate event processing.

d. Relevant Technologies, Frameworks, or Libraries:
- .NET 6 (or higher) is the foundation for all projects.
- ASP.NET Core for the REST API.
- EF Core as the likely ORM for repository patterns used in various modules.
- Custom RCON client implemented in SquadNET.Core.
- Unit Testing Framework (e.g., xUnit or NUnit) used in SquadNET.Test.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Log Monitoring Module
    subgraph "Log Monitoring (SquadNET.LogManagement)"
        LM_FTP["FtpLogReader"]:::infra
        LM_SFTP["SftpLogReader"]:::infra
        LM_Tail["TailLogReader"]:::infra
    end

    %% Event Processing Engine
    subgraph "Event Processing Engine"
        EP1["Application Logic (ParseLineQueryHandler)"]:::core
        EP2["Core Parsers"]:::core
    end

    EP_Merge["Event Processor"]:::core

    %% Arrows from Log Monitoring to Event Processor
    LM_FTP --> EP_Merge
    LM_SFTP --> EP_Merge
    LM_Tail --> EP_Merge

    %% Arrows from Event Processing Engine to Aggregated Event Processor
    EP1 --> EP_Merge
    EP2 --> EP_Merge

    %% Branching from Event Processor to various components
    EP_Merge --> PF_A["Plugin Abstractions"]:::infra
    EP_Merge --> PF_I["Plugin Implementations"]:::infra
    EP_Merge --> API["REST API"]:::api
    EP_Merge --> RCON1["Core RCON Client"]:::infra
    EP_Merge --> RCON2["RCON Service"]:::infra
    EP_Merge --> BG_P["Event Processing Service"]:::infra
    EP_Merge --> BG_D["Data Update Service"]:::infra

    %% Exception Middleware (intercepts errors from selected components)
    PF_A -->|error| EM["Exception Middleware"]:::core
    API -->|error| EM
    RCON1 -->|error| EM
    BG_P -->|error| EM
    BG_D -->|error| EM

    %% Testing Component (development tool)
    EP_Merge --> TEST["Testing"]:::test

    %% Styles
    classDef infra fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef core fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef api fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef test fill:#F5B7B1,stroke:#333,stroke-width:2px;

    %% Click Events
    click LM_FTP "https://github.com/carmc99/squadnet/blob/dev/SquadNET.LogManagement/LogReaders/FtpLogReader.cs"
    click LM_SFTP "https://github.com/carmc99/squadnet/blob/dev/SquadNET.LogManagement/LogReaders/SftpLogReader.cs"
    click LM_Tail "https://github.com/carmc99/squadnet/blob/dev/SquadNET.LogManagement/LogReaders/TailLogReader.cs"
    click EP1 "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Application/Squad/ParseLineQueryHandler.cs"
    click EP2 "https://github.com/carmc99/squadnet/tree/dev/SquadNET.Core/Squad/Parsers"
    click PF_A "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Plugins.Abstractions/IPlugin.cs"
    click PF_I "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Plugins/ChatMessagePlugin.cs"
    click API "https://github.com/carmc99/squadnet/blob/dev/SquadNET.API/Squad/Game/GameController.cs"
    click RCON1 "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Core/RconClient.cs"
    click RCON2 "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Rcon/SquadRcon.cs"
    click BG_P "https://github.com/carmc99/squadnet/blob/dev/SquadNET.SquadMonitoringService/SquadEventProcessingService.cs"
    click BG_D "https://github.com/carmc99/squadnet/blob/dev/SquadNET.SquadMonitoringService/SquadDataUpdateService.cs"
    click EM "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Extensions.Exceptions/ExceptionMiddleware.cs"
    click TEST "https://github.com/carmc99/squadnet/blob/dev/SquadNET.Test"
```
