# darshan98solanki/medium architecture

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

- Interactive diagram: https://gitdiagram.com/darshan98solanki/medium
- Repository: https://github.com/darshan98solanki/medium

## Overview

##### Project Type and Purpose
- This is a full-stack, Medium-style blogging platform (“TechLog”) with three key modules:
- Frontend: React + Tailwind CSS app hosted on Vercel
- Backend: Node.js + Hono REST API deployed as Cloudflare Worker
- Common: Shared utilities/constants used by both sides
- Purpose: Allow users to register/login, read, write, edit, delete, and explore articles.

##### File Structure Analysis
- Top-Level Directories:
- backend/ – REST API routes (src/routes), Prisma ORM (prisma/schema.prisma + migrations)
- frontend/ – React pages/components, styling, Vite config, deployment config (vercel.json)
- common/ – Shared code (src/index.ts), published as npm package for cross-project reuse
- Config & Deployment Files:
- backend/package.json, tsconfig.json, Cloudflare Worker setup via wrangler (implicit)
- frontend/vite.config.ts, vercel.json, Tailwind/postCSS configs
- Prisma migrations under backend/prisma/migrations

##### README Insights
- Highlights the tech stack: Node.js, Hono, Prisma, JWT, Crypto on the backend; React, Tailwind, Axios on the frontend; PostgreSQL database
- Deployment targets: Vercel for frontend, Cloudflare Worker for backend
- Database schema evolves via Prisma migrations (users, blogs, status column)

a. Main Components
- Client Browser (Chrome/Firefox on desktop/mobile)
- Frontend App (React+Tailwind)
- HTTP/API Layer (Axios on frontend → Hono routes on backend)
- Shared Common Library (npm package used at build time)
- Backend Business Logic (Hono controllers, JWT auth, Crypto hashing)
- ORM Layer (Prisma)
- PostgreSQL Database (hosted on a managed service)
- External Services: Vercel CDN/edge, Cloudflare Worker runtime

b. Relationships & Data Flows
1. User interacts with Frontend UI in the Browser
2. Frontend makes REST calls via Axios to Cloudflare Worker endpoint
3. Hono routes parse requests → invoke controllers using shared utilities from common/
4. Controllers use Prisma client to query/update PostgreSQL
5. Data returned through Hono → Axios promise resolves → UI updates
6. JWT workflows: Login endpoint issues JWT → stored in localStorage or HTTP-only cookie → attached to subsequent requests

c. Architectural Patterns & Principles
- Separation of Concerns: UI vs API vs Data Access
- RESTful API design using Hono
- ORM abstraction with Prisma migrations for schema evolution
- Shared module (common/) to DRY up utilities across frontend & backend
- Edge-deployed backend (low latency) + CDN-served frontend

d. Key Technologies
- Frontend: React.js, Tailwind CSS, Vite, Axios
- Backend: Node.js, Hono, Prisma, JWT, Crypto
- Database: PostgreSQL

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Zone
    subgraph "Client Zone"
        direction TB
        Browser["Client Browser"]:::client
        FE_App["Frontend App\n(React + Tailwind)"]:::client
        FE_Pages["Pages (UI Routes)"]:::client
        FE_Components["Reusable Components"]:::client
        FE_HTTPUtil["HTTP Client (Axios)"]:::client
        TailwindCfg["Tailwind Config"]:::client
        PostCSSCfg["PostCSS Config"]:::client
        ViteCfg["Vite Config"]:::client
        VercelCfg["Vercel Deployment Config"]:::client
    end

    %% Server Zone
    subgraph "Server Zone"
        direction TB
        CF_Worker["Cloudflare Worker\n(Hono Entry)"]:::server
        HonoRoutes["API Routes (Hono)"]:::server
        BlogsRoute(["/blogs endpoints"]):::server
        UsersRoute(["/users endpoints"]):::server
        Controllers["Controllers & Business Logic\n(JWT Auth, Crypto)"]:::server
        ORM["Prisma Client"]:::server
        Schema["Prisma Schema"]:::server
        Mig1["Migration: 20241217143455_user_and_blogs_added"]:::server
        Mig2["Migration: 20241226143543_add_status_column"]:::server
        MigLock["Migration Lock File"]:::server
    end

    %% Shared Common Library
    subgraph "Shared/Common"
        direction TB
        CommonLib["Common Library (utils/constants)"]:::shared
        CommonSrc["Source"]:::shared
        CommonPkg["package.json"]:::shared
        CommonTsCfg["tsconfig.json"]:::shared
    end

    %% Data Zone
    subgraph "Data Zone"
        direction TB
        Postgres["PostgreSQL Database"]:::db
    end

    %% Connections
    Browser -->|"UI Interaction"| FE_App
    FE_App -->|"Renders Pages"| FE_Pages
    FE_App -->|"Uses Components"| FE_Components
    FE_App -->|"Build-time Shared Utils"| CommonLib
    FE_App -->|"HTTP Calls (Axios)"| FE_HTTPUtil
    FE_HTTPUtil -->|"HTTP JSON with JWT"| CF_Worker
    CF_Worker -->|"Routes Request"| HonoRoutes
    HonoRoutes -->|"Handles /blogs"| BlogsRoute
    HonoRoutes -->|"Handles /users"| UsersRoute
    HonoRoutes -->|"Invokes"| Controllers
    Controllers -->|"Uses Shared Utils"| CommonLib
    Controllers -->|"Prisma Queries"| ORM
    ORM -->|"Executes SQL"| Postgres
    Postgres -->|"Returns Data"| ORM
    ORM -->|"Returns Results"| Controllers
    Controllers -->|"Sends Response"| HonoRoutes
    HonoRoutes -->|"Responds JSON"| FE_HTTPUtil

    %% Config connections
    FE_App --> TailwindCfg
    FE_App --> PostCSSCfg
    FE_App --> ViteCfg
    FE_App --> VercelCfg
    CF_Worker --> Schema
    CF_Worker --> Mig1
    CF_Worker --> Mig2
    CF_Worker --> MigLock

    %% Click Events
    click FE_App "https://github.com/darshan98solanki/medium/blob/main/frontend/src/main.tsx"
    click FE_Pages "https://github.com/darshan98solanki/medium/tree/main/frontend/src/pages"
    click FE_Components "https://github.com/darshan98solanki/medium/tree/main/frontend/src/components"
    click FE_HTTPUtil "https://github.com/darshan98solanki/medium/blob/main/frontend/src/lib/utils.ts"
    click TailwindCfg "https://github.com/darshan98solanki/medium/blob/main/frontend/tailwind.config.js"
    click PostCSSCfg "https://github.com/darshan98solanki/medium/blob/main/frontend/postcss.config.js"
    click ViteCfg "https://github.com/darshan98solanki/medium/blob/main/frontend/vite.config.ts"
    click VercelCfg "https://github.com/darshan98solanki/medium/blob/main/frontend/vercel.json"
    click CF_Worker "https://github.com/darshan98solanki/medium/blob/main/backend/src/index.ts"
    click BlogsRoute "https://github.com/darshan98solanki/medium/blob/main/backend/src/routes/blogs.ts"
    click UsersRoute "https://github.com/darshan98solanki/medium/blob/main/backend/src/routes/user.ts"
    click Schema "https://github.com/darshan98solanki/medium/blob/main/backend/prisma/schema.prisma"
    click Mig1 "https://github.com/darshan98solanki/medium/blob/main/backend/prisma/migrations/20241217143455_user_and_blogs_added/migration.sql"
    click Mig2 "https://github.com/darshan98solanki/medium/blob/main/backend/prisma/migrations/20241226143543_add_status_column/migration.sql"
    click MigLock "https://github.com/darshan98solanki/medium/blob/main/backend/prisma/migrations/migration_lock.toml"
    click CommonSrc "https://github.com/darshan98solanki/medium/blob/main/common/src/index.ts"
    click CommonPkg "https://github.com/darshan98solanki/medium/blob/main/common/package.json"
    click CommonTsCfg "https://github.com/darshan98solanki/medium/blob/main/common/tsconfig.json"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef server fill:#DFF8E0,stroke:#2E8B57,stroke-width:1px
    classDef db fill:#FFE5B4,stroke:#D2691E,stroke-width:1px
    classDef shared fill:#F0F0F0,stroke:#888888,stroke-width:1px
```
