# johnyburd/net-route architecture

> Architecture diagram of the GitHub repository johnyburd/net-route, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johnyburd/net-route
- Repository: https://github.com/johnyburd/net-route

## Overview

##### Core Architecture Components

a) Platform-Agnostic Interface Layer
- Represented by src/lib.rs
- This is the public API that consumers will interact with

b) Platform-Specific Implementation Layer
- This below the interface layer
- Three distinct implementations:
- Windows (windows.rs)
- macOS (macos folder)
- Linux (linux.rs)

c) Native Code Bridge
- Route.c and wrapper.h as a bridge component
- How it interfaces with the platform-specific implementations

##### Component Relationships

a) Interface Layer → Platform-Specific Layer
- Use a strategy pattern representation
- How the top-level interface delegates to platform-specific implementations

b) Platform Implementations → Native Bridge
- FFI (Foreign Function Interface) connections
- Bidirectional communication where applicable

##### Specific Implementation Details

For each platform implementation, show:

a) macOS Implementation
- Modular structure (bind.rs, macos.rs, mod.rs)
- Relationship between these components

b) Windows/Linux Implementations
- Direct implementation paths
- System API integration points

**[Application Layer (Examples)]**
- ↓
**[Public API Layer (lib.rs)]**
- ↓
**[Platform Abstraction Layer]**
- ↓
**[Platform-Specific Implementations]**
- ↓
**[Native System Calls]**

##### Technical Details

- Conditional compilation flags
- FFI boundary points
- System API integration points
- Error handling paths
- Event listening flows (especially for the listen functionality)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef interface fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef platform fill:#ffcccc,stroke:#333,stroke-width:2px
    classDef native fill:#ffd9b3,stroke:#333,stroke-width:2px
    classDef example fill:#d9f2d9,stroke:#333,stroke-width:2px
    classDef build fill:#e6ccff,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Interface Layer]:::interface
        L2[Platform Layer]:::platform
        L3[Native Layer]:::native
        L4[Examples]:::example
        L5[Build System]:::build
    end

    %% Main Interface Layer
    PublicAPI[Public API]:::interface
    click PublicAPI "https://github.com/johnyburd/net-route/blob/main/src/lib.rs"

    %% Platform Implementation Layer
    PlatformImpl[Platform Implementation Module]:::platform
    click PlatformImpl "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/mod.rs"

    %% Platform-Specific Implementations
    Windows[Windows Implementation]:::platform
    MacOS[macOS Implementation]:::platform
    Linux[Linux Implementation]:::platform
    click Windows "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/windows.rs"
    click MacOS "https://github.com/johnyburd/net-route/tree/main/src/platform_impl/macos/"
    click Linux "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/linux.rs"

    %% macOS Specific Components
    MacOSBind[FFI Bindings]:::platform
    MacOSImpl[Main Implementation]:::platform
    MacOSMod[Module Definition]:::platform
    click MacOSBind "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/macos/bind.rs"
    click MacOSImpl "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/macos/macos.rs"
    click MacOSMod "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/macos/mod.rs"

    %% Native Bridge Components
    RouteC[route.c]:::native
    WrapperH[wrapper.h]:::native
    click RouteC "https://github.com/johnyburd/net-route/blob/main/src/platform_impl/route.c"
    click WrapperH "https://github.com/johnyburd/net-route/blob/main/wrapper.h"

    %% Build System
    BuildRS[build.rs]:::build
    click BuildRS "https://github.com/johnyburd/net-route/blob/main/build.rs"

    %% Example Applications
    AddExample[Add Route Example]:::example
    DefaultExample[Default Route Example]:::example
    DeleteExample[Delete Route Example]:::example
    ListExample[List Routes Example]:::example
    ListenExample[Listen Example]:::example
    click AddExample "https://github.com/johnyburd/net-route/blob/main/examples/add.rs"
    click DefaultExample "https://github.com/johnyburd/net-route/blob/main/examples/default.rs"
    click DeleteExample "https://github.com/johnyburd/net-route/blob/main/examples/delete.rs"
    click ListExample "https://github.com/johnyburd/net-route/blob/main/examples/list.rs"
    click ListenExample "https://github.com/johnyburd/net-route/blob/main/examples/listen.rs"

    %% Relationships
    PublicAPI --> PlatformImpl
    PlatformImpl --> Windows & MacOS & Linux
    MacOS --> MacOSBind & MacOSImpl & MacOSMod
    Windows & Linux & MacOS -.-> RouteC
    RouteC -.-> WrapperH
    BuildRS -.-> RouteC
    AddExample & DefaultExample & DeleteExample & ListExample & ListenExample --> PublicAPI

    %% Subgraphs for organization
    subgraph Examples
        AddExample
        DefaultExample
        DeleteExample
        ListExample
        ListenExample
    end

    subgraph "Platform Specific"
        Windows
        Linux
        subgraph "macOS Components"
            MacOSBind
            MacOSImpl
            MacOSMod
        end
    end

    subgraph "Native Bridge"
        RouteC
        WrapperH
    end
```
