# gustavomorinaga/copyscotch architecture

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

- Interactive diagram: https://gitdiagram.com/gustavomorinaga/copyscotch
- Repository: https://github.com/gustavomorinaga/copyscotch

## Overview

##### Project type and purpose
- This is “Copyscotch,” a SvelteKit–based reimplementation of an API‐request builder (Hoppscotch).
- It’s a full‑stack web application (SSR + client) that allows users to construct, send, and view HTTP requests/responses to arbitrary external APIs.

##### File structure
- Top‑level:
- src/routes → SvelteKit pages and layouts (UI entry points, error pages).
- src/lib → Shared code (components, features, contexts, repositories, schemas, utils).
- src/server → SvelteKit server hooks and utilities (minification).
- service-worker.ts → PWA support / offline caching.
- Everything under src/lib/components is a UI component library (shadcn‑svelte + custom infra).
- src/lib/features/rest & settings & support hold the core domain logic and feature‑specific components and views.
- src/lib/functions (export, fetcher) encapsulate cross‑cutting logic.
- src/lib/repositories contain the HTTP request abstractions.
- No external database: it’s purely client‑driven state (contexts + localStorage / file export).

##### README for additional insights
- Tech stack: SvelteKit 1.0 (SSR + CSR), TypeScript, TailwindCSS, PostCSS & CSSnano, Zod + Superforms for validation, shadcn‑svelte UI primitives.
- Purpose: demo learning SvelteKit while mimicking Hoppscotch’s functionality.

##### Main components & interactions
a. Components
- Browser (Client)
– UI Shell (SvelteKit client hydration)
– Service Worker
– Feature Modules (REST builder, Settings, Support)
– Component Library (ui/, infra/, metadata/, mode/screen watchers)
- SvelteKit Server (Node)
– SSR Engine (renders + serves HTML)
– Server Hooks & Utilities (minify hook, fetcher function)
- Static Asset Server
– Static/: images, manifest, robots.txt
- External APIs
– Target HTTP endpoints under user control (the ones the user wants to test)
b. Relationships & Data Flow
1. Client requests a page → hits SvelteKit server SSR → returns HTML + hydration script.
2. Client hydrates, loads component library.
3. User composes a request in UI → repository.fetcher calls browser fetch → goes to External API → response flows back to UI.
4. Export feature: client triggers export.function → triggers browser download (no server round‑trip).
5. Service Worker: intercepts navigations/static assets for caching/offline.
c. Architectural patterns
- Monorepo‑style grouping under src/lib by domain (components, features, contexts, repositories, schemas, utils).
- Feature‑driven folders for REST, settings, support.
- MVC‑like separation:
- Views = src/lib/features/*/views
- Controllers/State = contexts & repositories & superforms
- Models = Zod schemas in src/lib/schemas
- Server‑side hooks for build‑time minification.
d. Key technologies
- SvelteKit: SSR + routing (src/routes) + server hooks
- TypeScript (tsconfig.json)
- Tailwind/PostCSS/CSSnano (tailwind.config.js + postcss.config.js)
- Vite (vite.config.js)
- Superforms & Zod (form validation)
- Shadcn‑svelte (UI components)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser / Client
    subgraph "Browser / Client"
        UI_Shell["UI Shell"]:::client
        SW["Service Worker"]:::client
        subgraph "Feature Modules"
            REST_Module["REST Builder"]:::client
            Settings_Module["Settings"]:::client
            Support_Module["Support"]:::client
        end
        CompLib["Component Library"]:::client
        ExportFuncNode["Export Function"]:::client
        FS["Browser File System"]:::client
    end

    %% SvelteKit Server
    subgraph "SvelteKit Server"
        SSR["SSR Engine"]:::server
        subgraph "Server Hooks & Utilities"
            MinifyHook["Minification Hook"]:::server
            MinifyUtil["Minify Util"]:::server
        end
    end

    %% External & Static
    External["External APIs"]:::external
    StaticServer["Static Asset Server"]:::static

    %% Data Flows
    UI_Shell -->|"GET /"| SSR
    SSR -->|"HTML + Hydration"| UI_Shell
    SW -->|"cache nav/assets"| StaticServer
    REST_Module -->|"calls repository"| Repo
    Repo["HTTP Repository"]:::client -->|"uses fetcher"| Fetcher
    Fetcher["Fetcher Function"]:::client -->|"HTTP request"| External
    External -->|"HTTP response"| Fetcher
    Fetcher -->|"returns data"| Repo
    Repo -->|"provides data"| REST_Module
    ExportFuncNode -->|"download file"| FS

    %% Click Events
    click UI_Shell "https://github.com/gustavomorinaga/copyscotch/blob/next/src/routes/+layout.svelte"
    click UI_Shell "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/layouts/app/app.layout.svelte"
    click SW "https://github.com/gustavomorinaga/copyscotch/blob/next/service-worker.ts"
    click SW "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/components/service-worker/service-worker.svelte"
    click REST_Module "https://github.com/gustavomorinaga/copyscotch/tree/next/src/lib/features/rest"
    click Settings_Module "https://github.com/gustavomorinaga/copyscotch/tree/next/src/lib/features/settings"
    click Support_Module "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/features/support/components/dialogs/dialog-support/dialog-support.component.svelte"
    click CompLib "https://github.com/gustavomorinaga/copyscotch/tree/next/src/lib/components"
    click SSR "https://github.com/gustavomorinaga/copyscotch/tree/next/src/routes"
    click MinifyHook "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/server/hooks/minify/minify.hook.ts"
    click MinifyUtil "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/server/utils/minify/minify.util.ts"
    click Repo "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/repositories/rest/rest.repository.ts"
    click Fetcher "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/functions/fetcher/fetcher.function.ts"
    click ExportFuncNode "https://github.com/gustavomorinaga/copyscotch/blob/next/src/lib/functions/export/export.function.ts"
    click StaticServer "https://github.com/gustavomorinaga/copyscotch/tree/next/static/"

    %% Styles
    classDef client fill:#e5f5e0,stroke:#2d7a2d,color:#2d7a2d
    classDef server fill:#e0e5f5,stroke:#2a2d7a,color:#2a2d7a
    classDef external fill:#fde4d4,stroke:#d95f0e,color:#d95f0e
    classDef static fill:#f0f0f0,stroke:#666666,color:#666666
```
