# finnishtransportagency/suomen-vaylat architecture

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

- Interactive diagram: https://gitdiagram.com/finnishtransportagency/suomen-vaylat
- Repository: https://github.com/finnishtransportagency/suomen-vaylat

## Overview

##### Project type and purpose
- This is a React single-page application (SPA) that integrates with an external Oskari map service.
- It displays Finnish transport infrastructure data via RPC calls, uses a proxy for API calls, and a WebSocket server for file downloads.

##### File structure
- Top-level folder `suomen-vaylat-app` contains the React front-end:
- `public/` – static assets (HTML, fonts, manifest)
- `src/` – app code
– `components/` (UI widgets)
– `state/` (Redux store & slices)
– `utils/` (helpers, RPC & GFI utilities)
– `translations/` (i18n JSON files)
– `webpack.config.js`, environment configs
- `linter/` – pre-commit hooks
- No backend code here; external services (published map, proxy, WebSocket server) are configured via environment variables.

##### README for additional insights
- Environment variables define endpoints:
- `REACT_APP_PUBLISHED_MAP_URL` → Oskari published map with RPC
- `REACT_APP_PROXY_URL` → Proxy domain for API calls
- `REACT_APP_WEBSOCKET_URL` → WebSocket URL for download support
- Shows that the SPA communicates with two main external services plus translations.

##### Main components and interactions
a. Browser / User
b. React SPA
- State Management (Redux slices)
- Utils (RPC, GFI, logging)
c. External Oskari Map Service (RPC endpoint)
d. Proxy Server (REST API)
e. WebSocket Server (file downloads)
f. CDN / Static Host for production build
g. Translation files (build-time resource)

Relationships:
- Browser ↔ React SPA
- SPA → RPC on Oskari map (via `REACT_APP_PUBLISHED_MAP_URL`)
- SPA → Proxy (via `REACT_APP_PROXY_URL`) for backend API calls
- SPA ↔ WebSocket server (via `REACT_APP_WEBSOCKET_URL`)
- Build pipeline picks up translations and environment variables

##### Architectural patterns & design principles
- Component-based UI (React + MUI)
- Unidirectional data flow (Redux store with slices)
- Separation of concerns:
- Presentation (components)
- Business logic (utils, hooks)
- State (Redux)
- Configuration via environment variables (12-factor app)
- Build-time translation injection

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "React SPA"
    direction TB
    Browser((Browser)):::frontend
    Assets["Static Assets (public)"]:::assets
    Entry["Entry & App Shell"]:::frontend
    Components["UI Components"]:::ui
    State["State Management"]:::state
    Utils["Utility Modules"]:::utils
    Translations["Translations"]:::data
    Config["Env & Build Config"]:::config
    Theme["Theming & Styles"]:::theme
    Linter["Linter / Pre-commit Hooks"]:::tools

    Browser -->|loads from CDN| Assets
    Assets --> Entry
    Entry --> Components
    Entry --> State
    Entry --> Utils
    Components --> State
    Components --> Utils
    State --> Components
    Utils --> Components
    Utils -->|"RPC over HTTP"| Oskari
    Utils -->|"REST API"| Proxy
    Utils -->|"WebSocket"| WS
    Translations --> Components
    Config --> Entry
    Theme --> Components
    Linter --> Entry
  end

  subgraph "External Services"
    direction TB
    Oskari([Oskari Map Service]):::external
    Proxy([Proxy / Backend API]):::external
    WS([WebSocket Server]):::external
    CDN([Static Host / CDN]):::external
  end

  CDN --> Browser

  click Assets "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/public/"
  click Components "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/src/components/"
  click State "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/state/store.tsx"
  click State "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/src/state/slices/"
  click State "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/state/hooks.tsx"
  click State "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/state/localStorage.tsx"
  click State "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/state/DataContext.jsx"
  click Utils "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/src/utils/"
  click Translations "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/src/translations/"
  click Config "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/webpack.config.js"
  click Config "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/tsconfig.json"
  click Config "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/react-app-env.d.ts"
  click Linter "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/linter/"
  click Theme "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/custom.scss"
  click Theme "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/_colors.scss"
  click Theme "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/_utils.scss"
  click Theme "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/theme/theme.js"
  click Theme "https://github.com/finnishtransportagency/suomen-vaylat/tree/production/suomen-vaylat-app/src/theme/icons/"
  click Entry "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/index.tsx"
  click Entry "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/App.tsx"
  click Entry "https://github.com/finnishtransportagency/suomen-vaylat/blob/production/suomen-vaylat-app/src/reportWebVitals.ts"

  classDef frontend fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
  classDef ui fill:#BBDEFB,stroke:#42A5F5,color:#0D47A1
  classDef state fill:#C8E6C9,stroke:#66BB6A,color:#1B5E20
  classDef utils fill:#FFF9C4,stroke:#FFEB3B,color:#F57F17
  classDef data fill:#F0F4C3,stroke:#DCE775,color:#827717
  classDef config fill:#E1BEE7,stroke:#BA68C8,color:#4A148C
  classDef tools fill:#FFCCBC,stroke:#FF8A65,color:#BF360C
  classDef theme fill:#F3E5F5,stroke:#CE93D8,color:#6A1B9A
  classDef assets fill:#FFF3E0,stroke:#FFB74D,color:#E65100
  classDef external fill:#FFCDD2,stroke:#E57373,color:#B71C1C
```
