# surakal/nationalidconvertor-2 architecture

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

- Interactive diagram: https://gitdiagram.com/surakal/nationalidconvertor-2
- Repository: https://github.com/surakal/nationalidconvertor-2

## Overview

1. **Overall shape**
   - This is a **client-side React application** built with **Vite + TypeScript**, with **Supabase** providing the backend services.
   - The repo is organized as a typical single-page app: route-level pages in `src/pages`, shared feature components in `src/components`, app-wide state in `src/contexts`, and backend/schema code under `supabase/`.

2. **Route and page layer**
   - The main user-facing entry points are `Index`, `Login`, `Register`, `ForgotPassword`, `Dashboard`, `Admin`, and `NotFound`.
   - That implies two major navigation zones:
     - a **public/auth zone** for onboarding and password recovery
     - an **authenticated application zone** for dashboard and admin workflows

3. **Authentication boundary**
   - `src/contexts/AuthContext.tsx` is the main app-level auth boundary.
   - It likely owns session state, user identity, and protected-route behavior, and it is the point where the frontend connects to Supabase auth.
   - Password reset and account creation are not purely client-side: they are backed by Supabase edge functions.

4. **Business feature modules**
   - The feature components suggest the app is centered on **identity/document processing and account operations**:
     - `IDUploader`, `PrintableID`, `ResultsPanel`
     - `WalletTopUp`, `PaymentMethods`, `PaymentRequests`
     - `PackageManagement`
   - These are separate feature areas rather than generic UI, so they likely map to distinct dashboard tabs/cards and backend entities.

5. **OCR/document-processing flow**
   - `src/lib/ocr.ts` and `src/lib/ocr-v1.ts` indicate a dedicated OCR layer with at least one versioned implementation.
   - `IDUploader` is the entry point for document input; OCR runs in the client-side library layer; the extracted results are then displayed through `ResultsPanel` and likely used to populate a printable identity view.
   - This is a key architecture boundary: **user uploads → OCR processing → structured results → downstream profile/ID rendering**.

6. **Payments and wallet subsystem**
   - `WalletTopUp`, `PaymentMethods`, and `PaymentRequests` form a focused payment/workflow area.
   - The naming suggests the UI supports funding a wallet, selecting payment rails, and handling incoming/outgoing payment requests.
   - In diagram terms, this is a distinct business subsystem that likely persists transactional state in Supabase tables.

7. **Admin subsystem**
   - `src/pages/Admin.tsx` plus `src/components/admin/AdminSidebar.tsx` and `AdminUsers.tsx` define a separate administrative surface.
   - This area is isolated from normal dashboard usage and likely depends on role-based access control from Supabase/auth claims and database policies.
   - The admin side appears focused on user management rather than general content editing.

8. **Supabase backend layer**
   - `src/integrations/supabase/client.ts` and `types.ts` are the frontend’s typed access layer to Supabase.
   - The `supabase/migration/*.sql` files show that schema and policy changes are versioned in the repo, so the database is part of the source of truth.
   - This likely includes auth-related tables, application records, and access control rules.

9. **Serverless backend functions**
   - `supabase/functions/create-user` and `supabase/functions/reset-password-otp` are backend execution boundaries outside the browser.
   - These functions handle privileged workflows that should not be done directly from the client:
     - user provisioning
     - password reset / OTP handling
   - In the architecture diagram, they sit alongside Supabase auth and database services, not inside the React app.

10. **UI system and design layer**
   - The app uses a large `src/components/ui` library, which is characteristic of **shadcn/ui** style composition.
   - This means the product UI is assembled from reusable primitives like dialogs, tables, tabs, forms, sidebars, etc., rather than a custom design system built from scratch.
   - `tailwind.config.ts`, `src/index.css`, and `src/App.css` provide the styling layer.

11. **State, responsiveness, and cross-cutting utilities**
   - `use-toast`, `sonner`, and the toast components indicate a global notification mechanism for async feedback.
   - `use-mobile.tsx` suggests responsive behavior is handled in app code, not only via CSS.
   - `src/lib/utils.ts` is the shared helper layer for component composition and formatting.

12. **Build, testing, and delivery**
   - The project is built and served by **Vite**, tested with **Vitest**, and linted with ESLint.
   - `public/robots.txt` and `public/images` are static assets served directly by the frontend bundle.
   - The README describes Lovable-based editing and deployment, but the actual runtime architecture remains a static SPA plus Supabase backend.

13. **How data flows through the system**
   - Typical flow is: **user/browser → React page/component → auth context / feature UI → Supabase client or edge function → Supabase database/auth → UI updates and notifications**.
   - OCR and document generation stay primarily on the client side, while authentication, account creation, reset flows, user management, and persistent business data go through Supabase.

14. **Key diagram boundaries to draw**
   - Draw separate boxes for:
     - **Frontend SPA**
     - **Auth/session management**
     - **OCR/document processing**
     - **Payments/wallet business logic**
     - **Admin console**
     - **Supabase auth + database**
     - **Supabase edge functions**
   - The most important boundary is between the **browser-based React app** and the **Supabase backend services**, with OCR as a client-side processing subflow.

Main entry points: [`src/App.tsx`](https://github.com/surakal/nationalidconvertor-2/blob/main/src/App.tsx) (App Shell), [`src/pages/Dashboard.tsx`](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Dashboard.tsx) (Dashboard), [`src/integrations/supabase/client.ts`](https://github.com/surakal/nationalidconvertor-2/blob/main/src/integrations/supabase/client.ts) (Supabase Client), [`src/pages/Register.tsx`](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Register.tsx) (Register)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_main(("Entry<br/>vite bootstrap<br/>[main.tsx]"))
  node_app["App Shell<br/>router shell<br/>[App.tsx]"]
  node_auth{{"Auth State<br/>context<br/>[AuthContext.tsx]"}}
  node_index["Home<br/>public page<br/>[Index.tsx]"]
  node_login["Login<br/>auth page<br/>[Login.tsx]"]
  node_register["Register<br/>auth page<br/>[Register.tsx]"]
  node_forgot["Recover<br/>auth page<br/>[ForgotPassword.tsx]"]
  node_dashboard["Dashboard<br/>app page<br/>[Dashboard.tsx]"]
  node_admin["Admin<br/>[Admin.tsx]"]
  node_notfound["Not Found<br/>error page<br/>[NotFound.tsx]"]
  node_idupload["ID Upload<br/>document input<br/>[IDUploader.tsx]"]
  node_ocr{{"OCR Engine<br/>client processing<br/>[ocr.ts]"}}
  node_results["Results<br/>extraction view<br/>[ResultsPanel.tsx]"]
  node_printable["Printable ID<br/>rendering view<br/>[PrintableID.tsx]"]
  node_wallet["Wallet Top-Up<br/>payments workflow<br/>[WalletTopUp.tsx]"]
  node_methods["Payment Methods<br/>payments workflow<br/>[PaymentMethods.tsx]"]
  node_requests["Payment Requests<br/>payments workflow"]
  node_packages["Packages<br/>account workflow"]
  node_adminside["Admin Sidebar<br/>admin navigation<br/>[AdminSidebar.tsx]"]
  node_adminusers["User Admin<br/>admin management<br/>[AdminUsers.tsx]"]
  node_uikit["UI Primitives<br/>design system"]
end

subgraph group_backend["Supabase Backend"]
  node_supaclient{{"Supabase Client<br/>data access<br/>[client.ts]"}}
  node_supacore[("Supabase Core<br/>auth/db service")]
  node_schema["Schema & Policies<br/>db migrations"]
  node_functions["Edge Functions<br/>serverless functions"]
  node_createuser["Create User<br/>provisioning function<br/>[index.ts]"]
  node_resetotp["Reset OTP<br/>recovery function<br/>[index.ts]"]
end

node_main -->|"bootstraps"| node_app
node_app -->|"wraps"| node_auth
node_app -->|"routes"| node_index
node_app -->|"routes"| node_login
node_app -->|"routes"| node_register
node_app -->|"routes"| node_forgot
node_app -->|"routes"| node_dashboard
node_app -->|"routes"| node_admin
node_app -->|"fallback"| node_notfound
node_dashboard -->|"uses"| node_idupload
node_idupload -->|"processes"| node_ocr
node_ocr -->|"feeds"| node_results
node_ocr -->|"feeds"| node_printable
node_dashboard -->|"uses"| node_wallet
node_dashboard -->|"uses"| node_methods
node_dashboard -->|"uses"| node_requests
node_dashboard -->|"uses"| node_packages
node_admin -->|"contains"| node_adminside
node_admin -->|"contains"| node_adminusers
node_login -->|"auth"| node_supaclient
node_register -->|"auth"| node_supaclient
node_forgot -->|"calls"| node_resetotp
node_register -->|"calls"| node_createuser
node_auth -->|"reads session"| node_supaclient
node_supaclient -->|"connects"| node_supacore
node_supacore -->|"governed by"| node_schema
node_functions -.->|"runs beside"| node_supacore
node_createuser -->|"provisions"| node_supacore
node_resetotp -->|"recovery"| node_supacore
node_uikit -->|"supports"| node_app

click node_main "https://github.com/surakal/nationalidconvertor-2/blob/main/src/main.tsx"
click node_app "https://github.com/surakal/nationalidconvertor-2/blob/main/src/App.tsx"
click node_auth "https://github.com/surakal/nationalidconvertor-2/blob/main/src/contexts/AuthContext.tsx"
click node_index "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Index.tsx"
click node_login "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Login.tsx"
click node_register "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Register.tsx"
click node_forgot "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/ForgotPassword.tsx"
click node_dashboard "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Dashboard.tsx"
click node_admin "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Admin.tsx"
click node_notfound "https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/NotFound.tsx"
click node_idupload "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/IDUploader.tsx"
click node_ocr "https://github.com/surakal/nationalidconvertor-2/blob/main/src/lib/ocr.ts"
click node_results "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/ResultsPanel.tsx"
click node_printable "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PrintableID.tsx"
click node_wallet "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/WalletTopUp.tsx"
click node_methods "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PaymentMethods.tsx"
click node_requests "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PaymentRequests.tsx"
click node_packages "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PackageManagement.tsx"
click node_adminside "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/admin/AdminSidebar.tsx"
click node_adminusers "https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/admin/AdminUsers.tsx"
click node_supaclient "https://github.com/surakal/nationalidconvertor-2/blob/main/src/integrations/supabase/client.ts"
click node_schema "https://github.com/surakal/nationalidconvertor-2/tree/main/supabase/migration"
click node_functions "https://github.com/surakal/nationalidconvertor-2/tree/main/supabase/functions"
click node_createuser "https://github.com/surakal/nationalidconvertor-2/blob/main/supabase/functions/create-user/index.ts"
click node_resetotp "https://github.com/surakal/nationalidconvertor-2/blob/main/supabase/functions/reset-password-otp/index.ts"

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,node_app,node_auth,node_index,node_login,node_register,node_forgot,node_dashboard,node_admin,node_notfound,node_idupload,node_ocr,node_results,node_printable,node_wallet,node_methods,node_requests,node_packages,node_adminside,node_adminusers,node_uikit toneBlue
class node_supaclient,node_supacore,node_schema,node_functions,node_createuser,node_resetotp toneAmber
```

## Components

### Frontend SPA

React client, route pages, shared UI, and browser-side processing.

- [Entry](https://github.com/surakal/nationalidconvertor-2/blob/main/src/main.tsx): vite bootstrap · Browser entry that mounts the React app. · `src/main.tsx`
- [App Shell](https://github.com/surakal/nationalidconvertor-2/blob/main/src/App.tsx): router shell · Top-level routing and application composition. · `src/App.tsx`
- [Auth State](https://github.com/surakal/nationalidconvertor-2/blob/main/src/contexts/AuthContext.tsx): context · Session and identity boundary for protected flows. · `src/contexts/AuthContext.tsx`
- [Home](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Index.tsx): public page · Landing or entry page for the public zone. · `src/pages/Index.tsx`
- [Login](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Login.tsx): auth page · Sign-in entry point. · `src/pages/Login.tsx`
- [Register](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Register.tsx): auth page · Account creation entry point. · `src/pages/Register.tsx`
- [Recover](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/ForgotPassword.tsx): auth page · Password reset and recovery entry point. · `src/pages/ForgotPassword.tsx`
- [Dashboard](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Dashboard.tsx): app page · Authenticated workspace for core product workflows. · `src/pages/Dashboard.tsx`
- [Admin](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/Admin.tsx): admin page · Restricted administrative surface. · `src/pages/Admin.tsx`
- [Not Found](https://github.com/surakal/nationalidconvertor-2/blob/main/src/pages/NotFound.tsx): error page · Fallback route for unknown paths. · `src/pages/NotFound.tsx`
- [ID Upload](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/IDUploader.tsx): document input · Captures identity document images for processing. · `src/components/IDUploader.tsx`
- [OCR Engine](https://github.com/surakal/nationalidconvertor-2/blob/main/src/lib/ocr.ts): client processing · Client-side OCR and extraction logic. · `src/lib/ocr.ts`
- [Results](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/ResultsPanel.tsx): extraction view · Displays OCR output and structured data. · `src/components/ResultsPanel.tsx`
- [Printable ID](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PrintableID.tsx): rendering view · Formats extracted identity data for printable output. · `src/components/PrintableID.tsx`
- [Wallet Top-Up](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/WalletTopUp.tsx): payments workflow · Funds wallet balance and payment activity. · `src/components/WalletTopUp.tsx`
- [Payment Methods](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PaymentMethods.tsx): payments workflow · Selects or manages payment rails. · `src/components/PaymentMethods.tsx`
- [Payment Requests](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PaymentRequests.tsx): payments workflow · Tracks incoming and outgoing payment requests. · `src/components/PaymentRequests.tsx`
- [Packages](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/PackageManagement.tsx): account workflow · Manages package or service bundles. · `src/components/PackageManagement.tsx`
- [Admin Sidebar](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/admin/AdminSidebar.tsx): admin navigation · Navigation and layout for the admin console. · `src/components/admin/AdminSidebar.tsx`
- [User Admin](https://github.com/surakal/nationalidconvertor-2/blob/main/src/components/admin/AdminUsers.tsx): admin management · Administrative user management surface. · `src/components/admin/AdminUsers.tsx`
- **UI Primitives**: design system · Reusable component library for the app UI.

### Supabase Backend

Auth, database schema, and privileged serverless workflows.

- [Supabase Client](https://github.com/surakal/nationalidconvertor-2/blob/main/src/integrations/supabase/client.ts): data access · Typed frontend client for Supabase services. · `src/integrations/supabase/client.ts`
- **Supabase Core**: auth/db service · Hosted auth and database services behind the frontend.
- [Schema & Policies](https://github.com/surakal/nationalidconvertor-2/tree/main/supabase/migration): db migrations · Versioned database schema and access policy definitions. · `supabase/migration`
- [Edge Functions](https://github.com/surakal/nationalidconvertor-2/tree/main/supabase/functions): serverless functions · Privileged backend workflows executed outside the browser. · `supabase/functions`
- [Create User](https://github.com/surakal/nationalidconvertor-2/blob/main/supabase/functions/create-user/index.ts): provisioning function · Provisions users through a privileged backend path. · `supabase/functions/create-user/index.ts`
- [Reset OTP](https://github.com/surakal/nationalidconvertor-2/blob/main/supabase/functions/reset-password-otp/index.ts): recovery function · Handles password reset and OTP workflows. · `supabase/functions/reset-password-otp/index.ts`

## Connections

- Entry → App Shell: bootstraps · Mounts the application shell.
- App Shell → Auth State: wraps · Provides session and protection context.
- App Shell → Home: routes · Public landing route.
- App Shell → Login: routes · Authentication route.
- App Shell → Register: routes · Account creation route.
- App Shell → Recover: routes · Password recovery route.
- App Shell → Dashboard: routes · Authenticated application route.
- App Shell → Admin: routes · Restricted admin route.
- App Shell → Not Found: fallback · Unknown route handler.
- Dashboard → ID Upload: uses · Starts document capture flow.
- ID Upload → OCR Engine: processes · Runs OCR on uploaded identity documents.
- OCR Engine → Results: feeds · Produces structured extraction output.
- OCR Engine → Printable ID: feeds · Supplies data for printable ID rendering.
- Dashboard → Wallet Top-Up: uses · Exposes wallet top-up workflow.
- Dashboard → Payment Methods: uses · Exposes payment method management.
- Dashboard → Payment Requests: uses · Exposes payment request workflow.
- Dashboard → Packages: uses · Exposes package management workflow.
- Admin → Admin Sidebar: contains · Admin navigation and layout.
- Admin → User Admin: contains · User management surface.
- Login → Supabase Client: auth · Signs users in through Supabase.
- Register → Supabase Client: auth · Creates accounts through Supabase.
- Recover → Reset OTP: calls · Invokes privileged recovery flow.
- Register → Create User: calls · Invokes privileged provisioning flow.
- Auth State → Supabase Client: reads session · Keeps app state aligned with Supabase auth.
- Supabase Client → Supabase Core: connects · Frontend access to hosted Supabase services.
- Supabase Core → Schema & Policies: governed by · Database behavior defined by migrations and policies.
- Edge Functions → Supabase Core: runs beside · Serverless execution boundary adjacent to core services.
- Create User → Supabase Core: provisions · Creates or updates backend user records.
- Reset OTP → Supabase Core: recovery · Coordinates password reset and OTP state.
- UI Primitives → App Shell: supports · Shared component primitives used across the SPA.
