# zamorzgar/image-security-verification architecture

> Architecture diagram of the GitHub repository zamorzgar/image-security-verification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zamorzgar/image-security-verification
- Repository: https://github.com/zamorzgar/image-security-verification

## Overview

- Frontend (Client Application):
- Represented by the Next.js application in the “app” directory (pages for login, register, dashboard, image upload, and verification).
- Components such as the “app/dashboard”, “app/login”, “app/register”, and “app/verify” directories indicate you have clearly separated UI flows.
- “components” folder that handles the UI elements (Shadcn UI integrated with Tailwind CSS).

- API/Server-side Endpoints:
- API routes under “app/api” indicate server-side logic handling authentication (e.g., routes for registering, profile, etc.).
- “app/actions” contain business logic for key generation, image signing, and verification that the API endpoints likely call.

- Cryptographic and Helper Libraries:
- The “lib” directory includes crypto utilities (crypto-utils.ts) and Supabase utilities for interacting with authentication, storage, and database operations.
- This layer handles the core security operations, such as RSA key pair generation, SHA-256 hashing, and signing.

- Backend Services (Supabase):
- Although not coded in this repository, Supabase is central to authentication, database storage (e.g., for public keys and image signatures), and file storage.
- The “supabase/migrations” folder shows SQL setup for the database, emphasizing RLS (Row Level Security) and storage tables.

- Deployment and Configuration:
- Files such as next.config.ts, tsconfig.json, package.json, and environment handling (via .env.local as mentioned in the README) are crucial for deployment environments like Vercel.

##### Relationships and Data Flows

- User Registration Flow:
- The user interface (UI pages in “app/register” and “app/login”) interacts with the backend API endpoints.
- Immediately after registration, the client triggers RSA key generation (using routines from “lib/crypto-utils.ts” and “app/actions/generate-initial-keys.ts”), storing the public key in Supabase (using “lib/supabase-utils.ts”).

- Image Upload and Signing Flow:
- A user selects an image via the frontend’s upload page (located in “app/dashboard/upload”).
- The system computes the image hash and uses the private key (which remains on the user's device) to sign the hash.
- The signed image along with its signature is then sent to Supabase storage as well as the respective database record.

- Image Verification Flow:
- The user accesses the verify page (e.g., “app/dashboard/verify” or “app/verify”).
- The client recalculates the image hash, then the system retrieves the originally stored signature and associated public key from Supabase.
- The verification routine (found under “app/actions/verify.ts”) then validates the signature.

##### Architectural Patterns & Design Principles

- Separation of Concerns:
- Clearly distinguish between UI components, server-side API routes, and helper libraries.
- The use of dedicated directories (like “actions”, “api”, “dashboard”, and “lib”) highlights the modular design.

- Security-Centric Design:
- Client-side cryptography ensures that the private keys never leave the device.
- Supabase’s secure storage of public keys and use of SQL migrations for setting up RLS rules should be clearly depicted.

- Use of Modern Web Frameworks:
- Supabase as a Backend-as-a-Service (BaaS) provides a managed database, authentication, and storage service.

- Data Flow & Dependencies:
- How the UI initiates requests, which are handled by backend API endpoints.
- How these endpoints leverage utility and crypto services.
- How data is persisted and retrieved in Supabase.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User"):::external

    subgraph "Frontend (Next.js UI)"
        F1("UI Pages (Login/Register/Dashboard/Verify)"):::frontend
        F2("UI Components"):::frontend
    end

    subgraph "API Layer"
        API("API Endpoints (app/api)"):::backend
    end

    subgraph "Business Logic"
        A("Action Handlers (app/actions)"):::actions
    end

    subgraph "Helper Libraries"
        C("Crypto Utilities (lib/crypto-utils.ts)"):::utilities
        S("Supabase Utilities (lib/supabase-utils.ts)"):::utilities
        SC("Supabase Client (lib/supabase)"):::utilities
    end

    subgraph "Supabase Backend"
        SB("Supabase Services (Database & Storage)"):::external
    end

    subgraph "Deployment & Config"
        D1("next.config.ts"):::config
        D2("tsconfig.json"):::config
        D3("package.json"):::config
    end

    U -->|"initiates"| F1
    F1 -->|"sends request"| API
    API -->|"invokes"| A
    A -->|"calls for RSA_Key/Sign"| C
    A -->|"performs Supabase Ops"| S
    S -->|"uses"| SC
    SC -->|"stores/retrieves"| SB
    API -->|"stores/retrieves keys"| SB
    A -->|"verifies signature"| SB
    SB -->|"returns response"| API

    classDef frontend fill:#a2d9ce,stroke:#000,stroke-width:2px;
    classDef backend fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef actions fill:#aed6f1,stroke:#000,stroke-width:2px;
    classDef utilities fill:#f5b7b1,stroke:#000,stroke-width:2px;
    classDef config fill:#d5f5e3,stroke:#000,stroke-width:2px;
    classDef external fill:#d6eaf8,stroke:#000,stroke-width:2px;

    click F1 "https://github.com/zamorzgar/image-security-verification/tree/main/app"
    click F2 "https://github.com/zamorzgar/image-security-verification/tree/main/components/ui"
    click API "https://github.com/zamorzgar/image-security-verification/tree/main/app/api"
    click A "https://github.com/zamorzgar/image-security-verification/tree/main/app/actions"
    click C "https://github.com/zamorzgar/image-security-verification/blob/main/lib/crypto-utils.ts"
    click S "https://github.com/zamorzgar/image-security-verification/blob/main/lib/supabase-utils.ts"
    click SC "https://github.com/zamorzgar/image-security-verification/tree/main/lib/supabase"
    click SB "https://github.com/zamorzgar/image-security-verification/tree/main/supabase/migrations"
    click D1 "https://github.com/zamorzgar/image-security-verification/blob/main/next.config.ts"
    click D2 "https://github.com/zamorzgar/image-security-verification/blob/main/tsconfig.json"
    click D3 "https://github.com/zamorzgar/image-security-verification/blob/main/package.json"
```
