How zamorzgar/image-security-verification works
• 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.