# bubuanabelas/web3-redirector architecture

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

- Interactive diagram: https://gitdiagram.com/bubuanabelas/web3-redirector
- Repository: https://github.com/bubuanabelas/web3-redirector

## Overview

Key Components to Include:

##### Browser Extension Components
- Background Service Worker (represented by background.ts)
- Error Handler (represented by error.ts)
- Utility Services (helpers.ts and searchEngines.ts)

##### External Systems
- Web Browser (Firefox/Chrome)
- Blockchain Networks (for resolving .crypto, .eth domains)
- Traditional DNS System
- Web Servers (destination websites)

##### External Interactions
- On the left: User's Browser
- On the right: Blockchain Networks
- Bottom: Traditional DNS & Web Servers

##### Flow Representation

**User Request -> Browser -> Extension Background Worker**
**Background Worker -> Blockchain Networks (for domain resolution)**
**Background Worker -> Traditional DNS (for resolved domains)**
**Background Worker -> Error Handler (when resolution fails)**

##### Specific Flows
a. Domain Resolution Flow:
- User enters Web3 domain (.crypto, .eth)
- Background worker intercepts request
- Query to blockchain networks
- Resolution to traditional domain
- Redirect to resolved domain

b. Error Handling Flow:
- Failed resolution detection
- Error page rendering
- User feedback path

##### Technical Details
- TypeScript implementation notation
- Browser WebExtension API integration points
- Blockchain query interfaces
- Search engine integration points (from searchEngines.ts)

##### Important Notes
- Manifest.json configuration influence
- Background script's persistent nature
- Content script injection points
- Error.html rendering path

Remember to maintain a balance between showing the technical implementation details (TypeScript, WebExtension APIs) and the high-level architecture (domain resolution flow, blockchain interaction). This will help other developers understand both the overall system and its implementation details.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Browser
        User[User Input]
        WebUI[Web Interface]
    end

    subgraph "Browser Extension"
        subgraph "Core Services"
            BSW["Background Service Worker"]
            EH["Error Handler"]
            direction TB
        end

        subgraph "Utility Layer"
            Helpers["Helper Utilities"]
            SearchEng["Search Engine Handler"]
            direction TB
        end

        Config["Extension Configuration"]
        EntryPoint["Extension Entry Point"]
    end

    subgraph "External Systems"
        BC["Blockchain Networks"]
        DNS["Traditional DNS"]
        WS["Web Servers"]
        direction TB
    end

    %% Main Flow
    User --> WebUI
    WebUI --> BSW
    BSW --> BC
    BSW --> DNS
    BSW --> EH
    DNS --> WS

    %% Utility Connections
    BSW --> Helpers
    BSW --> SearchEng
    EH --> EntryPoint
    Config --> BSW

    %% Styling
    classDef browser fill:#f9f,stroke:#333
    classDef core fill:#bbf,stroke:#333
    classDef utility fill:#bfb,stroke:#333
    classDef external fill:#ddd,stroke:#333
    classDef config fill:#fbb,stroke:#333

    class User,WebUI browser
    class BSW,EH core
    class Helpers,SearchEng utility
    class BC,DNS,WS external
    class Config,EntryPoint config

    %% Click Events
    click BSW "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/scripts/background.ts"
    click EH "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/scripts/error.ts"
    click Helpers "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/util/helpers.ts"
    click SearchEng "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/util/searchEngines.ts"
    click Config "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/manifest.json"
    click EntryPoint "https://github.com/BubuAnabelas/web3-redirector/blob/master/src/index.html"

    %% Legend
    subgraph Legend
        L1[Browser Components]:::browser
        L2[Core Services]:::core
        L3[Utility Services]:::utility
        L4[External Systems]:::external
        L5[Configuration]:::config
        direction TB
    end
```
