# t3dotgg/unduck architecture

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

- Interactive diagram: https://gitdiagram.com/t3dotgg/unduck
- Repository: https://github.com/t3dotgg/unduck

## Overview

This project, “Unduck”, is a lightweight, client-side application built to offer much faster bang redirection than DuckDuckGo’s server-side approach. Based on the file tree and README, it’s clear that the project is a front-end focused tool built with modern web technologies (using Vite, TypeScript, and a typical HTML/CSS/JS setup).

##### Main Components
- Browser Client: The user’s browser serves as the environment where the entire logic will run. This includes the HTML (index.html), CSS (global.css), and the JavaScript/TypeScript code.
- Entry Point and Application Logic: The index.html loads the main bundle (compiled from src/main.ts) which orchestrates the entire process. Note that files like src/bang.ts likely contain the core logic for processing and handling the bang redirection.
- Caching Mechanism: Emphasize that once the page is loaded, the JavaScript gets cached by the browser, reducing subsequent load times.

##### Relationships and Interactions
- Data Flow: Start with the user entering a query via the custom search engine URL (https://unduck.link?q=%s). The browser loads index.html which, in turn, loads the main bundle.
- Redirect Logic: From main.ts, execution flows to bang.ts which processes the query client-side and performs the redirection.
- Build Process: The Vite build tool takes in all source files (from src, public, etc.) and compiles them into optimized assets that the browser caches.
- External Dependency: Show the relationship with DuckDuckGo’s bang system as the underlying functionality that is being re-implemented client-side for speed benefits.

##### Architectural Patterns and Design Principles
- Client-side Emphasis: The whole process is executed on the client, reducing reliance on potentially slow server-side redirects.
- Single-Page Application (SPA) Concept: Even though the project is relatively simple, it follows modern SPA design where all logic is loaded upfront and then handled within the browser.
- Progressive Enhancement & Caching: Once loaded initially, the JavaScript is cached, showcasing a design principle aimed at significantly reducing subsequent load times.

##### Relevant Technologies & Frameworks
- Vite (as the build tool)
- TypeScript (ensured by tsconfig.json and the *.ts files in src)
- CSS for basic styling
- Potential reliance on browser caching mechanisms

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Request
    U["User Query"]:::external

    %% Client-Side Application Subgraph
    subgraph "Client-Side Application"
        I["Entry Point: index.html"]:::browser
        C["Styling: src/global.css"]:::browser
        M["Application Logic: src/main.ts"]:::logic
        B["Redirect Logic: src/bang.ts"]:::logic
        P["Public Assets: public"]:::asset
    end

    %% Build & Development Tools Subgraph
    subgraph "Build & Development Tools"
        V["Vite Config: vite.config.ts"]:::build
        PJ["Package Manager: package.json"]:::build
        PN["Lock File: pnpm-lock.yaml"]:::build
        TS["TypeScript Config: tsconfig.json"]:::build
    end

    %% External Dependency
    D["DuckDuckGo Bang System"]:::external

    %% Connections between components
    U -->|"requests"| I
    I -->|"loads_css"| C
    I -->|"loads_executes"| M
    M -->|"calls"| B
    B -->|"redirects_to"| D
    I -->|"uses"| P
    V --- PJ
    PJ --- PN
    PN --- TS
    V -->|"builds_assets"| I

    %% Styling Classes
    classDef browser fill:#b3d9ff,stroke:#333,stroke-width:2px;
    classDef logic fill:#b3ffb3,stroke:#333,stroke-width:2px;
    classDef asset fill:#ffdb99,stroke:#333,stroke-width:2px;
    classDef build fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef external fill:#f9f3c2,stroke:#333,stroke-width:2px;

    %% Click Events
    click I "https://github.com/t3dotgg/unduck/blob/main/index.html"
    click C "https://github.com/t3dotgg/unduck/blob/main/src/global.css"
    click M "https://github.com/t3dotgg/unduck/blob/main/src/main.ts"
    click B "https://github.com/t3dotgg/unduck/blob/main/src/bang.ts"
    click P "https://github.com/t3dotgg/unduck/tree/main/public"
    click V "https://github.com/t3dotgg/unduck/blob/main/vite.config.ts"
    click PJ "https://github.com/t3dotgg/unduck/blob/main/package.json"
    click PN "https://github.com/t3dotgg/unduck/blob/main/pnpm-lock.yaml"
    click TS "https://github.com/t3dotgg/unduck/blob/main/tsconfig.json"
```
