# samualtnorman/internet-address architecture

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

- Interactive diagram: https://gitdiagram.com/samualtnorman/internet-address
- Repository: https://github.com/samualtnorman/internet-address

## Overview

##### Main Components

a. Core Modules:
- IPv4 Module
- IPv6 Module
- CIDR Module
- Process Module
- Subnet Match Module

b. Utility Layers:
- Parser Layer
- Conversion Layer
- Validation Layer
- Address Range Operations

**┌─ Public API Layer ─────────────────────┐**
- IPv4 | IPv6 | CIDR | Process | Subnet │
- ┬─────────────────────────┘

**┌─ Core Operations Layer ─────────────────┐**
- ┌─────────┐ ┌──────────┐ ┌──────────┐  │
- Parsing │ │Validation│ │Conversion│  │
- ┘ └──────────┘ └──────────┘  │
- ┬─────────────────────────┘

**┌─ Implementation Layer ──────────────────┐**
- ┌─────────┐ ┌──────────┐ ┌──────────┐  │
- IPv4    │ │  IPv6    │ │  CIDR    │  │
- Functions│ │ Functions │ │Operations│  │
- ┘ └──────────┘ └──────────┘  │
- ┘

##### Key Relationships to Highlight

a. IPv4 Operations:
- Parse → Validate → Convert/Process
- CIDR calculations
- Subnet operations

b. IPv6 Operations:
- Similar flow to IPv4 but with hextet handling
- IPv4 to IPv6 conversion
- IPv6-specific CIDR operations

##### Implementation Details

a. Data Types:
- Uint8Array for IPv4
- Uint16Array for IPv6
- Native JavaScript type usage

b. Function Groups:
- Address parsing
- CIDR operations
- Range calculations
- Validation functions
- Conversion utilities

##### Additional Notes

- Lightweight and browser-friendly architecture
- Clear separation between IPv4 and IPv6 operations
- Shared utilities between modules

- Minimal abstraction
- Direct use of JavaScript built-ins
- Clear separation of concerns
- Independent module structure

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef impl fill:#e67e22,stroke:#d35400,color:white
    classDef legend fill:none,stroke:#666,color:#666

    %% Public API Layer
    subgraph API["Public API Layer"]
        IPv4["IPv4 Module"]:::api
        IPv6["IPv6 Module"]:::api
        CIDR["CIDR Module"]:::api
        Process["Process Module"]:::api
        Subnet["Subnet Match Module"]:::api
    end

    %% Core Operations Layer
    subgraph CoreOps["Core Operations Layer"]
        Parse["Parsing Operations"]:::core
        Validate["Validation Operations"]:::core
        Convert["Conversion Operations"]:::core
    end

    %% Implementation Layer
    subgraph Impl["Implementation Layer"]
        IPv4Impl["IPv4 Functions"]:::impl
        IPv6Impl["IPv6 Functions"]:::impl
        CIDROps["CIDR Operations"]:::impl
        RangeOps["Range Operations"]:::impl
        SubnetOps["Subnet Operations"]:::impl
    end

    %% Relationships
    IPv4 --> Parse
    IPv4 --> Validate
    IPv6 --> Parse
    IPv6 --> Validate
    CIDR --> CIDROps
    Process --> Convert
    Subnet --> SubnetOps

    Parse --> IPv4Impl
    Parse --> IPv6Impl
    Validate --> IPv4Impl
    Validate --> IPv6Impl
    Convert --> IPv4Impl
    Convert --> IPv6Impl

    CIDROps --> IPv4Impl
    CIDROps --> IPv6Impl
    RangeOps --> IPv4Impl
    RangeOps --> IPv6Impl
    SubnetOps --> IPv4Impl
    SubnetOps --> IPv6Impl

    %% Click Events
    click IPv4 "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4.ts"
    click IPv6 "https://github.com/samualtnorman/internet-address/blob/main/src/IPv6.ts"
    click CIDR "https://github.com/samualtnorman/internet-address/blob/main/src/CIDR.ts"
    click Process "https://github.com/samualtnorman/internet-address/blob/main/src/process.ts"
    click Subnet "https://github.com/samualtnorman/internet-address/blob/main/src/subnetMatch.ts"
    click IPv4Impl "https://github.com/samualtnorman/internet-address/tree/main/src/IPv4/"
    click IPv6Impl "https://github.com/samualtnorman/internet-address/tree/main/src/IPv6/"
    click Parse "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/parse.ts"
    click Validate "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/is.ts"
    click Convert "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/toIPv6.ts"
    click CIDROps "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/cidrToNetworkAddress.ts"
    click RangeOps "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/getRange.ts"
    click SubnetOps "https://github.com/samualtnorman/internet-address/blob/main/src/IPv4/prefixToSubnetMask.ts"

    %% Legend
    subgraph Legend["Legend"]
        L1["Public API"]:::api
        L2["Core Operations"]:::core
        L3["Implementation"]:::impl
    end
```
