# adriengras/php-clamav architecture

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

- Interactive diagram: https://gitdiagram.com/adriengras/php-clamav
- Repository: https://github.com/adriengras/php-clamav

## Overview

##### Main Components

a. Client Layer:
- Two initialization methods: `fromDSN()` and `fromParts()`

b. Connector Layer:
- `ConnectorInterface` at the top
- `AbstractConnector` implementation
- Branch into two concrete implementations: `SocketConnector` and `TcpConnector`

c. External Components:
- ClamAV Daemon (clamd)
- Unix Socket / TCP Socket connections
- Client Application (using the library)

##### Relationships and Interactions

- Communication flow from Connectors to the clamd daemon
- Supported commands (PING, SCAN, VERSION, etc.) as interfaces between components

##### Specific Implementation Details

- Rectangle: Main classes (ClamAV, Connectors)
- Hexagon: External services (clamd)
- Oval: Communication protocols (TCP/Unix Sockets)

**[Client Application]**
- ↓
- [ClamAV]
- ↓
**[ConnectorInterface]**
- ↓
**[AbstractConnector]**
- ↙        ↘
**[Socket]    [TCP]**
- ↘        ↙
- [clamd daemon]

##### Important Elements to Highlight

- Command Flow: Show how commands like scan(), ping(), version() flow through the system
- Error Handling: Indicate where exceptions might occur
- Configuration Options: Show how different connection methods are handled
- Protocol Support: Highlight both Unix and TCP socket support

##### Technical Details

- PHP 8.0+ requirement
- Sockets extension dependency
- Supported clamd commands
- Connection string formats (DSN)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        App[Client Application]
        ClamAV[ClamAV Client]:::client
        click ClamAV "https://github.com/AdrienGras/php-clamav/blob/main/src/ClamAV.php"
    end

    subgraph Connector
        ConnInterface[Connector Interface]:::interface
        click ConnInterface "https://github.com/AdrienGras/php-clamav/blob/main/src/Connector/Impl/ConnectorInterface.php"
        
        AbstractConn[Abstract Connector]:::abstract
        click AbstractConn "https://github.com/AdrienGras/php-clamav/blob/main/src/Connector/Impl/AbstractConnector.php"
        
        SocketConn[Socket Connector]:::connector
        click SocketConn "https://github.com/AdrienGras/php-clamav/blob/main/src/Connector/SocketConnector.php"
        
        TcpConn[TCP Connector]:::connector
        click TcpConn "https://github.com/AdrienGras/php-clamav/blob/main/src/Connector/TcpConnector.php"
    end

    subgraph Testing
        SocketTest[Socket Tests]:::test
        click SocketTest "https://github.com/AdrienGras/php-clamav/blob/main/tests/SocketTest.php"
        
        TcpTest[TCP Tests]:::test
        click TcpTest "https://github.com/AdrienGras/php-clamav/blob/main/tests/TcpTest.php"
        
        TestUtils[Test Utilities]:::test
        click TestUtils "https://github.com/AdrienGras/php-clamav/blob/main/src/Mixins/TestTrait.php"
    end

    subgraph External
        Clamd[ClamAV Daemon]:::external
        UnixSocket[Unix Socket]:::socket
        TcpSocket[TCP Socket]:::socket
    end

    App --> ClamAV
    ClamAV --> ConnInterface
    ConnInterface --> AbstractConn
    AbstractConn --> SocketConn
    AbstractConn --> TcpConn
    SocketConn --> UnixSocket
    TcpConn --> TcpSocket
    UnixSocket --> Clamd
    TcpSocket --> Clamd
    
    SocketTest -.-> SocketConn
    TcpTest -.-> TcpConn
    TestUtils -.-> SocketTest
    TestUtils -.-> TcpTest

    classDef client fill:#a8e6cf
    classDef interface fill:#dcedc1
    classDef abstract fill:#ffd3b6
    classDef connector fill:#ffaaa5
    classDef external fill:#ff8b94
    classDef socket fill:#e6e6e6
    classDef test fill:#d4d4d4,stroke-dasharray: 5 5

    %% Legend
    subgraph Legend
        L1[Client Component]:::client
        L2[Interface]:::interface
        L3[Abstract Class]:::abstract
        L4[Connector]:::connector
        L5[External Service]:::external
        L6[Socket]:::socket
        L7[Test Component]:::test
    end
```
