# endurosat/es-csp-server architecture

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

- Interactive diagram: https://gitdiagram.com/endurosat/es-csp-server
- Repository: https://github.com/endurosat/es-csp-server

## Overview

##### Main Components
- Application Layer (“app”): Contains the main entry point (main.c) which sets up the CSP server, processes command-line args, and triggers server operations.
- CSP Server Library (“libs/es_csp_server”): Implements core CSP server protocols and logic.
- Logging Library (“libs/es_log”): Provides logging functionality to report server actions and debugging.
- TFTP Library (“libs/es_tftp”): Handles file transfer functionalities using es-tftp, including protocols for WRQ, RRQ, and data packet exchange.
- External Libcsp (“external/libcsp” and “libs/libcsp” with patches): This is the underlying communication library supporting the CSP protocol with platform-specific patches due to the lack of native CMake in CSP 1.6.
- Build and Configuration Infrastructure (CMake files in the root, “cmake” directory, and module-specific CMakeLists.txt): These define build targets, configuration, and integration logic.
- Documentation (“docs”): Contains sphinx configuration and markdown/rst files for API docs.
- Deployment Configurations (e.g., systemd service files in the “app” folder): Provide sample integration with systemd for CAN and UART setups.

##### Relationships and Interactions
- The “app” component acts as the driver—it initializes the server utilizing the functionality provided by the es_csp_server library.
- The CSP server logic (es_csp_server) depends on the external “libcsp” components (both the submodule and its patched version in libs) for the lower-level communication protocols.
- The build system (CMake) and configuration components are crucial as they tie together these libraries and the application. It helps show how various libraries are integrated into the final binary.
- The provided systemd service samples reflect how the final server binary is deployed, interacting with dedicated physical interfaces.

##### Architectural Patterns and Design Principles
- Modularity: The project separates core server logic, logging, and file transfer into distinct libraries, making it easier to extend or replace individual functionalities.
- Layered Architecture: There is a clear separation between the application level (user interfacing / command-line usage) and the lower-level network/communication layers provided by libcsp and the server libraries.
- Extensibility: With multiple libraries and components, the design supports extension (e.g., using different physical layers or adding new protocols) as indicated in the README.
- Use of standard build tools (CMake) and integration with system-level services (systemd) indicates a focus on portability and robust deployment.

##### Relevant Technologies and Frameworks
- CMake for configuration and build management.
- The CSP protocol via libcsp.
- Libraries for file transfer (es-tftp) and logging.
- Optionally, integration with testing or CI (as seen in the .github/workflows directory).
- Systemd for service management on Linux.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Build["Build & Config Infrastructure"]:::build
    Docs["Documentation"]:::docs
    App["Application (app)"]:::app
    Server["CSP Server Library (es_csp_server)"]:::csp
    Log["Logging Library (es_log)"]:::log
    Tftp["TFTP Library (es_tftp)"]:::tftp
    ExtLibcsp["External Libcsp (external)"]:::lib
    Libcsp_Patch["Patched Libcsp (libs)"]:::lib
    Deploy_CAN["Systemd Service (CAN)"]:::deploy
    Deploy_UART["Systemd Service (UART)"]:::deploy

    %% Relationships
    Build --> App
    Build --> Server
    Build --> Log
    Build --> Tftp
    Build --> ExtLibcsp
    Build --> Libcsp_Patch
    Build --> Docs

    App -->|"initializes"| Server
    Server -->|"calls"| Log
    Server -->|"calls"| Tftp
    Server -->|"depends"| ExtLibcsp
    Server -->|"depends"| Libcsp_Patch

    App -->|"deploys via"| Deploy_CAN
    App -->|"deploys via"| Deploy_UART

    %% Click Events
    click App "https://github.com/endurosat/es-csp-server/blob/master/app/src/main.c"
    click Deploy_CAN "https://github.com/endurosat/es-csp-server/blob/master/app/es-csp-server-can.service"
    click Deploy_UART "https://github.com/endurosat/es-csp-server/blob/master/app/es-csp-server-uart.service"
    click Server "https://github.com/endurosat/es-csp-server/blob/master/libs/es_csp_server/src/es_csp_server.c"
    click Log "https://github.com/endurosat/es-csp-server/blob/master/libs/es_log/src/es_log.c"
    click Tftp "https://github.com/endurosat/es-csp-server/blob/master/libs/es_tftp/src/es_tftp.c"
    click ExtLibcsp "https://github.com/endurosat/es-csp-server/tree/master/external/libcsp"
    click Libcsp_Patch "https://github.com/endurosat/es-csp-server/tree/master/libs/libcsp"
    click Build "https://github.com/endurosat/es-csp-server/blob/master/Root CMakeLists.txt"
    click Docs "https://github.com/endurosat/es-csp-server/blob/master/docs/conf.py"

    %% Styles
    classDef build fill:#ffd1dc,stroke:#ff69b4,stroke-width:2px;
    classDef docs fill:#e6ffe6,stroke:#33cc33,stroke-width:2px;
    classDef app fill:#cce5ff,stroke:#3399ff,stroke-width:2px;
    classDef csp fill:#fff2cc,stroke:#ff9900,stroke-width:2px;
    classDef log fill:#f0e68c,stroke:#daa520,stroke-width:2px;
    classDef tftp fill:#d1e0e0,stroke:#008080,stroke-width:2px;
    classDef lib fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px;
    classDef deploy fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
```
