# tedkim97/adcache architecture

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

- Interactive diagram: https://gitdiagram.com/tedkim97/adcache
- Repository: https://github.com/tedkim97/adcache

## Overview

Project Type: This is a DNS resolver service written in Rust that modifies DNS responses to include advertisements.

Key Components to Include in the System Design:

##### Core Components (Main Flow)
- DNS Request Handler (main.rs)
- Advertisement Cache (adcache.rs)
- DNS Parser (parser.rs)
- Response Writer (response_writer.rs)
- Serializer (serializer.rs)

##### External Dependencies
- Upstream DNS Server (e.g., 1.1.1.1:53 as mentioned in the README)
- Advertisement Data Source (implied by the project's purpose)

##### Component Relationships

a. Input Flow:
- Client DNS Query → DN$ Resolver
- DN$ Resolver → Parser (for query processing)
- Parser → Upstream DNS Server

b. Response Flow:
- Upstream DNS Server → DN$ Resolver
- Advertisement Cache → Response Writer
- Response Writer → Serializer
- Serializer → Client

##### Technical Details
- Port numbers (53 for DNS)
- Protocol indicators (UDP/TCP for DNS)
- Cache interaction paths
- Advertisement injection points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        Client["DNS Client"]
        UpstreamDNS["Upstream DNS Server\n(1.1.1.1:53)"]:::external
    end

    subgraph "DN$ Resolver"
        Main["DNS Request Handler"]:::core
        Parser["DNS Parser"]:::core
        AdCache["Advertisement Cache"]:::advert
        RespWriter["Response Writer"]:::io
        Serial["Serializer"]:::core
        Config["Configuration"]:::config
    end

    %% Data Flow
    Client -->|"DNS Query\n(Port 53)"| Main
    Main --> Parser
    Parser -->|"Forwarded Query"| UpstreamDNS
    UpstreamDNS -->|"DNS Response"| Main
    Main --> RespWriter
    AdCache -->|"Ad Data"| RespWriter
    RespWriter --> Serial
    Serial -->|"Modified Response"| Client

    %% Configuration Flow
    Config -.->|"Settings"| Main
    Config -.->|"Settings"| AdCache
    Config -.->|"Settings"| RespWriter

    %% Styling
    classDef core fill:#2374ab
    classDef advert fill:#57a773
    classDef io fill:#ffc857
    classDef external fill:#8491a3
    classDef config fill:#ed553b

    %% Click Events
    click Main "https://github.com/tedkim97/adcache/blob/main/src/main.rs"
    click AdCache "https://github.com/tedkim97/adcache/blob/main/src/adcache.rs"
    click Parser "https://github.com/tedkim97/adcache/blob/main/src/parser.rs"
    click RespWriter "https://github.com/tedkim97/adcache/blob/main/src/response_writer.rs"
    click Serial "https://github.com/tedkim97/adcache/blob/main/src/serializer.rs"
    click Config "https://github.com/tedkim97/adcache/blob/main/src/constants.rs"

    %% Legend
    subgraph Legend
        L1["Core DNS Components"]:::core
        L2["Advertisement Component"]:::advert
        L3["I/O Component"]:::io
        L4["External Systems"]:::external
        L5["Configuration"]:::config
    end
```
