How mariuslang/mapcn-svelte works
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: map Map blocks · +layout.svelte App layout · index.ts Library API · +page.svelte Docs pages
Components 17
App shell
SvelteKit entrypoints, shared layout, and public routes.
- App layout · Shared SvelteKit layout and root data loading.
src/routes/+layout.svelte - Home page · Landing page for the public site.
src/routes/(home)/+page.svelte - Docs pages · Documentation pages composed from shared docs components.
src/routes/docs/+page.svelte - Blocks page · Browser for registry blocks and examples.
src/routes/blocks/+page.svelte - Preview 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 · Navigation, example loading, source extraction, and highlighting.
Library core
Public export surface plus shared hooks and theme behavior.
- Library API · Main export surface for consumers.
src/lib/index.ts - Use map · Shared map state and integration behavior.
src/lib/hooks/use-map.svelte.ts - Theme · App and map theme-aware behavior.
src/lib/theme.ts
Registry
Reusable map blocks and shared UI primitives.
- Map blocks · Reusable map container, markers, popups, clustering, routes, controls, and labels.
src/lib/registry/blocks/map - UI primitives · Shared low-level interface components used across docs and examples.
src/lib/registry/ui - Block pages · Named example implementations outside the core map primitives.
src/lib/registry/blocks - 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 · Sidebar, header, layout, toc, prop tables, notes, and code blocks.
src/lib/components/docs - Preview UI · Interactive docs previews and source-code panes.
src/lib/components/docs/preview - Home chrome · Marketing page showcase cards and animated map examples.
src/lib/components/home - Block viewer · Block display, iframe preview, and code viewer for the gallery.
src/lib/components/blocks
Connections 26
- 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.