# jakbor32/privnote architecture

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

- Interactive diagram: https://gitdiagram.com/jakbor32/privnote
- Repository: https://github.com/jakbor32/privnote

## Overview

Based on our analysis of the file tree and the README content, the PrivNote project is a secure, client-side application built using React and TypeScript. It primarily focuses on enabling users to create encrypted, self-destructing notes – and now also supports secure file hosting. The encryption and decryption processes all occur in the browser using AES-256 (via crypto-js), and Supabase is used for storage and possibly other backend functions (like JWT validation for file access).

##### Main Components
- Frontend Application: This is built with React and TypeScript and includes all components under the src directory. It handles UI rendering, note creation, encryption, decryption, and secure file uploads.
- Encryption/Decryption Engine: Represented as a dedicated module (using crypto-js) that encrypts notes client-side before storage and decrypts them on retrieval. This logic is embedded in various components like CreateNote and OpenNote.
- Storage & Supabase Service: Supabase acts as the backend storage for encrypted notes and uploaded files. Include any API or configuration modules (see src/utils/supabaseConfig.ts) that indicate how the app interacts with Supabase. This section should also cover the JWT-based secure file hosting.
- External Services / Infrastructure: Even though most processes are client-side, mention any hosting platforms (like Vercel for deployment) since they are defined in configuration files (like vercel.json).

##### Relationships and Data Flow
- Encryption Module: Show how raw note content flows into the encryption routine (in the browser) and becomes an encrypted string. Emphasize that the encryption key remains client-side and is appended to the URL fragment.
- Retrieval & Decryption: Indicate that when a recipient accesses a note (using a URL with an appended key), the app retrieves the encrypted note from Supabase, then performs client-side decryption to display the content.
- Extensions for Secure File Hosting: Detail the flow where file uploads (with a size up to 50MB) go through a secure file upload flow – utilize functions in the UploadToStorage module, which handle file input, uploading, token generation, and secure link generation.

##### Architectural Patterns/Design Principles
- Component-Based Architecture: Clearly defined React components are split into directories such as CreateNote, OpenNote, and NoteSettings, each handling a discrete part of functionality.
- Layered Architecture: Represent how presentation (React components), business logic (encryption and file handling routines), and data access (Supabase interactions) are layered.

##### Relevant Technologies & Frameworks
- React & TypeScript for UI and component logic.
- Vite as the build tool (inferred from vite.config.ts and vite-env.d.ts).
- Tailwind CSS for styling, with configurations in tailwind.config.js.
- Crypto-js for AES-256 encryption.
- Supabase for backend data storage and file hosting.
- Deployment artifacts like vercel.json indicate a Vercel-hosted platform.

##### Specific Elements
- Each major component (Frontend App, Encryption Engine, Supabase Storage, File Hosting Service).
- Data flows: User input → Encryption → Supabase storage and back (with decryption).
- "User Interface" (with detailed components like CreateNote, OpenNote, UploadToStorage) and "Encryption Engine".
- "Encryption Engine" to "Supabase Storage".
- "Supabase Storage" back to "UI" during note retrieval, followed by "Decryption Process".
- "File Upload Service" depicting JWT-token generation and secure file hosting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::user

    F["Frontend Application"]:::frontend
    subgraph "UI Components"
        FN1["Create Note (UI)"]:::ui
        FN2["Open Note (UI)"]:::ui
        FN3["Common UI Elements"]:::ui
        FN4["Note Settings"]:::ui
    end

    subgraph "Encryption & Business Logic"
        EN1["CreateNote Encryption"]:::logic
        EN2["OpenNote Decryption"]:::logic
        CT["Crypto‑js Types"]:::logic
        SFA["Secure File Upload Handler"]:::logic
        FUP["File Upload Components"]:::logic
    end

    subgraph "Backend Storage"
        SS["Supabase Storage"]:::storage
    end

    ES["Vercel Deployment"]:::external

    U -->|"input"| F
    F -->|"triggers"| FN1
    F -->|"triggers"| FN2
    F --> FN3
    F --> FN4

    FN1 -->|"encryptsNote"| EN1
    FN2 -->|"decryptsNote"| EN2
    FN1 -->|"handlesFileUpload"| SFA
    SFA -->|"initiatesUpload"| FUP
    SFA -->|"storesFile"| SS
    EN1 -->|"storesNote"| SS
    SS -->|"retrievesNote"| EN2

    F -->|"hostedOn"| ES

    click F "https://github.com/jakbor32/privnote/tree/main/src/"
    click FN1 "https://github.com/jakbor32/privnote/tree/main/src/components/CreateNote/"
    click FN2 "https://github.com/jakbor32/privnote/tree/main/src/components/OpenNote/"
    click FN3 "https://github.com/jakbor32/privnote/tree/main/src/components/common/"
    click FN4 "https://github.com/jakbor32/privnote/tree/main/src/components/NoteSettings/"
    click EN1 "https://github.com/jakbor32/privnote/blob/main/src/components/CreateNote/CreateNote.tsx"
    click EN2 "https://github.com/jakbor32/privnote/blob/main/src/components/OpenNote/OpenNote.tsx"
    click CT "https://github.com/jakbor32/privnote/blob/main/src/types/crypto-js.d.ts"
    click SFA "https://github.com/jakbor32/privnote/blob/main/src/components/CreateNote/UploadToStorage.tsx"
    click FUP "https://github.com/jakbor32/privnote/tree/main/src/components/UploadToStorage/"
    click SS "https://github.com/jakbor32/privnote/blob/main/src/utils/supabaseConfig.ts"
    click ES "https://github.com/jakbor32/privnote/blob/main/vercel.json"

    classDef user fill:#ffcccc,stroke:#b30000,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef ui fill:#e2e2e2,stroke:#666666,stroke-width:1px;
    classDef logic fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef storage fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
