# apple/swift-http-structured-headers architecture

> Architecture diagram of the GitHub repository apple/swift-http-structured-headers, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/apple/swift-http-structured-headers
- Repository: https://github.com/apple/swift-http-structured-headers

## Overview

##### Main Components Structure

a) Public API Layer
- Two distinct modules: `StructuredFieldValues` (high-level) and `RawStructuredFieldValues` (low-level)

b) Core Processing Layer
- Parser components
- Serializer components
- Encoder/Decoder components

c) Data Types Layer
- Container types (Dictionary, List, Inner List, Parameters)
- Base item types (Boolean, Integer, Decimal, Token, String, Binary, Date, Display String)

##### Component Relationships

a) High-Level Flow:
- Client Code → StructuredFieldValues Module → RawStructuredFieldValues Module → Raw Byte Processing

b) Parallel Processing Paths:
- Encoding Path: `Codable Types → StructuredFieldValueEncoder → Serializer → Bytes`
- Decoding Path: `Bytes → Parser → StructuredFieldValueDecoder → Codable Types`

##### Specific Implementation Details

Key components with appropriate connections:

a) StructuredFieldValues Module:
- StructuredFieldValueEncoder
- StructuredFieldValueDecoder
- Keyed/Unkeyed Containers
- Foundation Integration (Date, Data handling)

b) RawStructuredFieldValues Module:
- FieldParser
- FieldSerializer
- ASCII Processing
- Component Types
- Error Handling

##### Important Notes

Annotations highlighting:
- Foundation dependency for the high-level module
- Standard library-only dependency for the low-level module
- Base64 encoding/decoding requirements
- Type conversion flows

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Legend"
        L1[High-Level API]:::highlevel
        L2[Low-Level API]:::lowlevel
        L3[Core Processing]:::core
        L4[Data Types]:::datatype
        L5[Error Handling]:::error
    end

    subgraph "Public API Layer"
        StructuredFieldValues[StructuredFieldValues Module]:::highlevel
        RawStructuredFieldValues[RawStructuredFieldValues Module]:::lowlevel
        PublicInterface[Public Interface]:::highlevel
    end

    subgraph "Core Processing Layer"
        Parser[Field Parser]:::core
        Serializer[Field Serializer]:::core
        ASCII[ASCII Processing]:::core
    end

    subgraph "Encoder Components"
        MainEncoder[Structured Field Value Encoder]:::highlevel
        KeyedContainer[Keyed Container]:::highlevel
        UnkeyedContainer[Unkeyed Container]:::highlevel
    end

    subgraph "Decoder Components"
        MainDecoder[Structured Field Value Decoder]:::highlevel
        DictContainer[Dictionary Container]:::highlevel
        ListDecoder[List Decoder]:::highlevel
        InnerListDecoder[Inner List Decoder]:::highlevel
        ParamsDecoder[Parameters Decoder]:::highlevel
    end

    subgraph "Data Types Layer"
        ComponentTypes[Component Types]:::datatype
        DisplayString[Display String]:::datatype
        PseudoDecimal[Pseudo Decimal]:::datatype
        OrderedMap[Ordered Map]:::datatype
    end

    ErrorHandling[Error Handling]:::error

    %% Relationships
    PublicInterface --> StructuredFieldValues
    StructuredFieldValues --> RawStructuredFieldValues
    RawStructuredFieldValues --> Parser
    RawStructuredFieldValues --> Serializer
    Parser --> ASCII
    Serializer --> ASCII
    Parser --> ErrorHandling
    Serializer --> ErrorHandling

    MainEncoder --> Serializer
    MainDecoder --> Parser
    
    KeyedContainer --> MainEncoder
    UnkeyedContainer --> MainEncoder
    
    DictContainer --> MainDecoder
    ListDecoder --> MainDecoder
    InnerListDecoder --> MainDecoder
    ParamsDecoder --> MainDecoder

    Parser --> ComponentTypes
    Serializer --> ComponentTypes
    ComponentTypes --> PseudoDecimal
    ComponentTypes --> OrderedMap
    StructuredFieldValues --> DisplayString

    %% Styles
    classDef highlevel fill:#a8d1ff
    classDef lowlevel fill:#90EE90
    classDef core fill:#FFB366
    classDef datatype fill:#DDA0DD
    classDef error fill:#FF9999

    %% Click Events
    click StructuredFieldValues "https://github.com/apple/swift-http-structured-headers/tree/main/Sources/StructuredFieldValues/"
    click RawStructuredFieldValues "https://github.com/apple/swift-http-structured-headers/tree/main/Sources/RawStructuredFieldValues/"
    click Parser "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/FieldParser.swift"
    click Serializer "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/FieldSerializer.swift"
    click ASCII "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/ASCII.swift"
    click MainEncoder "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Encoder/StructuredFieldValueEncoder.swift"
    click KeyedContainer "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Encoder/StructuredFieldKeyedEncodingContainer.swift"
    click UnkeyedContainer "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Encoder/StructuredFieldUnkeyedEncodingContainer.swift"
    click MainDecoder "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Decoder/StructuredFieldValueDecoder.swift"
    click DictContainer "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Decoder/DictionaryKeyedContainer.swift"
    click ListDecoder "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Decoder/TopLevelListDecoder.swift"
    click InnerListDecoder "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Decoder/BareInnerListDecoder.swift"
    click ParamsDecoder "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/Decoder/ParametersDecoder.swift"
    click ComponentTypes "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/ComponentTypes.swift"
    click DisplayString "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/DisplayString.swift"
    click PseudoDecimal "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/PseudoDecimal.swift"
    click OrderedMap "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/OrderedMap.swift"
    click ErrorHandling "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/RawStructuredFieldValues/Errors.swift"
    click PublicInterface "https://github.com/apple/swift-http-structured-headers/blob/main/Sources/StructuredFieldValues/StructuredFieldValue.swift"
```
