How incode-technologies-example-repos/onboarding-core-javascript works
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.