# platong34821/project-dsm architecture

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

- Interactive diagram: https://gitdiagram.com/platong34821/project-dsm
- Repository: https://github.com/platong34821/project-dsm

## Overview

1. **Project shape**
   - This is a **SvelteKit** frontend application, not a full backend service.
   - The repo is centered on a road-safety map experience described in the README: hazards, user reports, and GPS-style alerts.

2. **Top-level app boundary**
   - `src/app.html`, `src/app.d.ts`, `svelte.config.js`, and `vite.config.js` define the SvelteKit runtime and build pipeline.
   - `package.json`/`package-lock.json` manage the app dependencies and scripts; Vite is the local dev/build toolchain.

3. **Route-level UI structure**
   - The user-facing app is organized under `src/routes`.
   - `+layout.svelte` is the shared shell for all pages.
   - `+page.svelte` is the main landing/home view.
   - `save.svelte` is a separate page, likely for persisting or submitting route/report data based on the project theme.

4. **Primary functional subsystem: map-centered safety UI**
   - The README’s “real-time map data” and “gps-based notifications” imply the main experience is map-driven.
   - The route components are where the map, hazard overlays, and user-facing alerts would be assembled.

5. **Reusable application library layer**
   - `src/lib/index.js` is the app’s internal library entry point.
   - `src/lib/assets` holds static application assets used by the Svelte components.
   - This is the boundary for shared UI helpers/resources that should not live directly in a route.

6. **Vendored Leaflet mapping stack**
   - The repository includes a full local copy of **Leaflet** under `src/lib/leaflet`.
   - This is the core map rendering engine and strongly suggests the app runs the map entirely on the client side in the browser.

7. **Routing and directions subsystem**
   - `src/lib/leaflet-routing-machine` is a vendored routing plugin for Leaflet.
   - Its source includes route planning, waypoint handling, itinerary rendering, geocoding hooks, and OSRM/Mapbox adapters.
   - Architecturally, this is the part that would turn locations into routes and turn routes into displayed directions.

8. **External routing / geocoding dependencies**
   - The routing machine contains adapters for **OSRM v1** and **Mapbox**, which means the app can integrate with external routing services.
   - This matters for architecture because the map UI is likely not doing routing computation locally; it delegates to a route provider.

9. **Data flow from user action to map output**
   - A likely flow is: user loads the Svelte page → map initializes via Leaflet → route/geocoder plugins request route data → the UI displays roads, hazards, and guidance.
   - User reports or saved data would likely be captured in a route like `save.svelte` and then reflected back in the map experience.

10. **Testing and examples live inside vendored code, not the app**
   - The Leaflet Routing Machine copy includes its own `examples` and `test` directories, plus Jasmine specs.
   - These are library-level artifacts and indicate the routing subsystem is imported as source/vendor code rather than treated as a remote npm-only dependency.

11. **Static delivery model**
   - `static/robots.txt` and the absence of server-side app code suggest a mostly static/browser-executed application.
   - Any real-time behavior is therefore expected to happen through client-side calls to mapping/routing APIs rather than server-rendered logic.

12. **Architectural summary**
   - The repo is essentially a **SvelteKit SPA-style frontend** with a shared layout, a small set of route pages, and a large embedded mapping stack.
   - Leaflet handles map rendering; Leaflet Routing Machine handles directions and geocoding; the Svelte routes provide the application UI for road-safety reporting and alerts.

Main entry points: [`src/lib/leaflet-routing-machine/src/index.js`](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/index.js) (Routing plugin), [`src/routes/+page.svelte`](https://github.com/platong34821/project-dsm/blob/main/src/routes/+page.svelte) (Home), [`svelte.config.js`](https://github.com/platong34821/project-dsm/blob/main/svelte.config.js) (SvelteKit), [`src/routes/save.svelte`](https://github.com/platong34821/project-dsm/blob/main/src/routes/save.svelte) (Save page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["SvelteKit app"]
  node_package["Package<br/>deps/scripts<br/>[package.json]"]
  node_vite["Vite<br/>build tool<br/>[vite.config.js]"]
  node_svelte["SvelteKit<br/>runtime config<br/>[svelte.config.js]"]
  node_apphtml["App shell<br/>HTML template<br/>[app.html]"]
  node_appdts["Types<br/>type defs<br/>[app.d.ts]"]
  node_static["Static<br/>public files<br/>[robots.txt]"]
end

subgraph group_routes["Routes"]
  node_layout["Layout<br/>route shell<br/>[+layout.svelte]"]
  node_home["Home<br/>main page<br/>[+page.svelte]"]
  node_save["Save page<br/>route page<br/>[save.svelte]"]
end

subgraph group_lib["Shared lib"]
  node_libentry["Lib entry<br/>shared entry<br/>[index.js]"]
  node_assets[("Assets<br/>static resources")]
end

subgraph group_mapping["Mapping stack"]
  node_leaflet["Leaflet<br/>map engine<br/>[leaflet-src.esm.js]"]
end

subgraph group_routing["Routing machine"]
  node_lrm["Routing plugin<br/>directions plugin<br/>[index.js]"]
  node_plan["Plan<br/>[plan.js]"]
  node_itin["Itinerary<br/>ui formatter"]
  node_geocode["Geocoding<br/>provider adapters"]
  node_osrm["OSRM v1<br/>routing adapter<br/>[osrm-v1.js]"]
  node_mapbox["Mapbox<br/>routing adapter<br/>[mapbox.js]"]
end

node_package -->|"uses"| node_vite
node_package -->|"configures"| node_svelte
node_svelte -->|"renders"| node_apphtml
node_svelte -->|"types"| node_appdts
node_layout -->|"wraps"| node_home
node_layout -->|"wraps"| node_save
node_home -->|"maps"| node_leaflet
node_home -->|"routes"| node_lrm
node_save -->|"uses"| node_libentry
node_libentry -->|"loads"| node_assets
node_leaflet -->|"extends"| node_lrm
node_lrm -->|"includes"| node_plan
node_lrm -->|"includes"| node_itin
node_lrm -->|"includes"| node_geocode
node_lrm -->|"adapts"| node_osrm
node_lrm -->|"adapts"| node_mapbox
node_home -->|"serves"| node_static
node_save -->|"serves"| node_static

click node_package "https://github.com/platong34821/project-dsm/blob/main/package.json"
click node_vite "https://github.com/platong34821/project-dsm/blob/main/vite.config.js"
click node_svelte "https://github.com/platong34821/project-dsm/blob/main/svelte.config.js"
click node_apphtml "https://github.com/platong34821/project-dsm/blob/main/src/app.html"
click node_appdts "https://github.com/platong34821/project-dsm/blob/main/src/app.d.ts"
click node_layout "https://github.com/platong34821/project-dsm/blob/main/src/routes/+layout.svelte"
click node_home "https://github.com/platong34821/project-dsm/blob/main/src/routes/+page.svelte"
click node_save "https://github.com/platong34821/project-dsm/blob/main/src/routes/save.svelte"
click node_libentry "https://github.com/platong34821/project-dsm/blob/main/src/lib/index.js"
click node_assets "https://github.com/platong34821/project-dsm/tree/main/src/lib/assets"
click node_leaflet "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet/dist/leaflet-src.esm.js"
click node_lrm "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/index.js"
click node_plan "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/plan.js"
click node_itin "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/itinerary-builder.js"
click node_geocode "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/geocoder-element.js"
click node_osrm "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/osrm-v1.js"
click node_mapbox "https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/mapbox.js"
click node_static "https://github.com/platong34821/project-dsm/blob/main/static/robots.txt"

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_package,node_vite,node_svelte,node_apphtml,node_appdts,node_static toneBlue
class node_layout,node_home,node_save toneAmber
class node_libentry,node_assets toneMint
class node_leaflet toneRose
class node_lrm,node_plan,node_itin,node_geocode,node_osrm,node_mapbox toneIndigo
```

## Components

### SvelteKit app

Top-level frontend runtime and build boundary.

- [Package](https://github.com/platong34821/project-dsm/blob/main/package.json): deps/scripts · Dependency and script manifest for the app. · `package.json`
- [Vite](https://github.com/platong34821/project-dsm/blob/main/vite.config.js): build tool · Local dev and production bundling pipeline. · `vite.config.js`
- [SvelteKit](https://github.com/platong34821/project-dsm/blob/main/svelte.config.js): runtime config · SvelteKit app configuration and runtime integration. · `svelte.config.js`
- [App shell](https://github.com/platong34821/project-dsm/blob/main/src/app.html): HTML template · Base document template for the client app. · `src/app.html`
- [Types](https://github.com/platong34821/project-dsm/blob/main/src/app.d.ts): type defs · Global app type declarations. · `src/app.d.ts`
- [Static](https://github.com/platong34821/project-dsm/blob/main/static/robots.txt): public files · Browser-served static content. · `static/robots.txt`

### Routes

User-facing pages and shared shell.

- [Layout](https://github.com/platong34821/project-dsm/blob/main/src/routes/+layout.svelte): route shell · Shared page chrome for all routes. · `src/routes/+layout.svelte`
- [Home](https://github.com/platong34821/project-dsm/blob/main/src/routes/+page.svelte): main page · Primary landing view for the road-safety experience. · `src/routes/+page.svelte`
- [Save page](https://github.com/platong34821/project-dsm/blob/main/src/routes/save.svelte): route page · Page for persisting or submitting route/report data. · `src/routes/save.svelte`

### Shared lib

Reusable app code and assets.

- [Lib entry](https://github.com/platong34821/project-dsm/blob/main/src/lib/index.js): shared entry · Internal application library entry point. · `src/lib/index.js`
- [Assets](https://github.com/platong34821/project-dsm/tree/main/src/lib/assets): static resources · Shared app assets consumed by UI components. · `src/lib/assets`

### Mapping stack

Vendored client-side mapping and routing libraries.

- [Leaflet](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet/dist/leaflet-src.esm.js): map engine · Vendored client-side map rendering engine. · `src/lib/leaflet/dist/leaflet-src.esm.js`

### Routing machine

Leaflet routing plugin internals and adapters.

- [Routing plugin](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/index.js): directions plugin · Vendored routing and itinerary layer for Leaflet. · `src/lib/leaflet-routing-machine/src/index.js`
- [Plan](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/plan.js): route planning · Waypoint and route-planning model for directions. · `src/lib/leaflet-routing-machine/src/plan.js`
- [Itinerary](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/itinerary-builder.js): ui formatter · Builds displayed turn-by-turn directions and route summary. · `src/lib/leaflet-routing-machine/src/itinerary-builder.js`
- [Geocoding](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/geocoder-element.js): provider adapters · Geocoder hooks and provider integrations. · `src/lib/leaflet-routing-machine/src/geocoder-element.js`
- [OSRM v1](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/osrm-v1.js): routing adapter · Adapter for OSRM-based route services. · `src/lib/leaflet-routing-machine/src/osrm-v1.js`
- [Mapbox](https://github.com/platong34821/project-dsm/blob/main/src/lib/leaflet-routing-machine/src/mapbox.js): routing adapter · Adapter for Mapbox route services. · `src/lib/leaflet-routing-machine/src/mapbox.js`

## Connections

- Package → Vite: uses · Scripts and dependencies drive the Vite toolchain.
- Package → SvelteKit: configures · Package setup supports the SvelteKit app runtime.
- SvelteKit → App shell: renders · SvelteKit uses the app shell as the base document.
- SvelteKit → Types: types · App configuration ties into shared type declarations.
- Layout → Home: wraps · Shared shell provides common structure for pages.
- Layout → Save page: wraps · Shared shell provides common structure for pages.
- Home → Leaflet: maps · Main page initializes and displays the map experience.
- Home → Routing plugin: routes · Home view can attach routing and direction controls.
- Save page → Lib entry: uses · Save flow can share internal helpers and UI resources.
- Lib entry → Assets: loads · Shared library exposes application assets.
- Leaflet → Routing plugin: extends · Routing plugin builds on top of the Leaflet map engine.
- Routing plugin → Plan: includes · Routing machine manages route planning state.
- Routing plugin → Itinerary: includes · Routing machine renders route instructions and itinerary UI.
- Routing plugin → Geocoding: includes · Routing machine supports geocoding and search inputs.
- Routing plugin → OSRM v1: adapts · Routing machine can delegate route computation to OSRM.
- Routing plugin → Mapbox: adapts · Routing machine can delegate route computation to Mapbox.
- Home → Static: serves · Client app can deliver browser-visible static content.
- Save page → Static: serves · Static assets are available to the save/report page.
