# zqq-nuli/cloudflare-navihive architecture

> Architecture diagram of the GitHub repository zqq-nuli/cloudflare-navihive, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zqq-nuli/cloudflare-navihive
- Repository: https://github.com/zqq-nuli/cloudflare-navihive

## Overview

##### Project Overview & Components
- Project Type: This is a full-stack web application. The frontend is built using React, TypeScript, Material UI, and Vite, while the backend runs on Cloudflare Workers and utilizes Cloudflare D1 (SQLite) for data storage. The addition of JWT-based authentication and drag-and-drop capabilities (via DND Kit) are key features.
- Main Components:
- Frontend: Includes all the React code (found under the “src” folder with components, API client implementations, and styling files) and static assets (located in “public”).
- Backend: Implemented as Cloudflare Worker functions (found under “worker” and configured via “wrangler.jsonc”) which provide APIs to the frontend.
- Database: Cloudflare D1 database (initialized via “init_table.sql” and configured in the wrangler config) consisting of “groups”, “sites”, and “configs” tables.
- Deployment & Configuration: The project uses Cloudflare Workers for hosting, with deployment instructions in the README and configuration files (like “wrangler.template.jsonc”, various “tsconfig” files, and “vite.config.ts”).

##### Relationship and Interactions
- User Interaction Flow:
- A user accesses the frontend (index.html loaded from the “public” folder or served via the React app).
- The React app (in “src/App.tsx” and components) handles UI interactions such as logging in (using the LoginForm component) and managing website groups and cards.
- API calls are made using the client code in the “src/API” directory. These calls are directed to the Cloudflare Worker’s endpoints implemented in “worker/index.ts”.
- The Worker interacts with the Cloudflare D1 database – executing SQL commands for CRUD operations on groups, sites, and configuration data.
- All data exchange, authentication (JWT), and any data transformation (during login, drag-and-drop sorting, etc.) are managed by these defined interfaces.

##### Architectural Patterns and Details
- Separation of Concerns: There is a clear division between frontend and backend processes. The API layer in “src/API” abstracts the details of HTTP requests, while the Cloudflare Worker acts as a serverless API endpoint.
- Authentication: JWT authentication is implemented for user access control. Ensure this is highlighted by indicating the “login” pathway from frontend to backend with secure handling of credentials.
- Service-Oriented Approach: The use of Cloudflare Workers emphasizes a serverless architecture where endpoints directly service requisitions as functions.
- Extensibility & Modular Design: The React components are modular (as seen in “src/components”), and the API communication logic is abstracted and reusable across the application.

##### Technologies and Integration Points
- Frontend Technologies: React 19, TypeScript, Material UI 7.0, Tailwind CSS, and Vite 6.
- Backend/Cloud Infrastructure: Cloudflare Workers (with a specific entry point in “worker/index.ts”), Cloudflare D1 database integrated through Wrangler, and associated configuration files (wrangler.jsonc, worker-configuration.d.ts).
- Data Flow & API: Components in the “src/API” folder (client.ts, http.ts, mock.ts) provide a layer of abstraction for HTTP calls between the frontend and worker.
- Build & Dependency Management: The project uses pnpm for package management and Vite for bundling and development serving.

- An element for “Authentication” showing the login process and JWT token generation/validation.
- Configuration steps taken at deployment (like Cloudflare deployment and D1 database initialization) as ancillary but essential tasks in setting up the environment.

##### Final Inclusions
- External dependencies such as Cloudflare (both Workers and D1) and any external libraries used in the frontend.
- You may also include annotations for deployment steps or initialization (such as a note about running SQL commands from “init_table.sql” for database setup).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    U("User"):::user

    %% Frontend Section
    subgraph "Frontend"
        FE1("React App (src/App.tsx)"):::frontend
        FE2("LoginForm (src/components/LoginForm.tsx)"):::frontend
        FE3("API Client (src/API)"):::frontend
        FE4("Public Assets (public)"):::frontend
    end

    %% Backend Section
    subgraph "Backend"
        BE1("Cloudflare Worker (worker/index.ts)"):::backend
        BE2("JWT Auth & API Endpoints"):::backend
    end

    %% Database Section
    subgraph "Database"
        DB1("Cloudflare D1 Database<br/>(tables: groups, sites, configs)"):::database
    end

    %% Deployment & Configuration Section
    subgraph "Deployment & Configuration"
        DC1("Workers Config (wrangler.template.jsonc)"):::config
        DC2("Worker Types (worker-configuration.d.ts)"):::config
        DC3("Worker TS Config (tsconfig.worker.json)"):::config
        DC4("Vite Config (vite.config.ts)"):::config
        DC5("DB Init Script (init_table.sql)"):::config
    end

    %% Connections and Data Flow
    U -->|"accesses"| FE1
    FE1 -->|"renders"| FE2
    FE1 -->|"uses"| FE3
    FE1 -->|"delivers"| FE4
    FE3 -->|"calls_API"| BE2
    BE2 -->|"delegates_to"| BE1
    BE1 -->|"queries_updates"| DB1

    %% Deployment & Config Connections
    DC1 -->|"configures"| BE1
    DC2 -->|"provides_types_for"| BE1
    DC3 -->|"sets_TS_config_for"| BE1
    DC4 -->|"builds"| FE1
    DC5 -->|"initializes"| DB1

    %% Click Events
    click FE1 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/src/App.tsx"
    click FE2 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/src/components/LoginForm.tsx"
    click FE3 "https://github.com/zqq-nuli/cloudflare-navihive/tree/main/src/API"
    click BE1 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/worker/index.ts"
    click DC1 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/wrangler.template.jsonc"
    click DC2 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/worker-configuration.d.ts"
    click DC3 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/tsconfig.worker.json"
    click DC4 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/vite.config.ts"
    click DC5 "https://github.com/zqq-nuli/cloudflare-navihive/blob/main/init_table.sql"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef config fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef user fill:#85C1E9,stroke:#1B4F72,stroke-width:2px;
```
