# asiercamara/alpr-vue architecture

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

- Interactive diagram: https://gitdiagram.com/asiercamara/alpr-vue
- Repository: https://github.com/asiercamara/alpr-vue

## Overview

1. **Overall shape**
   This is a single-page browser application built with Vue 3 + TypeScript. It has no backend service dependency for runtime recognition: the detection and OCR pipeline runs locally in the browser, with heavy inference offloaded to Web Workers. The root app is organized around camera input, upload input, and a detection/history UI.

2. **Primary runtime boundary**
   The app is split into a **main UI thread** and a **worker-based inference layer**. Vue components, Pinia stores, theming, localization, and user interaction live on the main thread. ONNX model loading and frame processing live in `src/workers/`, which keeps video scanning responsive while AI runs.

3. **Core user flow**
   Input enters the system from two paths: a live webcam via `useCamera` or uploaded/local media via `useStaticMedia` and `MediaUploader`. Both feed frames into the same detection pipeline. The worker returns plate boxes and OCR text, which are validated, grouped, and displayed in the UI.

4. **Inference pipeline**
   The worker side is a two-stage ALPR flow: YOLOv9 plate detection first, then OCR on cropped plate regions. Model assets are shipped in `public/models/` as ONNX files, and `modelsLoader.js` warms them up before use. Detection logic includes image preprocessing, box filtering/NMS, cropping, OCR postprocessing, and text cleanup.

5. **State management boundaries**
   The app state is centralized in three Pinia stores:
   - `appStore`: operational state such as camera status, loading, and errors
   - `plateStore`: detection results, grouping/confirmation, editing, clearing, ordering
   - `settingsStore`: persistent user preferences saved to `localStorage`
   This separation keeps UI state, recognition results, and preferences distinct.

6. **Detection result handling**
   `useDetection` bridges the worker output into application state. It validates plate quality using utility rules, then sends accepted detections into `plateStore`. `plateStore` performs Levenshtein-based grouping and confirmation timing so repeated detections merge into stable plate records rather than noisy duplicates.

7. **UI composition**
   `App.vue` acts as the shell and composes the main subsystems: camera preview, uploader, plate list, modals, settings, help, and toast notifications. `CameraPreview` is the live scanning surface with a `<video>` element plus canvas overlay for boxes. `PlateList` and `PlateModal` are the primary result surfaces for browsing, editing, copying, and exporting detections.

8. **Configuration and personalization**
   User preferences are implemented as first-class architecture, not incidental UI state. `useTheme` controls light/dark/system mode by toggling the document root class. `useLocale` syncs language to vue-i18n. Settings cover recognition behavior, feedback, theme, and language, and are exposed through a dedicated bottom-sheet panel.

9. **Internationalization and accessibility-oriented UI**
   The app includes localized strings for English and Spanish under `src/i18n/`, with automatic browser-language detection plus manual override. The UI uses bottom sheets, toast feedback, icon-only controls, and responsive layouts optimized for mobile and camera use, which affects component structure and interaction design.

10. **Utility layer**
   Several small utilities support the main flow without owning state: `export.ts` generates CSV output, `feedback.ts` handles audio/vibration confirmation feedback, and `validation.ts` contains plate quality rules and similarity helpers. These are invoked from stores/composables rather than directly from UI components, keeping logic centralized.

11. **Assets and offline behavior**
   The app ships its own models, sample media, PWA manifest, and static assets inside the repo. Because the recognition stack runs client-side and uses browser APIs like camera access, WebAssembly, and OffscreenCanvas, the deployment model is static hosting rather than server rendering or API-backed execution.

12. **Tooling and quality gates**
   The repo is built with Vite, type-checked with `vue-tsc`, tested with Vitest, linted with ESLint, and formatted with Prettier. Component and composable test files are colocated with implementation, which suggests a design focused on behavior-level verification around the stores, worker bridge, and UI states.

Main entry points: [`src/App.vue`](https://github.com/asiercamara/alpr-vue/blob/main/src/App.vue) (App shell), [`src/stores/plateStore.ts`](https://github.com/asiercamara/alpr-vue/blob/main/src/stores/plateStore.ts) (plateStore), [`src/composables/useDetection.ts`](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useDetection.ts) (useDetection), [`src/workers/mainWorker.js`](https://github.com/asiercamara/alpr-vue/blob/main/src/workers/mainWorker.js) (main worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_main["Main thread"]
  node_main_ts["main.ts<br/>app bootstrap<br/>[main.ts]"]
  node_app_vue["App shell<br/>vue shell<br/>[App.vue]"]
  node_camera_preview["Camera preview<br/>ui surface<br/>[CameraPreview.vue]"]
  node_media_uploader["Media uploader<br/>input ui<br/>[MediaUploader.vue]"]
  node_plate_list["Plate list<br/>results ui<br/>[PlateList.vue]"]
  node_plate_modal["Plate modal<br/>details ui<br/>[PlateModal.vue]"]
  node_settings_sheet["Settings sheet<br/>prefs ui<br/>[SettingsSheet.vue]"]
  node_help_sheet["Help sheet<br/>support ui<br/>[HelpSheet.vue]"]
  node_use_camera["useCamera<br/>composable<br/>[useCamera.ts]"]
  node_use_static_media["useStaticMedia<br/>composable<br/>[useStaticMedia.ts]"]
  node_use_detection["useDetection<br/>bridge composable<br/>[useDetection.ts]"]
  node_app_store["appStore<br/>ui state<br/>[appStore.ts]"]
  node_plate_store["plateStore<br/>result state<br/>[plateStore.ts]"]
  node_settings_store["settingsStore<br/>prefs state<br/>[settingsStore.ts]"]
  node_use_theme["useTheme<br/>theme composable<br/>[useTheme.ts]"]
  node_use_locale["useLocale<br/>locale composable<br/>[useLocale.ts]"]
  node_i18n_core["i18n<br/>localization<br/>[index.ts]"]
  node_validation["validation<br/>rules util<br/>[validation.ts]"]
  node_feedback["feedback<br/>[feedback.ts]"]
  node_export_csv["export<br/>[export.ts]"]
end

subgraph group_worker["Inference layer"]
  node_main_worker["main worker<br/>worker bridge<br/>[mainWorker.js]"]
  node_models_loader["models loader<br/>worker init<br/>[modelsLoader.js]"]
  node_detector_pipeline["detector pipeline<br/>plate detection"]
  node_ocr_pipeline["ocr pipeline<br/>ocr stage<br/>[ocrProcessor.js]"]
end

subgraph group_assets["Assets"]
  node_models_bundle[("model assets<br/>onnx assets")]
  node_sample_media["sample media<br/>test assets"]
end

node_main_ts -->|"mounts"| node_app_vue
node_app_vue -->|"composes"| node_camera_preview
node_app_vue -->|"composes"| node_media_uploader
node_app_vue -->|"composes"| node_plate_list
node_app_vue -->|"composes"| node_plate_modal
node_app_vue -->|"composes"| node_settings_sheet
node_app_vue -->|"composes"| node_help_sheet
node_app_vue -->|"uses"| node_use_camera
node_app_vue -->|"uses"| node_use_static_media
node_app_vue -->|"uses"| node_use_detection
node_use_detection -->|"posts frames"| node_main_worker
node_main_worker -->|"initializes"| node_models_loader
node_main_worker -->|"runs"| node_detector_pipeline
node_detector_pipeline -->|"crops to OCR"| node_ocr_pipeline
node_main_worker -->|"loads assets"| node_models_bundle
node_use_detection -->|"validates"| node_validation
node_use_detection -->|"commits"| node_plate_store
node_plate_store -->|"exports"| node_export_csv
node_plate_store -->|"triggers"| node_feedback
node_settings_store -->|"drives"| node_use_theme
node_settings_store -->|"drives"| node_use_locale
node_use_locale -->|"syncs"| node_i18n_core
node_plate_list -->|"reads"| node_plate_store
node_plate_modal -->|"edits"| node_plate_store
node_settings_sheet -->|"edits"| node_settings_store
node_camera_preview -->|"binds"| node_use_camera
node_media_uploader -->|"binds"| node_use_static_media
node_use_camera -.->|"demo input"| node_sample_media

click node_main_ts "https://github.com/asiercamara/alpr-vue/blob/main/src/main.ts"
click node_app_vue "https://github.com/asiercamara/alpr-vue/blob/main/src/App.vue"
click node_camera_preview "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/CameraPreview.vue"
click node_media_uploader "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/MediaUploader.vue"
click node_plate_list "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/PlateList.vue"
click node_plate_modal "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/PlateModal.vue"
click node_settings_sheet "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/SettingsSheet.vue"
click node_help_sheet "https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/HelpSheet.vue"
click node_use_camera "https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useCamera.ts"
click node_use_static_media "https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useStaticMedia.ts"
click node_use_detection "https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useDetection.ts"
click node_app_store "https://github.com/asiercamara/alpr-vue/blob/main/src/stores/appStore.ts"
click node_plate_store "https://github.com/asiercamara/alpr-vue/blob/main/src/stores/plateStore.ts"
click node_settings_store "https://github.com/asiercamara/alpr-vue/blob/main/src/stores/settingsStore.ts"
click node_use_theme "https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useTheme.ts"
click node_use_locale "https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useLocale.ts"
click node_i18n_core "https://github.com/asiercamara/alpr-vue/blob/main/src/i18n/index.ts"
click node_validation "https://github.com/asiercamara/alpr-vue/blob/main/src/utils/validation.ts"
click node_feedback "https://github.com/asiercamara/alpr-vue/blob/main/src/utils/feedback.ts"
click node_export_csv "https://github.com/asiercamara/alpr-vue/blob/main/src/utils/export.ts"
click node_main_worker "https://github.com/asiercamara/alpr-vue/blob/main/src/workers/mainWorker.js"
click node_models_loader "https://github.com/asiercamara/alpr-vue/blob/main/src/workers/modelsLoader.js"
click node_detector_pipeline "https://github.com/asiercamara/alpr-vue/blob/main/src/workers/detector/detector/detectionProcessor.js"
click node_ocr_pipeline "https://github.com/asiercamara/alpr-vue/blob/main/src/workers/ocr/ocr/ocrProcessor.js"
click node_models_bundle "https://github.com/asiercamara/alpr-vue/tree/main/public/models"
click node_sample_media "https://github.com/asiercamara/alpr-vue/tree/main/public/test"

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_main_ts,node_app_vue,node_camera_preview,node_media_uploader,node_plate_list,node_plate_modal,node_settings_sheet,node_help_sheet,node_use_camera,node_use_static_media,node_use_detection,node_app_store,node_plate_store,node_settings_store,node_use_theme,node_use_locale,node_i18n_core,node_validation,node_feedback,node_export_csv toneBlue
class node_main_worker,node_models_loader,node_detector_pipeline,node_ocr_pipeline toneAmber
class node_models_bundle,node_sample_media toneMint
```

## Components

### Main thread

Vue UI, state, localization, and user interaction run in the browser UI thread.

- [main.ts](https://github.com/asiercamara/alpr-vue/blob/main/src/main.ts): app bootstrap · Creates the Vue application and registers global plugins/runtime setup. · `src/main.ts`
- [App shell](https://github.com/asiercamara/alpr-vue/blob/main/src/App.vue): vue shell · Top-level composition of camera, upload, results, settings, help, and notifications. · `src/App.vue`
- [Camera preview](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/CameraPreview.vue): ui surface · Live video scanning surface with overlay feedback for detection results. · `src/components/ui/CameraPreview.vue`
- [Media uploader](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/MediaUploader.vue): input ui · Upload and local media entry point for static image/video scanning. · `src/components/ui/MediaUploader.vue`
- [Plate list](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/PlateList.vue): results ui · Primary browsing surface for detected plates, ordering, and actions. · `src/components/ui/PlateList.vue`
- [Plate modal](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/PlateModal.vue): details ui · Expanded record view for editing, copying, and exporting a detection. · `src/components/ui/PlateModal.vue`
- [Settings sheet](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/SettingsSheet.vue): prefs ui · Bottom-sheet controls for recognition behavior, theme, language, and feedback. · `src/components/ui/SettingsSheet.vue`
- [Help sheet](https://github.com/asiercamara/alpr-vue/blob/main/src/components/ui/HelpSheet.vue): support ui · Guidance and usage help for the camera-first scanning workflow. · `src/components/ui/HelpSheet.vue`
- [useCamera](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useCamera.ts): composable · Manages webcam access, camera state, and live capture orchestration. · `src/composables/useCamera.ts`
- [useStaticMedia](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useStaticMedia.ts): composable · Handles uploaded or local media playback and frame extraction. · `src/composables/useStaticMedia.ts`
- [useDetection](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useDetection.ts): bridge composable · Bridges worker output into application state and applies detection validation. · `src/composables/useDetection.ts`
- [appStore](https://github.com/asiercamara/alpr-vue/blob/main/src/stores/appStore.ts): ui state · Operational state for camera status, loading, and errors. · `src/stores/appStore.ts`
- [plateStore](https://github.com/asiercamara/alpr-vue/blob/main/src/stores/plateStore.ts): result state · Central store for recognition results, grouping, confirmation, editing, and clearing. · `src/stores/plateStore.ts`
- [settingsStore](https://github.com/asiercamara/alpr-vue/blob/main/src/stores/settingsStore.ts): prefs state · Persistent user preferences saved to local storage. · `src/stores/settingsStore.ts`
- [useTheme](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useTheme.ts): theme composable · Switches light, dark, and system theme modes by updating the document root. · `src/composables/useTheme.ts`
- [useLocale](https://github.com/asiercamara/alpr-vue/blob/main/src/composables/useLocale.ts): locale composable · Synchronizes language selection with vue-i18n and browser defaults. · `src/composables/useLocale.ts`
- [i18n](https://github.com/asiercamara/alpr-vue/blob/main/src/i18n/index.ts): localization · Localization bootstrap and runtime translation registry. · `src/i18n/index.ts`
- [validation](https://github.com/asiercamara/alpr-vue/blob/main/src/utils/validation.ts): rules util · Plate quality rules and similarity helpers used before accepting detections. · `src/utils/validation.ts`
- [feedback](https://github.com/asiercamara/alpr-vue/blob/main/src/utils/feedback.ts): feedback util · Audio and vibration confirmation feedback triggered on successful recognition. · `src/utils/feedback.ts`
- [export](https://github.com/asiercamara/alpr-vue/blob/main/src/utils/export.ts): export util · CSV export generation for plate records. · `src/utils/export.ts`

### Inference layer

Web Worker-based detection and OCR pipeline that keeps processing off the UI thread.

- [main worker](https://github.com/asiercamara/alpr-vue/blob/main/src/workers/mainWorker.js): worker bridge · Browser worker entry that coordinates model loading and inference messages. · `src/workers/mainWorker.js`
- [models loader](https://github.com/asiercamara/alpr-vue/blob/main/src/workers/modelsLoader.js): worker init · Loads and warms ONNX models before inference starts. · `src/workers/modelsLoader.js`
- [detector pipeline](https://github.com/asiercamara/alpr-vue/blob/main/src/workers/detector/detector/detectionProcessor.js): plate detection · YOLO-based plate detection with preprocessing, filtering, cropping, and box handling. · `src/workers/detector/detector/detectionProcessor.js`
- [ocr pipeline](https://github.com/asiercamara/alpr-vue/blob/main/src/workers/ocr/ocr/ocrProcessor.js): ocr stage · OCR processing for cropped plates plus text cleanup and postprocessing. · `src/workers/ocr/ocr/ocrProcessor.js`

### Assets

Bundled models, sample media, and static app assets shipped with the client app.

- [model assets](https://github.com/asiercamara/alpr-vue/tree/main/public/models): onnx assets · Packaged ONNX models and config files used entirely client-side. · `public/models`
- [sample media](https://github.com/asiercamara/alpr-vue/tree/main/public/test): test assets · Bundled videos used for local testing and demo playback. · `public/test`

## Connections

- main.ts → App shell: mounts · Bootstraps the Vue application shell.
- App shell → Camera preview: composes · Places the live camera scanning surface in the shell.
- App shell → Media uploader: composes · Provides upload and static-media entry points.
- App shell → Plate list: composes · Renders the main result browsing surface.
- App shell → Plate modal: composes · Opens detailed record editing and export flows.
- App shell → Settings sheet: composes · Exposes user preferences and recognition settings.
- App shell → Help sheet: composes · Provides workflow help and usage guidance.
- App shell → useCamera: uses · Connects live camera input into the app.
- App shell → useStaticMedia: uses · Connects uploads and local media into the app.
- App shell → useDetection: uses · Routes frames into the recognition bridge.
- useDetection → main worker: posts frames · Sends frames to worker-based inference and receives detections back.
- main worker → models loader: initializes · Loads and warms the model runtime before processing.
- main worker → detector pipeline: runs · Executes plate detection on incoming frames.
- detector pipeline → ocr pipeline: crops to OCR · Passes detected plate regions to OCR for text extraction.
- main worker → model assets: loads assets · Reads packaged ONNX models from the static asset bundle.
- useDetection → validation: validates · Filters accepted detections using plate quality rules.
- useDetection → plateStore: commits · Stores accepted plates and updates grouping state.
- plateStore → export: exports · Produces CSV output from stored plate records.
- plateStore → feedback: triggers · Emits recognition feedback when detections stabilize.
- settingsStore → useTheme: drives · Feeds theme preference into the theme controller.
- settingsStore → useLocale: drives · Feeds language preference into the locale controller.
- useLocale → i18n: syncs · Keeps the UI language aligned with the translation runtime.
- Plate list → plateStore: reads · Displays grouped detection history from state.
- Plate modal → plateStore: edits · Updates and confirms individual plate records.
- Settings sheet → settingsStore: edits · Persists recognition and UI preferences.
- Camera preview → useCamera: binds · Uses the live camera stream and capture controls.
- Media uploader → useStaticMedia: binds · Feeds uploaded media into frame extraction.
- useCamera → sample media: demo input · Shares the same media pipeline with bundled sample clips.
