# adilmunawar/adinox architecture

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

- Interactive diagram: https://gitdiagram.com/adilmunawar/adinox
- Repository: https://github.com/adilmunawar/adinox

## Overview

##### Project Type and Purpose
- AdiNox is a single-page, full-stack authenticator application built with React (TypeScript) on the front end and Supabase for user authentication and optional data storage.
- It generates TOTP/HOTP codes locally and optionally persists user session data or settings in Supabase.

##### File Structure
- Top-Level Directories
– public/: Static assets (images, favicon, robots.txt).
– src/: All application code.
- src/ Subdirectories
– components/: UI fragments (tokens list, UI primitives under ui/).
– context/: React Context Providers (AuthContext, TokenContext, ThemeContext).
– hooks/: Custom hooks (use-mobile, use-toast).
– integrations/supabase/: Supabase client setup & types.
– lib/utils.ts & utils/tokenUtils.ts: Business logic (TOTP/HOTP generation, QR parsing, encryption).
– pages/: Top-level pages (AuthPage, Index, NotFound).
– main.tsx & App.tsx: Application entry point and router.
- Configuration & Build
– vite.config.ts, tsconfig*.json, tailwind.config.ts, postcss.config.js
– supabase/config.toml: Supabase project schema & migration config.

##### README for Additional Insights
- Confirms TOTP/HOTP support, QR-scan/manual entry, secure local storage, and Supabase-backed user authentication.
- Emphasizes open source, privacy, and cross-platform compatibility.

##### Main System Components
a. Frontend (Browser / React SPA)
– UI Layer: pages → components/ui → components/tokens
– State Layer: React Contexts (AuthContext, TokenContext, ThemeContext)
– Business Logic: tokenUtils (TOTP/HOTP), utils.ts
– Environment & Build: Vite dev server, Tailwind CSS, TypeScript
b. External Service
– Supabase Auth & Database: user sign-up, sign-in, session management, optional metadata storage
c. Local Storage
– Secure storage of token secrets and user preferences (localStorage or IndexedDB, possibly encrypted by tokenUtils)
d. Optional Integrations
– QR-scanner library for secret provisioning
– Clipboard / Web Crypto APIs

##### Relationships & Interactions
- User interacts with Browser (UI) → React triggers Context actions.
- AuthContext calls supabase-js SDK → Supabase Auth HTTP API → returns session token.
- On successful auth, TokenContext reads/writes secrets to localStorage (via utils) → triggers UI update.
- tokenUtils reads current time or counter → generates OTP → UI displays codes.
- All build & deploy tasks handled via Vite and Supabase CLI (supabase/config.toml) if database migrations are used.

##### Architectural Patterns
- Component-based UI, Single-Page Application
- Context API for global state management (Auth, Tokens, Theme)
- Separation of concerns: UI vs. State vs. Business Logic (utils) vs. Integration
- External-as-a-Service: Supabase for auth, no custom backend server
- Build & deploy pipelines via Vite and supabase CLI

##### Final Checklist
- Containers/boundaries for client vs. external services.
- Notes on important frameworks/technologies: React, Vite, Tailwind, supabase-js, Web Crypto API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    User["End User"]:::external

    %% Browser / Client Boundary
    subgraph "Browser / Client"
        direction TB

        %% Entry & Routing
        subgraph "Entry Point & Routing"
            direction TB
            Main["main.tsx"]:::config
            App["App.tsx"]:::frontend
        end

        %% UI Layer
        subgraph "UI Layer"
            direction TB
            AuthPage["AuthPage"]:::frontend
            IndexPage["Index"]:::frontend
            NotFoundPage["NotFound"]:::frontend
            TokenList["TokenList"]:::frontend
            AddTokenForm["AddTokenForm"]:::frontend
            TokenCard["TokenCard"]:::frontend
            UIPrimitives["UI Primitives"]:::frontend
        end

        %% State Layer
        subgraph "State Layer"
            direction TB
            AuthContext["AuthContext"]:::context
            TokenContext["TokenContext"]:::context
            ThemeContext["ThemeContext"]:::context
        end

        %% Business Logic
        subgraph "Business Logic"
            direction TB
            UtilsLib["Utils (utils.ts)"]:::logic
            TokenUtils["TokenGenerator (tokenUtils.ts)"]:::logic
        end

        %% Custom Hooks
        subgraph "Custom Hooks"
            direction TB
            UseMobile["use-mobile"]:::hook
            UseToast["use-toast"]:::hook
        end

        %% Local Storage
        LocalStorage["LocalStorage / IndexedDB"]:::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Supabase["Supabase Auth & DB"]:::external
    end

    %% Connections
    User -->|uses| AuthPage
    User -->|browses| IndexPage

    Main --> App
    App --> AuthPage
    App --> IndexPage
    App --> NotFoundPage

    AuthPage -->|dispatch auth actions| AuthContext
    IndexPage -->|reads tokens| TokenContext
    AddTokenForm -->|add/delete token| TokenContext
    TokenList -->|display list| TokenContext
    TokenCard -->|show OTP| TokenUtils

    AuthContext -->|calls supabase.auth API| Supabase
    Supabase -->|returns session| AuthContext
    AuthContext -->|update state| TokenContext

    TokenContext -->|persist secrets| LocalStorage
    LocalStorage -->|load secrets| TokenContext

    TokenContext -->|provide tokens| TokenList
    TokenUtils -->|generate OTP| TokenCard
    TokenUtils -->|helper functions| UtilsLib

    UseMobile -->|responsive UI| UIPrimitives
    UseToast -->|notifications| UIPrimitives

    %% Click Events
    click AuthPage "https://github.com/adilmunawar/adinox/blob/main/src/pages/AuthPage.tsx"
    click IndexPage "https://github.com/adilmunawar/adinox/blob/main/src/pages/Index.tsx"
    click NotFoundPage "https://github.com/adilmunawar/adinox/blob/main/src/pages/NotFound.tsx"
    click TokenList "https://github.com/adilmunawar/adinox/blob/main/src/components/tokens/TokenList.tsx"
    click AddTokenForm "https://github.com/adilmunawar/adinox/blob/main/src/components/tokens/AddTokenForm.tsx"
    click TokenCard "https://github.com/adilmunawar/adinox/blob/main/src/components/tokens/TokenCard.tsx"
    click UIPrimitives "https://github.com/adilmunawar/adinox/tree/main/src/components/ui"
    click AuthContext "https://github.com/adilmunawar/adinox/blob/main/src/context/AuthContext.tsx"
    click TokenContext "https://github.com/adilmunawar/adinox/blob/main/src/context/TokenContext.tsx"
    click ThemeContext "https://github.com/adilmunawar/adinox/blob/main/src/context/ThemeContext.tsx"
    click UtilsLib "https://github.com/adilmunawar/adinox/blob/main/src/lib/utils.ts"
    click TokenUtils "https://github.com/adilmunawar/adinox/blob/main/src/utils/tokenUtils.ts"
    click UseMobile "https://github.com/adilmunawar/adinox/blob/main/src/hooks/use-mobile.tsx"
    click UseToast "https://github.com/adilmunawar/adinox/blob/main/src/hooks/use-toast.ts"
    click Supabase "https://github.com/adilmunawar/adinox/blob/main/src/integrations/supabase/client.ts"
    click Supabase "https://github.com/adilmunawar/adinox/blob/main/src/integrations/supabase/types.ts"
    click Main "https://github.com/adilmunawar/adinox/blob/main/src/main.tsx"
    click App "https://github.com/adilmunawar/adinox/blob/main/src/App.tsx"
    click LocalStorage "https://github.com/adilmunawar/adinox/blob/main/src/index.css"
    click LocalStorage "https://github.com/adilmunawar/adinox/blob/main/src/App.css"
    click Supabase "https://github.com/adilmunawar/adinox/blob/main/supabase/config.toml"
    click Main "https://github.com/adilmunawar/adinox/blob/main/vite.config.ts"
    click Main "https://github.com/adilmunawar/adinox/blob/main/tsconfig.json"
    click Main "https://github.com/adilmunawar/adinox/blob/main/tsconfig.app.json"
    click Main "https://github.com/adilmunawar/adinox/blob/main/tsconfig.node.json"
    click Main "https://github.com/adilmunawar/adinox/blob/main/tailwind.config.ts"
    click Main "https://github.com/adilmunawar/adinox/blob/main/postcss.config.js"

    %% Styles
    classDef frontend fill:#E8F5E9,stroke:#388E3C,color:#2E7D32
    classDef context fill:#E3F2FD,stroke:#1976D2,color:#0D47A1
    classDef logic fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef storage fill:#F3E5F5,stroke:#8E24AA,color:#6A1B9A
    classDef external fill:#ECEFF1,stroke:#546E7A,color:#37474F
    classDef hook fill:#FCE4EC,stroke:#D81B60,color:#880E4F
    classDef config fill:#FAFAFA,stroke:#B0BEC5,color:#455A64
```
