# vedanshiprajapati/verbly architecture

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

- Interactive diagram: https://gitdiagram.com/vedanshiprajapati/verbly
- Repository: https://github.com/vedanshiprajapati/verbly

## Overview

##### Main System Components
a. Frontend (React + Vite):
- Single‑Page Application (SPA) in TypeScript
- UI layer (components/ui), rich‑text editor (components/plate‑ui)
- API client modules (src/api/blog.ts, user.ts)
- Routing (routes.tsx, ProtectedRoute wrappers)
- Context providers (AuthContext, ThemeProvider)
b. Backend (Node + Cloudflare Worker + Express‑style routes):
- Entry: src/index.ts, wrapped by Wrangler for CF Workers
- Authentication middleware (auth.ts)
- REST routes: /user, /post
- Business logic using Prisma client (schema.prisma, migrations)
- Utility: passwordEncryption
c. Database (PostgreSQL/MySQL or equivalent):
- Prisma ORM layer, migrations folder
d. Shared Library (“common” package):
- Type definitions (common/src/types.ts) used by both frontend and backend to share DTOs and interfaces
e. External Services (if any):
- Cloudflare Workers (deployed via wrangler.toml)
- Package registry (npm)

##### Relationships & Data Flows
- Browser → Frontend SPA: Served either locally (Vite dev) or statically (production build).
- Frontend → Backend API: HTTP(S) calls to Cloudflare Worker endpoints (e.g., GET /post, POST /post).
- Backend → Database: Prisma client issues SQL queries to the relational database.
- Shared common/types: Both frontend and backend import the common package to enforce consistent data contracts.

##### Architectural Patterns & Design Principles
- Layered Architecture: UI Layer → API Layer → Data Layer
- Shared Type Contracts: Ensures type safety across client and server
- Serverless Functions: Backend hosted as Cloudflare Workers for horizontal scaling
- RESTful Routing + Middleware for Auth & Validation

##### Relevant Technologies & Libraries
- Frontend: React, TypeScript, Vite, Tailwind CSS, @udecode/plate (rich‑text editor), React Context
- Backend: Node.js, TypeScript, Express‑style routing, Cloudflare Workers (Wrangler), Prisma ORM
- Common: npm package, TypeScript types

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User's Browser"]:::external

    %% Shared Types
    Shared["Shared Types (common)"]:::shared

    %% Frontend
    subgraph "Frontend SPA" 
        direction TB
        FE_Entry["Entry Point: main.tsx, App.tsx"]:::frontend
        FE_UI["UI Layer (components/ui)"]:::frontend
        FE_Editor["Rich-Text Editor (components/plate-ui)"]:::frontend
        FE_API["API Clients (blog.ts, user.ts)"]:::frontend
        FE_Routing["Routing & Guards (routes.tsx, ProtectedRoute)"]:::frontend
        FE_Context["Context Providers (AuthContext, ThemeProvider)"]:::frontend
    end

    %% Backend
    subgraph "Backend API (Cloudflare Worker)" 
        direction TB
        BE_Entry["Entry & Deployment (index.ts, wrangler.toml)"]:::server
        BE_Auth["Auth Middleware (auth.ts)"]:::server
        BE_Routes["REST Handlers (user.ts, post.ts)"]:::server
        BE_Utils["Utilities (passwordEncryption.ts)"]:::server
        BE_DBClient["Prisma Client"]:::server
        BE_Schema["Prisma Schema & Migrations"]:::data
    end

    %% Database
    DB["Relational Database"]:::data

    %% Connections
    User -->|"loads SPA via HTTPS"| FE_Entry
    FE_Entry --> FE_UI
    FE_UI --> FE_Editor
    FE_UI --> FE_Routing
    FE_Routing --> FE_API
    FE_API -->|"HTTP JSON over HTTPS"| BE_Routes
    FE_Context --> FE_UI
    FE_Context --> FE_Routing

    FE_API --> Shared
    BE_Routes --> Shared
    BE_Entry --> BE_Auth
    BE_Auth --> BE_Routes
    BE_Routes --> BE_Utils
    BE_Routes --> BE_DBClient
    BE_DBClient -->|"Prisma ORM → SQL"| DB
    BE_Schema --> BE_DBClient

    %% Shared Types link
    Shared -.-> FE_Entry
    Shared -.-> BE_Entry

    %% Click Events
    click FE_Entry "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/main.tsx"
    click FE_Entry "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/App.tsx"
    click FE_UI "https://github.com/vedanshiprajapati/verbly/tree/main/frontend/src/components/ui"
    click FE_Editor "https://github.com/vedanshiprajapati/verbly/tree/main/frontend/src/components/plate-ui"
    click FE_API "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/api/blog.ts"
    click FE_API "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/api/user.ts"
    click FE_Routing "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/routes.tsx"
    click FE_Routing "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/components/Reusables/ProtectedRoute.tsx"
    click FE_Routing "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/components/Reusables/UserProtectedRoute.tsx"
    click FE_Context "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/components/context/AuthContext.tsx"
    click FE_Context "https://github.com/vedanshiprajapati/verbly/blob/main/frontend/src/components/context/ThemeProvider.tsx"
    click BE_Entry "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/src/index.ts"
    click BE_Entry "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/wrangler.toml"
    click BE_Auth "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/src/middlewares/auth.ts"
    click BE_Routes "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/src/routes/user.ts"
    click BE_Routes "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/src/routes/post.ts"
    click BE_Utils "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/src/utils/passwordEncryption.ts"
    click BE_Schema "https://github.com/vedanshiprajapati/verbly/blob/main/Backend/prisma/schema.prisma"
    click BE_Schema "https://github.com/vedanshiprajapati/verbly/tree/main/Backend/prisma/migrations/"
    click Shared "https://github.com/vedanshiprajapati/verbly/blob/main/common/src/types.ts"
    click Shared "https://github.com/vedanshiprajapati/verbly/blob/main/common/dist/types.d.ts"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef server fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef data fill:#FFE0B2,stroke:#F57C00,stroke-width:1px
    classDef shared fill:#EEEEEE,stroke:#9E9E9E,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000000,stroke-dasharray: 2 2
```
