# sidrao2006/dynamic_cached_fonts architecture

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

- Interactive diagram: https://gitdiagram.com/sidrao2006/dynamic_cached_fonts
- Repository: https://github.com/sidrao2006/dynamic_cached_fonts

## Overview

##### Project type and purpose
- This is a Flutter/Dart **library package** (`dynamic_cached_fonts`) whose sole responsibility is to **dynamically download web-hosted font files**, **cache** them locally, and **register** them in the Flutter engine on demand.
- It also provides an **example** multi-platform Flutter app to demonstrate usage, plus a full test suite.

##### File structure
- Top‐level configuration: `.github/`, `.gitignore`, `pubspec.yaml`, CI/workflow manifests, Docker setup under `dev/docker/`.
- **lib/**: the core package code
- `dynamic_cached_fonts.dart` – public exports and entry points
- `src/raw_dynamic_cached_fonts.dart` – abstract base for low-level methods
- `src/utils.dart` – shared utilities
- **example/**: a complete Flutter app (Android, iOS, Web, macOS, Linux, Windows) showing how to use the library
- **test/**: unit and mock tests for API correctness
- **doc/**: demo images

##### README for additional insights
- The package exposes two main APIs: synchronous (`load()`, `cacheFont()`, etc.) and **streamed** (`loadStream()`, `cacheFontStream()`).
- Internally it:
a. **Downloads** font bytes from an HTTP(S) URL or `gs://` Firebase storage
b. **Caches** files on local storage (with TTL and size limits)
c. **Loads** the font into the Flutter engine via the engine registry
d. Emits **progress** and **item-count** events on a Dart `Stream`
- Extensibility point: override `RawDynamicCachedFonts` to swap out network or cache implementation.

##### Detail without overcomplication
- Both **synchronous** (load, cacheFont) and **streamed** (`loadStream`, `cacheFontStream`) paths if space permits
- **extensibility hook** (`RawDynamicCachedFonts`) so readers can see where to plug in custom logic

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main flow
    Client["Flutter App (Client)"]:::client
    API["DynamicCachedFonts API Layer"]:::library
    Raw["RawDynamicCachedFonts<br/>(Extension Point)"]:::extension
    Utils["Utilities Module"]:::library
    Downloader["Downloader Module"]:::library
    External["External Font Source<br/>(HTTP/gs://)"]:::external
    Cache["Cache Manager"]:::cache
    Engine["Font Loader Engine"]:::engine

    %% Project artifacts
    subgraph "Project Artifacts"
        ExampleApp["Example App"]:::artifact
        TestSuite["Test Suite"]:::artifact
        TestMocks["Test Mocks"]:::artifact
        CI["CI / Workflows"]:::artifact
        Docker["Docker Setup"]:::artifact
        Docs["Documentation / Demo Images"]:::artifact
        Config["Package Configuration"]:::artifact
    end

    %% Connections
    Client -->|"invokes API"| API
    API -->|"uses extension"| Raw
    API -->|"uses utilities"| Utils
    API -->|"download font"| Downloader
    Downloader -->|"fetch from"| External
    External -->|"font bytes"| Downloader
    Downloader -->|"writes file"| Cache
    API -->|"check cache"| Cache
    Cache -->|"cache hit or path"| API
    API -->|"register font"| Engine
    Downloader -.->|"DownloadProgress event"| API
    API -.->|"LoadCompletion / ItemCount event"| Client

    %% Artifact connections
    Client --> ExampleApp
    API --> TestSuite
    API --> TestMocks
    API --> CI
    API --> Docker
    Docs --> API
    Config --> API

    %% Click events
    click Client "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/example/lib/main.dart"
    click API "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/lib/dynamic_cached_fonts.dart"
    click Raw "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/lib/src/raw_dynamic_cached_fonts.dart"
    click Utils "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/lib/src/utils.dart"
    click ExampleApp "https://github.com/sidrao2006/dynamic_cached_fonts/tree/main/example/"
    click TestSuite "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/test/dynamic_cached_fonts_test.dart"
    click TestMocks "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/test/dynamic_cached_fonts_test.mocks.dart"
    click CI "https://github.com/sidrao2006/dynamic_cached_fonts/tree/main/.github/workflows/"
    click Docker "https://github.com/sidrao2006/dynamic_cached_fonts/tree/main/dev/docker/"
    click Docs "https://github.com/sidrao2006/dynamic_cached_fonts/tree/main/doc/images/"
    click Config "https://github.com/sidrao2006/dynamic_cached_fonts/blob/main/pubspec.yaml"

    %% Styles
    classDef client fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1;
    classDef library fill:#E3F2FD,stroke:#42A5F5,color:#0D47A1;
    classDef extension fill:#FFF3E0,stroke:#FB8C00,color:#E65100,stroke-dasharray: 5 5;
    classDef cache fill:#C8E6C9,stroke:#43A047,color:#1B5E20,shape:cylinder;
    classDef external fill:#CFD8DC,stroke:#607D8B,color:#263238,shape:cloud;
    classDef engine fill:#F3E5F5,stroke:#8E24AA,color:#4A148C;
    classDef artifact fill:#F5F5F5,stroke:#BDBDBD,color:#424242,stroke-dasharray: 2 2;
```
