# lhpcode/three3d architecture

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

- Interactive diagram: https://gitdiagram.com/lhpcode/three3d
- Repository: https://github.com/lhpcode/three3d

## Overview

##### Project type and purpose
- This is a browser-based Single-Page Application built with Vue 3.
- It renders 3D scenes (Three.js), data charts (ECharts) and UI controls (Element Plus) for “patrol route” visualization, first-person navigation, device positioning, region detection and alarm highlighting.

##### File structure
Top-level files and folders:
- Configuration
– .env.development / .env.production (runtime configs)
– tsconfig.json / tsconfig.node.json (TypeScript)
– vite.config.ts (Vite build)
– .eslintrc.cjs, .prettierrc (linters/formatters)
- Public assets
– public/fbx, public/gltf (3D models)
– public/texture, public/image (textures & images)
- Source code (src/)
– main.ts, index.html, style.css (app bootstrap & global styles)
– App.vue (root component)
– src/components/… (Vue UI components, e.g. card/index.vue)
– src/hooks/… (composables: useThree, useEcharts, useVModel, useEchartsData)
– src/utils/…
· createDom (DOM helper for mounting canvases, etc.)
· threeUtils (abstractions: SpriteThree, lightThree, modelThree, shader, three)
· index.ts (general helpers)

##### Extract insights from README
- Core libraries: Vue 3, Three.js (0.160), ECharts (5.5), Element Plus (2.6)
- Main features: route patrol, trajectory display, FPS view, shader rendering, device locators, region-entry alerts

##### Main components
a. Front-end SPA (Browser)
- Presentation Layer: Vue 3 components (Element Plus UI, custom `<card>` component)
- 3D Engine Layer: Three.js + shader modules + model loaders (gltf/fbx)
- Chart Layer: ECharts instances driven by useEchartsData composable
- Composables Layer: Reactive hooks (useThree, useVModel, useEcharts, etc.)
- Utilities Layer: DOM creation helpers, threeUtils abstractions, general utils
b. Static Assets
- 3D Models (public/gltf, public/fbx)
- Textures & images (public/texture, public/image)
c. Build & Config
- Vite dev server & builder
- .env files for environment config
d. External Services (implicit)
- HTTP API endpoints for patrol‐route data, device status, region definitions (to be represented as “Backend Services” even if not in this repo)

##### Relationships & interactions
1. Browser → loads index.html → main.ts initializes Vue app
2. App.vue composes UI components and hooks
3. Components call composables:
– useThree sets up WebGL canvas, uses threeUtils to load models & shaders
– useEcharts mounts chart DOM, fetches/updates patrol data
4. Composables fetch JSON from external APIs (routes, device positions, region metadata)
5. Models & textures loaded from public/ assets by threeUtils
6. Charts & 3D scenes render side-by-side; UI controls (Element Plus) dispatch view-mode changes (first-person ↔ top-down)
7. Region detection runs in shaders or JS, triggers alarm UI overlays

##### Architectural patterns & principles
– Modular composition (Vue 3 Composition API for reusability)
– Separation of concerns: Presentation → Business logic (composables) → Data access (utils/fetch) → Static assets
– Layered resource management: asset folder vs. code folder
– Build abstraction: Vite/TS compile chain separate from runtime

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation (Vue Components & Bootstrap)"
        direction TB
        A_index["index.html"]:::ui
        A_main["main.ts"]:::ui
        A_style["style.css"]:::ui
        A_app["App.vue"]:::ui
        A_card["card/index.vue"]:::ui
    end

    subgraph "Business Logic (Composables & Utils)"
        direction TB
        B_useThree["useThree.ts"]:::business
        B_useVModel["useVModel.ts"]:::business
        B_useEcharts["useEcharts.ts"]:::business
        B_useEchartsData["useEchartsData.ts"]:::business
        B_dom["device.ts"]:::business
        B_domDir["createDom"]:::business
        B_utils["index.ts"]:::business
    end

    subgraph "Engines (Three.js & ECharts)"
        direction TB
        E_three["three.ts"]:::engine
        E_model["modelThree.ts"]:::engine
        E_sprite["SpriteThree.ts"]:::engine
        E_light["lightThree.ts"]:::engine
        E_shader["shader.ts"]:::engine
        E_echarts["ECharts Engine"]:::engine
    end

    subgraph "Assets & External API"
        direction TB
        A_models["public/gltf<br/>public/fbx"]:::asset
        A_textures["public/texture<br/>public/image"]:::asset
        A_api["External HTTP APIs"]:::asset
    end

    subgraph "Build & Config"
        direction TB
        C_vite["vite.config.ts"]:::config
        C_ts["tsconfig.json<br/>tsconfig.node.json"]:::config
        C_env[".env.development<br/>.env.production"]:::config
        C_lint[".eslintrc.cjs<br/>.prettierrc"]:::config
    end

    A_index --> A_main --> A_app
    A_app --> A_card
    A_app --> B_useThree
    A_app --> B_useEcharts
    A_app --> B_useVModel
    A_app --> B_useEchartsData

    B_useThree --> E_three
    B_useThree --> E_model
    B_useThree --> E_sprite
    B_useThree --> E_light
    B_useThree --> E_shader
    B_useThree --> B_domDir
    B_useThree --> A_models
    B_useThree --> A_textures

    B_useEcharts --> E_echarts
    B_useEchartsData --> E_echarts

    B_useThree --> A_api
    B_useEcharts --> A_api
    B_useEchartsData --> A_api

    C_env --> C_vite --> A_index

    click A_app "https://github.com/lhpcode/three3d/blob/main/src/App.vue"
    click A_card "https://github.com/lhpcode/three3d/blob/main/src/components/card/index.vue"
    click A_index "https://github.com/lhpcode/three3d/blob/main/index.html"
    click A_main "https://github.com/lhpcode/three3d/blob/main/src/main.ts"
    click A_style "https://github.com/lhpcode/three3d/blob/main/src/style.css"
    click B_useThree "https://github.com/lhpcode/three3d/blob/main/src/hooks/useThree.ts"
    click B_useVModel "https://github.com/lhpcode/three3d/blob/main/src/hooks/useVModel.ts"
    click B_useEcharts "https://github.com/lhpcode/three3d/blob/main/src/hooks/useEcharts.ts"
    click B_useEchartsData "https://github.com/lhpcode/three3d/blob/main/src/hooks/useEchartsData.ts"
    click E_three "https://github.com/lhpcode/three3d/blob/main/src/utils/threeUtils/three.ts"
    click E_model "https://github.com/lhpcode/three3d/blob/main/src/utils/threeUtils/modelThree.ts"
    click E_sprite "https://github.com/lhpcode/three3d/blob/main/src/utils/threeUtils/SpriteThree.ts"
    click E_light "https://github.com/lhpcode/three3d/blob/main/src/utils/threeUtils/lightThree.ts"
    click E_shader "https://github.com/lhpcode/three3d/blob/main/src/utils/threeUtils/shader.ts"
    click B_dom "https://github.com/lhpcode/three3d/blob/main/src/utils/createDom/device.ts"
    click B_domDir "https://github.com/lhpcode/three3d/tree/main/src/utils/createDom"
    click B_utils "https://github.com/lhpcode/three3d/blob/main/src/utils/index.ts"

    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px
    classDef business fill:#90ee90,stroke:#000,stroke-width:1px
    classDef engine fill:#ffa500,stroke:#000,stroke-width:1px
    classDef asset fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef config fill:#cccccc,stroke:#000,stroke-width:1px
```
