# dgen-technologies/dgen-ui architecture

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

- Interactive diagram: https://gitdiagram.com/dgen-technologies/dgen-ui
- Repository: https://github.com/dgen-technologies/dgen-ui

## Overview

##### Project Type and Purpose
- DGEN is a full-stack, web-based Bitcoin wallet interface with optional mobile support (via Capacitor/Android).
- It uses SvelteKit for the frontend (SSR + SPA) and serverless API routes, and relies on an external “dgen-server” for Bitcoin/Lightning operations through the Breez SDK.

##### Main Components
a. Frontend (Browser & Mobile WebView)
- SvelteKit app under `src/` (routes, components, lib).
- UI layers: pages in `src/routes`, reusable components in `src/components`.
- Local storage, client hooks, and real-time socket events via `src/lib/socket.ts`.
b. Backend/API (SvelteKit serverless routes)
- Server code in `src/routes/api`, `+server.ts` and `+page.server.ts` handlers.
- Business logic in `src/lib/*Service.ts` modules: walletService, cryptoService, transactionService, invoice, etc.
- Security modules: sessionManager, rateLimiter, domMonitor under `src/lib/security`.
c. External Service (“dgen-server”)
- Runs separately; exposes endpoints for on-chain and Lightning operations via the Breez SDK.
- Connects to Bitcoin & Lightning networks.
d. Static Assets & Hosting
- Static files under `static/`.
- Deployment config: Dockerfiles, `docker-compose.yml`, Netlify (`netlify.toml`), Codemagic for CI (`codemagic.yaml`).
e. Mobile Integration (Android)
- Capacitor plugin under `android/` implementing `NfcWriterPlugin`.
- Bridges web app to native NFC writing capabilities.

##### Relationships & Data Flows
- User ↔ Browser UI (HTTPS / WebSocket)
- Browser UI ↔ SvelteKit Serverless API (HTTP requests, load hooks)
- Serverless API ↔ dgen-server (HTTP/gRPC)
- dgen-server ↔ Bitcoin & Lightning networks
- Optional: Browser UI ↔ Android native plugin (Capacitor bridge)

##### Architectural Patterns & Design Principles
- Separation of concerns: UI components vs. page routes vs. service modules.
- Serverless/functions-as-API: each route handler encapsulates data fetching and business logic.
- Layered service modules: cryptoService, cache, walletService, transactionService.
- Security middleware: sessionManager, rateLimiter.
- Real-time updates via WebSocket/socket.io pattern.
- Internationalization: `src/locales` + guided translation script.

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef external fill:#FFE1B3,stroke:#333,stroke-width:1px
    classDef mobile fill:#E5D4FF,stroke:#333,stroke-width:1px
    classDef cicd fill:#F0F0F0,stroke:#333,stroke-width:1px

    User["User"]:::external

    subgraph "Frontend UI (SvelteKit)" 
        direction TB
        F_Routes["Page Routes<br/>src/routes/"]:::frontend
        F_Components["Reusable Components<br/>src/components/"]:::frontend
        F_Hooks["Client Hooks<br/>src/hooks.client.ts"]:::frontend
        F_Assets["App Shell & Styles<br/>src/app.html, src/app.css, src/app-modern.css"]:::frontend
        F_Utils["Client Utilities<br/>socket.ts, cache.ts, secureStorage.ts, store.ts"]:::frontend
        F_i18n["Internationalization<br/>src/locales/, guided_translation.py, src/lib/translations"]:::frontend
    end

    subgraph "Backend API (SvelteKit Serverless)" 
        direction TB
        B_APIRoutes["API Routes<br/>src/routes/api/"]:::backend
        SVC1["walletService.ts"]:::backend
        SVC2["cryptoService.ts"]:::backend
        SVC3["transactionService.ts"]:::backend
        SVC4["assetService.ts"]:::backend
        SVC5["invoice.ts"]:::backend
        SEC1["sessionManager.ts"]:::backend
        SEC2["rateLimiter.ts"]:::backend
        SEC3["domMonitor.ts"]:::backend
    end

    subgraph "External Services" 
        direction TB
        Dgen["dgen-server"]:::external
        Bitcoin["Bitcoin Network"]:::external
        Lightning["Lightning Network"]:::external
    end

    subgraph "Mobile Plugin (Android)" 
        direction TB
        Mobile["NFC Writer Plugin<br/>android/"]:::mobile
    end

    subgraph "CI/CD & Hosting" 
        direction TB
        CI_Docker["Dockerfiles & Compose"]:::cicd
        CI_Netlify["netlify.toml"]:::cicd
        CI_Codemagic["codemagic.yaml"]:::cicd
    end

    User -->|"HTTPS"| F_Routes
    User -.->|"WebSocket"| F_Utils
    F_Routes -->|"HTTP"| B_APIRoutes
    F_Utils -.->|"WebSocket"| B_APIRoutes
    B_APIRoutes -->|"gRPC/HTTP"| Dgen
    Dgen -->|"Bitcoin RPC"| Bitcoin
    Dgen -->|"Lightning RPC"| Lightning
    F_Routes -->|"Capacitor Bridge"| Mobile

    %% Click Events - Frontend
    click F_Routes "https://github.com/dgen-technologies/dgen-ui/tree/main/src/routes/"
    click F_Components "https://github.com/dgen-technologies/dgen-ui/tree/main/src/components/"
    click F_Hooks "https://github.com/dgen-technologies/dgen-ui/blob/main/src/hooks.client.ts"
    click F_Assets "https://github.com/dgen-technologies/dgen-ui/blob/main/src/app.html"
    click F_Utils "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/socket.ts"
    click F_i18n "https://github.com/dgen-technologies/dgen-ui/tree/main/src/locales/"

    %% Click Events - Backend
    click B_APIRoutes "https://github.com/dgen-technologies/dgen-ui/tree/main/src/routes/api/"
    click SVC1 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/walletService.ts"
    click SVC2 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/cryptoService.ts"
    click SVC3 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/transactionService.ts"
    click SVC4 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/assetService.ts"
    click SVC5 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/invoice.ts"
    click SEC1 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/security/sessionManager.ts"
    click SEC2 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/security/rateLimiter.ts"
    click SEC3 "https://github.com/dgen-technologies/dgen-ui/blob/main/src/lib/security/domMonitor.ts"

    %% Click Events - Mobile
    click Mobile "https://github.com/dgen-technologies/dgen-ui/tree/main/android/"

    %% Click Events - CI/CD
    click CI_Docker "https://github.com/dgen-technologies/dgen-ui/blob/main/docker-compose.yml"
    click CI_Netlify "https://github.com/dgen-technologies/dgen-ui/blob/main/netlify.toml"
    click CI_Codemagic "https://github.com/dgen-technologies/dgen-ui/blob/main/codemagic.yaml"
```
