# amrhalim/htmx-sync-css architecture

> Architecture diagram of the GitHub repository amrhalim/htmx-sync-css, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amrhalim/htmx-sync-css
- Repository: https://github.com/amrhalim/htmx-sync-css

## Overview

htmx-sync-css is a small browser extension that adds styles found in htmx response HTML. The page enables the extension; after an htmx request, the extension parses response style tags, skips previously seen IDs using an in-memory cache, and appends new styles to the document head. The runtime excerpts show parsing and DOM insertion; README documents the setup and response markup. External htmx event dispatch is represented from the extension registration contract.

Main entry points: [`src/index.ts`](https://github.com/amrhalim/htmx-sync-css/blob/master/src/index.ts) (sync-css extension), [`src/utils.ts`](https://github.com/amrhalim/htmx-sync-css/blob/master/src/utils.ts) (Style tag parser), [`src/constants.ts`](https://github.com/amrhalim/htmx-sync-css/blob/master/src/constants.ts) (Style tag matcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_page(("Web page"))
node_htmx["htmx runtime"]
node_extension["sync-css extension<br/>[index.ts]"]
node_cache[("Style ID cache<br/>[index.ts]")]
node_parser["Style tag parser<br/>[utils.ts]"]
node_matcher["Style tag matcher<br/>[constants.ts]"]
node_injector["Style injector<br/>[utils.ts]"]
node_head["Document head"]

node_page -->|"loads extension"| node_htmx
node_extension -->|"registers extension"| node_htmx
node_htmx -->|"dispatches event"| node_extension
node_extension -->|"passes response"| node_parser
node_extension -->|"provides cache"| node_cache
node_parser -->|"matches tags"| node_matcher
node_parser -->|"checks IDs"| node_cache
node_extension -->|"passes new styles"| node_injector
node_injector -->|"appends styles"| node_head

click node_extension "https://github.com/amrhalim/htmx-sync-css/blob/master/src/index.ts"
click node_cache "https://github.com/amrhalim/htmx-sync-css/blob/master/src/index.ts"
click node_parser "https://github.com/amrhalim/htmx-sync-css/blob/master/src/utils.ts"
click node_matcher "https://github.com/amrhalim/htmx-sync-css/blob/master/src/constants.ts"
click node_injector "https://github.com/amrhalim/htmx-sync-css/blob/master/src/utils.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_htmx,node_head toneIndigo
class node_extension,node_parser,node_matcher,node_injector toneTeal
class node_cache toneAmber
```

## Components

### Other components

- **Web page**
- **htmx runtime**
- [sync-css extension](https://github.com/amrhalim/htmx-sync-css/blob/master/src/index.ts): `src/index.ts`
- [Style ID cache](https://github.com/amrhalim/htmx-sync-css/blob/master/src/index.ts): `src/index.ts`
- [Style tag parser](https://github.com/amrhalim/htmx-sync-css/blob/master/src/utils.ts): `src/utils.ts`
- [Style tag matcher](https://github.com/amrhalim/htmx-sync-css/blob/master/src/constants.ts): `src/constants.ts`
- [Style injector](https://github.com/amrhalim/htmx-sync-css/blob/master/src/utils.ts): `src/utils.ts`
- **Document head**

## Connections

- Web page → htmx runtime: loads extension (evidence: `README.md`)
- sync-css extension → htmx runtime: registers extension (evidence: `src/index.ts`)
- htmx runtime → sync-css extension: dispatches event (evidence: `src/index.ts`)
- sync-css extension → Style tag parser: passes response (evidence: `src/index.ts`)
- sync-css extension → Style ID cache: provides cache (evidence: `src/index.ts`)
- Style tag parser → Style tag matcher: matches tags (evidence: `src/utils.ts`)
- Style tag parser → Style ID cache: checks IDs (evidence: `src/utils.ts`)
- sync-css extension → Style injector: passes new styles (evidence: `src/index.ts`)
- Style injector → Document head: appends styles (evidence: `src/utils.ts`)
