# incode-technologies-example-repos/onboarding-core-javascript architecture

> Architecture diagram of the GitHub repository incode-technologies-example-repos/onboarding-core-javascript, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/incode-technologies-example-repos/onboarding-core-javascript
- Repository: https://github.com/incode-technologies-example-repos/onboarding-core-javascript

## Overview

##### Project type and purpose
- This is a single‐page, front‑end demo built with vanilla JavaScript and Vite.
- It shows a simplified onboarding flow: createSession → frontId/backId → processId → selfie capture → finishStatus.
- It uses a fake backend module (fake_backend.js) for local testing but is designed to integrate with a real backend API (VITE_API_URL).
- It also loads an external WebSDK (VITE_SDK_URL) for biometric flows.

##### File structure
- Top level:
- index.html – entry HTML
- main.js – app bootstrap & flow orchestration
- fake_backend.js – in‑browser stub for server calls
- vite.config.js – Vite dev server config
- .env.example – template env vars for API URLs & keys
- public/ contains static assets (style.css, SDK file if overridden).
- No separate “backend” server folder—backend logic lives in fake_backend.js or in external API.

##### Extract insights from the README
- Uses Vite dev server over HTTPS, enabling mobile testing.
- Environment variables configure two endpoints:
- VITE_API_URL (real onboarding API)
- VITE_FAKE_BACKEND_APIURL (demo stub)
- Emphasizes that API keys/flow IDs must never go in the frontend in production.
- Build output in dist/ for static hosting.

##### Main components
a. Frontend (Browser)
- UI Layer (index.html + public/style.css)
- App Logic (main.js orchestrating steps)
- Fake Backend Module (fake_backend.js)
- External WebSDK (loaded via VITE_SDK_URL)
b. Vite Dev Server (local HTTPS server)
c. Environment Configuration (.env.local)
d. External Services
- Real Onboarding API (VITE_API_URL)
- (Optional) Fake Backend API URL (VITE_FAKE_BACKEND_APIURL) if swapped out
e. Build Output (dist/) — for production static hosting

##### Relationships & data flows
1) Browser requests index.html→Vite
2) Vite serves main.js & style.css → Browser
3) main.js loads the WebSDK script (VITE_SDK_URL) → Browser executes SDK
4) When user triggers a step (e.g. createSession), main.js calls fake_backend.js or directly calls VITE_API_URL.
5) fake_backend.js forwards requests to VITE_FAKE_BACKEND_APIURL (for demo)
6) Browser receives responses → SDK/UI updates → next step
7) Build: Vite outputs dist/ for static hosting (HTTPS required)

##### Architectural patterns & design principles
- Separation of concerns: UI, app logic, backend calls (stubbed or real).
- Configuration‐driven endpoints (via Env).
- Single‐page app served by a dev server, no server side beyond API.
- Pluggable “backend” stub—facilitates swap to real service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: Browser/Frontend
    subgraph "Browser / Frontend"
        direction TB
        UI["UI Layer\nindex.html"]:::client
        Styles["Stylesheet\npublic/style.css"]:::client
        AppLogic["App Logic\nmain.js"]:::client
        FakeStub["Fake Backend Module\nfake_backend.js"]:::client
        WebSDK["External WebSDK"]:::client
    end

    %% Vite Dev Server
    Vite["Vite Dev Server"]:::server

    %% Environment & Metadata
    subgraph "Configuration & Metadata"
        direction TB
        Config["Env Config\n.env.example"]:::config
        Meta["Project Metadata\npackage.json"]:::config
        Docs["Project Docs\nREADME.md"]:::config
    end

    %% External Services
    subgraph "External API Services"
        direction TB
        RealAPI["Onboarding API\nVITE_API_URL"]:::external
        FakeAPI["Fake Backend API\nVITE_FAKE_BACKEND_APIURL"]:::external
    end

    %% Build Output
    Build["Build Output\ndist/"]:::server

    %% Flows
    UI -->|"GET index.html"| Vite
    Styles -->|"GET style.css"| Vite
    AppLogic -->|"GET main.js"| Vite
    Vite -->|"serves index.html, JS & CSS"| UI

    AppLogic -.->|"loads SDK via VITE_SDK_URL"| WebSDK

    AppLogic -->|"calls createSession, getFrontId... "| FakeStub
    AppLogic -->|"calls real API endpoints"| RealAPI

    FakeStub -->|"forwards requests to"| FakeAPI
    FakeStub -->|"returns stubbed response"| AppLogic
    RealAPI -->|"returns real response"| AppLogic

    Config -->|"provides env vars"| Vite
    Config -->|"provides env vars"| AppLogic

    Vite -->|"builds for production"| Build

    %% Click Events
    click UI "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/index.html"
    click Styles "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/public/style.css"
    click AppLogic "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/main.js"
    click FakeStub "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/fake_backend.js"
    click Vite "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/vite.config.js"
    click Config "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/.env.example"
    click Meta "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/package.json"
    click Docs "https://github.com/incode-technologies-example-repos/onboarding-core-javascript/blob/main/README.md"

    %% Styles
    classDef client fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef server fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20;
    classDef config fill:#e0e0e0,stroke:#424242,color:#424242;
    classDef external fill:#dcedc8,stroke:#33691e,color:#33691e;
```
