# bensonliao/avc-camera-webui-fe architecture

> Architecture diagram of the GitHub repository bensonliao/avc-camera-webui-fe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bensonliao/avc-camera-webui-fe
- Repository: https://github.com/bensonliao/avc-camera-webui-fe

## Overview

##### Project type and purpose
- This repository is a full-stack web application, combining a Node.js/Express “backend” that exposes REST-style handlers (account, asset, snapshot, system) with a rich single-page frontend (under `src`) built with component modules, SCSS styling, i18n support, and bundled via Webpack.
- The README focuses on the “webserver-frontend” setup and build, but the presence of `backend/server.js`, routers, and handlers indicates the Express service also serves APIs and static assets.

##### File structure
- Top-level “backend” folder:
- server.js – entrypoint for Express server
- `routers/web-router.js` – mounts API endpoints
- `handlers/*-handler.js` – implements controller logic
- `models/errors.js` – domain-level error types
- Top-level configuration:
- `config/default.js` – runtime settings
- `.gitlab-ci.yml`, `Gruntfile.js`, `webpack.config.js` – build & CI pipelines
- Frontend source under `src`:
- `src/core` – shared utility modules, state store, custom UI components, validations, i18n, drawing-canvas editor
- `src/web` – page containers, routing, and page-specific logic
- `src/style` – SCSS files, theming & layout
- `i18n` & `languages` – translation infrastructure and locale files
- Testing:
- `cypress/` – end-to-end tests (fixtures, integration, plugins)
- `tests/e2e/` – environment-specific E2E test suites

##### README for additional insights
- Development workflow (npm start, npm build) runs the Webpack dev server and Express backend.
- Branching strategy hints at multi-flavor releases (master vs. avn).
- Links to UI spec (Figma, Behance) confirm the SPA’s design focus.

a. Main components
- Client (Browser SPA)
- Webpack Dev Server / Static Asset Host
- Node.js/Express Backend
- Routers & Handlers (API Layer)
- Configuration Service (reads `config/default.js`)
- External Dependencies (e.g., device SDKs, file system, translation files)
- Cypress E2E Test Harness
b. Relationships & interactions
- Browser SPA → HTTP(S) → Express API endpoints
- Express Routers delegate → Handler controllers → (optional) Models or external services
- SPA uses `src/core/apis/web-api.js` to invoke backend, and `i18n` modules for translations
- Build pipeline (Grunt/Webpack) packages `src` → `dist`, then Express serves `dist`
- Cypress tests simulate user flows against the running dev server
c. Architectural patterns
- MVC-like routing: `router` → `controller/handler` → `model`
- Component-based UI (React or custom view library) under `src/core/components` and `src/web/pages`
- Centralized state/store (`src/core/store.js`)
- Layered separation: config, service, business logic, presentation
d. Key technologies
- Node.js, Express.js
- Webpack, Grunt
- SCSS (styled modularization)
- Cypress (E2E testing)
- i18next (localization)
- Formik (form management)

##### Detailed but not over-engineered
- Shared modules (`src/core`) as reusable library components.
- Keep external services (e.g., device SDK or file storage) clearly labeled but abstracted.
- End-to-end flow: code → build → serve → run → test.

## Diagram (Mermaid)

```mermaid
graph TB

    subgraph "Frontend Source"
        ENTRY["Browser SPA (Client)"]:::frontend
        UI["UI Component Modules"]:::frontend
        STORE["Centralized State Store"]:::frontend
        API["API Service Module"]:::frontend
        I18N["Internationalization Modules"]:::frontend
        STYLE["SCSS Styling & Theming"]:::frontend
    end

    subgraph "Build Pipeline"
        WEBPACK["Webpack Build Configuration"]:::build
        GRUNT["Grunt Build Pipeline"]:::build
        DIST["Bundled Assets (dist)"]:::frontend
    end

    subgraph "Backend"
        SERVER["Express Server"]:::backend
        CONFIG["Runtime Configuration Service"]:::storage
        subgraph "API Layer"
            ROUTER["Express Router"]:::backend
            subgraph "Handlers"
                ACC["AccountHandler"]:::backend
                ASS["AssetHandler"]:::backend
                SNAP["SnapshotHandler"]:::backend
                SYS["SystemHandler"]:::backend
            end
            ERRORS["Domain Error Models"]:::storage
        end
    end

    subgraph "Testing"
        CYPRESS["Cypress End-to-End Test Harness"]:::test
        E2E["Env-Specific E2E Tests"]:::test
    end

    %% Frontend Source relationships
    ENTRY -->|"uses"| UI
    ENTRY -->|"uses"| STORE
    ENTRY -->|"uses"| API
    ENTRY -->|"uses"| I18N
    ENTRY -->|"uses"| STYLE

    %% Build pipeline
    UI -->|"source"| WEBPACK
    STORE -->|"source"| WEBPACK
    API -->|"source"| WEBPACK
    I18N -->|"source"| WEBPACK
    STYLE -->|"source"| WEBPACK

    UI -->|"source"| GRUNT
    STORE -->|"source"| GRUNT
    API -->|"source"| GRUNT
    I18N -->|"source"| GRUNT
    STYLE -->|"source"| GRUNT

    WEBPACK -->|"produces"| DIST
    GRUNT -->|"produces"| DIST

    %% Serving assets
    DIST -->|"served as static assets"| SERVER

    %% Frontend to backend API calls
    API -->|"HTTP(S) calls"| ROUTER

    %% Backend internals
    SERVER -->|"reads"| CONFIG
    SERVER -->|"routes to"| ROUTER
    ROUTER -->|"delegates to"| ACC
    ROUTER -->|"delegates to"| ASS
    ROUTER -->|"delegates to"| SNAP
    ROUTER -->|"delegates to"| SYS

    ACC -->|"may use"| ERRORS
    ASS -->|"may use"| ERRORS
    SNAP -->|"may use"| ERRORS
    SYS -->|"may use"| ERRORS

    %% Testing interactions
    CYPRESS -->|"executes tests against"| SERVER
    CYPRESS -->|"executes tests against"| ENTRY
    E2E -->|"executes tests against"| SERVER

    %% Click Events
    click ENTRY "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/src/web/index.js"
    click UI "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/src/core/components/"
    click STORE "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/src/core/store.js"
    click API "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/src/core/apis/web-api.js"
    click I18N "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/src/i18n/index.js"
    click I18N "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/src/languages/"
    click STYLE "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/src/style/main.scss"
    click STYLE "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/src/style/shared/"
    click WEBPACK "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/webpack.config.js"
    click GRUNT "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/Gruntfile.js"
    click SERVER "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/server.js"
    click ROUTER "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/routers/web-router.js"
    click ACC "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/handlers/account-handler.js"
    click ASS "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/handlers/asset-handler.js"
    click SNAP "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/handlers/snapshot-handler.js"
    click SYS "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/handlers/system-handler.js"
    click ERRORS "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/backend/models/errors.js"
    click CONFIG "https://github.com/bensonliao/avc-camera-webui-fe/blob/master/config/default.js"
    click CYPRESS "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/cypress/"
    click CYPRESS "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/cypress/integration/"
    click E2E "https://github.com/bensonliao/avc-camera-webui-fe/tree/master/tests/e2e/integration/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef build fill:#FFA500,stroke:#000,stroke-width:1px
    classDef storage fill:#FFFF00,stroke:#000,stroke-width:1px
    classDef test fill:#DDA0DD,stroke:#000,stroke-width:1px
```
