# mariuslang/mapcn-svelte architecture

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

- Interactive diagram: https://gitdiagram.com/mariuslang/mapcn-svelte
- Repository: https://github.com/mariuslang/mapcn-svelte

## Overview

1. **What this repo is**
   - `mapcn-svelte` is a SvelteKit site plus reusable component library for building MapLibre-based map UIs.
   - It serves three roles at once: marketing/homepage, documentation site, and live component showcase.

2. **Top-level app shape**
   - `src/routes` defines the public site: home, docs, a blocks gallery, and a dynamic `/view/[name]` preview route.
   - `src/routes/+layout.svelte` and `+layout.ts` provide the shared app shell and route-level data loading.

3. **Core library boundary**
   - `src/lib/index.ts` is the main export surface for consumers.
   - The library is split into:
     - `src/lib/registry/blocks/map` for the actual map primitives
     - `src/lib/registry/ui/*` for generic shadcn-style UI primitives
     - `src/lib/components/*` for app-specific docs/home/demo chrome

4. **Map component subsystem**
   - `src/lib/registry/blocks/map` contains the reusable map building blocks: map container, markers, popups, clustering, controls, routes, labels, and theme logic.
   - `src/lib/hooks/use-map.svelte.ts` and `src/lib/theme.ts` sit behind this layer and handle shared map state and theme-aware behavior.
   - The README’s MapLibre/CARTO note matters here: the rendering layer is MapLibre-powered and assumes a compatible basemap provider.

5. **Docs content pipeline**
   - The docs are not just static markdown; they are assembled from code and metadata.
   - `docs-navigation.ts`, `docs-example-loader.ts`, `examples.ts`, `blocks.ts`, `get-block-file-source.ts`, and `highlight.ts` form the content/data layer that turns source files into navigation, previews, and formatted code snippets.
   - This is the key “content transformation” boundary in the repo.

6. **Docs presentation layer**
   - `src/lib/components/docs/*` renders the documentation shell: sidebar, header, layout, table of contents, prop tables, notes, and code blocks.
   - `src/lib/components/docs/preview/*` renders interactive example previews and source-code panes for the docs pages.
   - The docs pages in `src/routes/docs/*` compose these pieces with page-specific content.

7. **Home page / marketing subsystem**
   - `src/lib/components/home/*` powers the landing page with showcase cards and animated example maps.
   - These components are presentation-only and sit above the core map primitives, demonstrating the library in a polished marketing context.

8. **Blocks gallery and live previews**
   - `src/routes/blocks` is a block browser for example pages from the registry.
   - `src/routes/view/[name]` is a dynamic preview route for rendering one named block/example at a time.
   - The `src/lib/components/blocks/*` and `src/lib/registry/blocks/*` layers provide the preview UI, iframe/code display, and the actual block implementations.

9. **UI primitive layer**
   - `src/lib/registry/ui/*` is a large set of low-level reusable components: button, card, dialog, command palette, sidebar, tabs, tooltip, table, select, etc.
   - These are shared infrastructure for the docs site and examples, following shadcn-svelte conventions rather than being map-specific.

10. **Data and example sources**
   - Several registry blocks include local `data.ts` files, which indicates that demos are powered by in-repo sample data rather than remote APIs.
   - This keeps the examples deterministic and allows docs pages to render both code and behavior from the same source tree.

11. **Styling and interaction boundaries**
   - Styling is Tailwind/shadcn-oriented, with a small number of app-level components handling theme toggles, mobile nav, copy buttons, and GitHub links.
   - `src/lib/hooks/is-mobile.svelte.ts` and the theme components bridge responsive behavior and dark/light mode across the site.

12. **Build/test/deploy concerns**
   - The repo includes unit tests around the registry/content utilities and map theme logic, which suggests the non-visual data pipeline is important enough to verify separately.
   - CI is configured via GitHub Actions, and `vercel.json` shows the app is intended for Vercel deployment.

13. **How to draw the architecture**
   - Think of it as: **source registry files and example data** → **content/load utilities** → **Svelte route pages** → **docs/home/block preview components** → **MapLibre-backed map UI in the browser**.
   - The main boundary is between the reusable map component library and the documentation/demo shell that renders and explains it.

Main entry points: [`src/lib/registry/blocks/map`](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/blocks/map) (Map blocks), [`src/routes/+layout.svelte`](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/+layout.svelte) (App layout), [`src/lib/index.ts`](https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/index.ts) (Library API), [`src/routes/docs/+page.svelte`](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/docs/+page.svelte) (Docs pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App shell"]
  node_src_routes_layout["App layout<br/>route shell<br/>[+layout.svelte]"]
  node_src_routes_home["Home page<br/>marketing route<br/>[+page.svelte]"]
  node_src_routes_docs["Docs pages<br/>docs routes<br/>[+page.svelte]"]
  node_src_routes_blocks["Blocks page<br/>gallery route<br/>[+page.svelte]"]
  node_src_routes_view["Preview route<br/>dynamic route<br/>[+page.svelte]"]
end

subgraph group_content["Content pipeline"]
  node_src_lib_docs_pipeline["Docs data<br/>content pipeline"]
end

subgraph group_library["Library core"]
  node_src_lib_index["Library API<br/>exports<br/>[index.ts]"]
  node_src_lib_hooks_use_map["Use map<br/>map state hook<br/>[use-map.svelte.ts]"]
  node_src_lib_theme["Theme<br/>[theme.ts]"]
end

subgraph group_registry["Registry"]
  node_src_lib_registry_map["Map blocks<br/>map primitives"]
  node_src_lib_registry_ui["UI primitives<br/>shadcn ui"]
  node_src_lib_registry_blocks_examples["Block pages<br/>example blocks"]
  node_src_lib_registry_map_theme["Map theme<br/>[theme.ts]"]
end

subgraph group_components["Presentation"]
  node_src_lib_components_docs["Docs chrome<br/>docs UI"]
  node_src_lib_components_docs_preview["Preview UI<br/>example viewer"]
  node_src_lib_components_home["Home chrome<br/>landing UI"]
  node_src_lib_components_blocks["Block viewer<br/>preview UI"]
end

node_src_routes_layout -->|"shells"| node_src_routes_home
node_src_routes_layout -->|"shells"| node_src_routes_docs
node_src_routes_layout -->|"shells"| node_src_routes_blocks
node_src_routes_layout -->|"shells"| node_src_routes_view
node_src_lib_index -->|"exports"| node_src_lib_registry_map
node_src_lib_index -->|"exports"| node_src_lib_registry_ui
node_src_lib_index -->|"exports"| node_src_lib_hooks_use_map
node_src_lib_index -->|"exports"| node_src_lib_theme
node_src_lib_docs_pipeline -->|"feeds"| node_src_routes_docs
node_src_lib_docs_pipeline -->|"feeds"| node_src_lib_components_docs_preview
node_src_lib_docs_pipeline -->|"feeds"| node_src_lib_components_blocks
node_src_lib_docs_pipeline -->|"indexes"| node_src_lib_registry_blocks_examples
node_src_lib_registry_blocks_examples -->|"builds on"| node_src_lib_registry_map
node_src_lib_registry_blocks_examples -->|"uses"| node_src_lib_registry_ui
node_src_lib_components_home -->|"demonstrates"| node_src_lib_registry_map
node_src_lib_components_docs -->|"uses"| node_src_lib_registry_ui
node_src_lib_components_docs -->|"references"| node_src_lib_registry_map
node_src_lib_components_docs_preview -->|"renders"| node_src_lib_registry_map
node_src_lib_components_blocks -->|"renders"| node_src_lib_registry_blocks_examples
node_src_routes_blocks -->|"uses"| node_src_lib_components_blocks
node_src_routes_docs -->|"uses"| node_src_lib_components_docs
node_src_routes_docs -->|"uses"| node_src_lib_components_docs_preview
node_src_routes_home -->|"uses"| node_src_lib_components_home
node_src_routes_view -->|"uses"| node_src_lib_components_docs_preview
node_src_lib_hooks_use_map -->|"supports"| node_src_lib_registry_map
node_src_lib_theme -->|"drives"| node_src_lib_registry_map_theme

click node_src_lib_index "https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/index.ts"
click node_src_lib_hooks_use_map "https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/hooks/use-map.svelte.ts"
click node_src_lib_theme "https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/theme.ts"
click node_src_routes_layout "https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/+layout.svelte"
click node_src_routes_home "https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/(home)/+page.svelte"
click node_src_routes_docs "https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/docs/+page.svelte"
click node_src_routes_blocks "https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/blocks/+page.svelte"
click node_src_routes_view "https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/view/[name]/+page.svelte"
click node_src_lib_registry_map "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/blocks/map"
click node_src_lib_registry_ui "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/ui"
click node_src_lib_components_docs "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/docs"
click node_src_lib_components_docs_preview "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/docs/preview"
click node_src_lib_components_home "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/home"
click node_src_lib_components_blocks "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/blocks"
click node_src_lib_registry_blocks_examples "https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/blocks"
click node_src_lib_registry_map_theme "https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/registry/blocks/map/theme.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_src_routes_layout,node_src_routes_home,node_src_routes_docs,node_src_routes_blocks,node_src_routes_view toneBlue
class node_src_lib_docs_pipeline toneAmber
class node_src_lib_index,node_src_lib_hooks_use_map,node_src_lib_theme toneMint
class node_src_lib_registry_map,node_src_lib_registry_ui,node_src_lib_registry_blocks_examples,node_src_lib_registry_map_theme toneRose
class node_src_lib_components_docs,node_src_lib_components_docs_preview,node_src_lib_components_home,node_src_lib_components_blocks toneIndigo
```

## Components

### App shell

SvelteKit entrypoints, shared layout, and public routes.

- [App layout](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/+layout.svelte): route shell · Shared SvelteKit layout and root data loading. · `src/routes/+layout.svelte`
- [Home page](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/(home)/+page.svelte): marketing route · Landing page for the public site. · `src/routes/(home)/+page.svelte`
- [Docs pages](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/docs/+page.svelte): docs routes · Documentation pages composed from shared docs components. · `src/routes/docs/+page.svelte`
- [Blocks page](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/blocks/+page.svelte): gallery route · Browser for registry blocks and examples. · `src/routes/blocks/+page.svelte`
- [Preview route](https://github.com/mariuslang/mapcn-svelte/blob/main/src/routes/view/[name]/+page.svelte): dynamic route · Renders one named block or example at a time. · `src/routes/view/[name]/+page.svelte`

### Content pipeline

Utilities that turn source files and metadata into docs navigation, previews, and snippets.

- **Docs data**: content pipeline · Navigation, example loading, source extraction, and highlighting.

### Library core

Public export surface plus shared hooks and theme behavior.

- [Library API](https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/index.ts): exports · Main export surface for consumers. · `src/lib/index.ts`
- [Use map](https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/hooks/use-map.svelte.ts): map state hook · Shared map state and integration behavior. · `src/lib/hooks/use-map.svelte.ts`
- [Theme](https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/theme.ts): theme logic · App and map theme-aware behavior. · `src/lib/theme.ts`

### Registry

Reusable map blocks and shared UI primitives.

- [Map blocks](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/blocks/map): map primitives · Reusable map container, markers, popups, clustering, routes, controls, and labels. · `src/lib/registry/blocks/map`
- [UI primitives](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/ui): shadcn ui · Shared low-level interface components used across docs and examples. · `src/lib/registry/ui`
- [Block pages](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/registry/blocks): example blocks · Named example implementations outside the core map primitives. · `src/lib/registry/blocks`
- [Map theme](https://github.com/mariuslang/mapcn-svelte/blob/main/src/lib/registry/blocks/map/theme.ts): map theme · Theme-specific map styling and behavior tests. · `src/lib/registry/blocks/map/theme.ts`

### Presentation

Docs, home, and blocks UI layers that compose the registry.

- [Docs chrome](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/docs): docs UI · Sidebar, header, layout, toc, prop tables, notes, and code blocks. · `src/lib/components/docs`
- [Preview UI](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/docs/preview): example viewer · Interactive docs previews and source-code panes. · `src/lib/components/docs/preview`
- [Home chrome](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/home): landing UI · Marketing page showcase cards and animated map examples. · `src/lib/components/home`
- [Block viewer](https://github.com/mariuslang/mapcn-svelte/tree/main/src/lib/components/blocks): preview UI · Block display, iframe preview, and code viewer for the gallery. · `src/lib/components/blocks`

## Connections

- App layout → Home page: shells · Shared layout wraps the public home route.
- App layout → Docs pages: shells · Shared layout wraps the documentation section.
- App layout → Blocks page: shells · Shared layout wraps the blocks gallery.
- App layout → Preview route: shells · Shared layout wraps dynamic previews.
- Library API → Map blocks: exports · Public API re-exports map primitives.
- Library API → UI primitives: exports · Public API re-exports shared UI primitives.
- Library API → Use map: exports · Public API exposes shared map hook behavior.
- Library API → Theme: exports · Public API exposes theme utilities.
- Docs data → Docs pages: feeds · Docs routes consume generated navigation, examples, and snippets.
- Docs data → Preview UI: feeds · Preview utilities source content for interactive examples.
- Docs data → Block viewer: feeds · Block gallery uses example metadata and source extraction.
- Docs data → Block pages: indexes · Content pipeline scans example blocks and page modules.
- Block pages → Map blocks: builds on · Example blocks compose the reusable map layer.
- Block pages → UI primitives: uses · Example blocks rely on shared UI primitives.
- Home chrome → Map blocks: demonstrates · Landing page examples showcase the map primitives.
- Docs chrome → UI primitives: uses · Docs chrome is built from shared UI primitives.
- Docs chrome → Map blocks: references · Docs explain and embed map components.
- Preview UI → Map blocks: renders · Interactive docs previews render map examples.
- Block viewer → Block pages: renders · Gallery UI renders registered block examples.
- Blocks page → Block viewer: uses · Blocks route composes the gallery presentation.
- Docs pages → Docs chrome: uses · Docs routes compose the docs presentation layer.
- Docs pages → Preview UI: uses · Docs routes embed live previews and code panes.
- Home page → Home chrome: uses · Home route composes landing-page showcase components.
- Preview route → Preview UI: uses · Dynamic preview route reuses preview rendering.
- Use map → Map blocks: supports · Shared hook supports the map block layer.
- Theme → Map theme: drives · Theme utilities feed map styling behavior.
