# ajay9177/medium architecture

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

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

## Overview

##### Project Type and Purpose
- Full-stack, blog-publishing web application (“Write and Share”)
- Monorepo with three packages:
– frontend: React + Vite SPA deployed on Vercel
– backend: TypeScript Cloudflare Worker (Wrangler) exposing blog/user REST API
– common: shared TypeScript library (data types, helpers)

##### File Structure
- Top-level directories:
– offline/frontend → UI, routes, components, Tailwind, Vercel config
– offline/backend → API entrypoint, routes, Prisma schema/migrations, wrangler.toml
– offline/common → shared src → dist → published as local npm dependency
- Patterns & tools:
– Monorepo/npm workspaces or local package references
– RESTful routing: /blog, /user
– Serverless deployment: Wrangler/Cloudflare Workers
– ORM: Prisma with migration folders
– Frontend build: Vite, Tailwind CSS

##### README
- Confirms web-app use-case and audience

##### Main Components & Their Relationships
a. Client (Browser)
– Loads React SPA (hosted on Vercel)
– Calls backend APIs over HTTPS
b. Frontend (Vercel)
– Serves static assets (index.html, JS bundles)
– Contains UI pages: Signup, Signin, Blogs, Blog, Publish
c. Backend (Cloudflare Worker)
– Exposes REST endpoints via index.ts → routes/{blog,user}.ts
– Uses Prisma client to talk to the database
d. Database
– Managed by Prisma (could be PostgreSQL, SQLite, or Cloudflare D1)
– Schema defined in prisma/schema.prisma; migrations folder tracks versions
e. Common Library
– Provides shared TypeScript types and utilities
– Imported by both frontend and backend
f. External Services
– Vercel (frontend hosting)
– Cloudflare Workers (serverless functions)
– CDN/SSL in front

##### Architectural Patterns & Design Principles
- Mono-repo with clear package separation (frontend / backend / shared)
- API-first, RESTful routing
- Serverless functions for backend (scale-to-zero, low ops)
- ORM layer (Prisma) enforcing schema & migrations
- Shared common-library for DRY types/logic

##### Inclusion Checklist
- Annotation of shared “common” module usage

– Captures the monorepo’s three-package structure
– Clearly shows client-to-API-to-DB flow
– Differentiates build-time vs. runtime dependencies
– Highlights cloud hosting platforms and technologies in use
– Is easy for architects and developers alike to understand at a glance

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Browser (User Agent)"]:::client
    CDN["CDN / SSL"]:::infra

    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        FE_Root["offline/frontend"]:::code
        IndexHTML["index.html"]:::code
        ViteConfig["vite.config.ts"]:::code
        VercelConfig["vercel.json"]:::code
        MainEntry["src/main.tsx"]:::code
        AppComp["src/App.tsx"]:::code
        Pages["src/pages/*.tsx"]:::code
        Components["src/components"]:::code
        Styles["src/index.css\ntailwind.config.js"]:::code
    end

    %% Backend Layer
    subgraph "Backend (Cloudflare Worker API)"
        direction TB
        BE_Root["offline/backend"]:::code
        BE_Entrypoint["src/index.ts"]:::code
        BlogRoutes["src/routes/blog.ts"]:::code
        UserRoutes["src/routes/user.ts"]:::code
        WranglerConfig["wrangler.toml"]:::code
        BE_TSConfig["tsconfig.json"]:::code
    end

    %% Database Layer
    subgraph "Database (Prisma ORM)" 
        direction TB
        DB_Root["offline/backend/prisma"]:::code
        SchemaDef["schema.prisma"]:::code
        Migrations["migrations/*"]:::code
        MigrationLock["migrations/migration_lock.toml"]:::code
    end

    %% Common Library
    subgraph "Common Library (shared)" 
        direction TB
        Common_Root["offline/common"]:::code
        CommonSrc["src/index.ts"]:::code
        CommonDist["dist/index.js\nindex.d.ts"]:::code
        CommonPkg["package.json"]:::code
        CommonTSConfig["tsconfig.json"]:::code
    end

    %% Data Flow
    Browser -->|"HTTPS GET\nstatic assets"| CDN
    CDN -->|"serves index.html & JS"| FE_Root
    FE_Root -->|"API calls (HTTPS)\nGET/POST /blogs,/user"| BE_Entrypoint
    BE_Entrypoint -->|"calls routes"| BlogRoutes
    BE_Entrypoint -->|"calls routes"| UserRoutes
    BlogRoutes -->|"Prisma Client"| SchemaDef
    UserRoutes -->|"Prisma Client"| SchemaDef
    SchemaDef -->|"reads/writes"| DB_Root

    %% Build-time Dependencies
    CommonSrc -.->|import types| MainEntry
    CommonSrc -.->|import types| BE_Entrypoint

    %% Click Events
    click FE_Root "https://github.com/ajay9177/medium/tree/master/offline/frontend"
    click IndexHTML "https://github.com/ajay9177/medium/blob/master/offline/frontend/index.html"
    click ViteConfig "https://github.com/ajay9177/medium/blob/master/offline/frontend/vite.config.ts"
    click VercelConfig "https://github.com/ajay9177/medium/blob/master/offline/frontend/vercel.json"
    click MainEntry "https://github.com/ajay9177/medium/blob/master/offline/frontend/src/main.tsx"
    click AppComp "https://github.com/ajay9177/medium/blob/master/offline/frontend/src/App.tsx"
    click Pages "https://github.com/ajay9177/medium/tree/master/offline/frontend/src/pages"
    click Components "https://github.com/ajay9177/medium/tree/master/offline/frontend/src/components"
    click Styles "https://github.com/ajay9177/medium/blob/master/offline/frontend/src/index.css"
    click BE_Root "https://github.com/ajay9177/medium/tree/master/offline/backend"
    click BE_Entrypoint "https://github.com/ajay9177/medium/blob/master/offline/backend/src/index.ts"
    click BlogRoutes "https://github.com/ajay9177/medium/blob/master/offline/backend/src/routes/blog.ts"
    click UserRoutes "https://github.com/ajay9177/medium/blob/master/offline/backend/src/routes/user.ts"
    click WranglerConfig "https://github.com/ajay9177/medium/blob/master/offline/backend/wrangler.toml"
    click BE_TSConfig "https://github.com/ajay9177/medium/blob/master/offline/backend/tsconfig.json"
    click DB_Root "https://github.com/ajay9177/medium/tree/master/offline/backend/prisma"
    click SchemaDef "https://github.com/ajay9177/medium/blob/master/offline/backend/prisma/schema.prisma"
    click Migrations "https://github.com/ajay9177/medium/tree/master/offline/backend/prisma/migrations"
    click MigrationLock "https://github.com/ajay9177/medium/blob/master/offline/backend/prisma/migrations/migration_lock.toml"
    click Common_Root "https://github.com/ajay9177/medium/tree/master/offline/common"
    click CommonSrc "https://github.com/ajay9177/medium/blob/master/offline/common/src/index.ts"
    click CommonDist "https://github.com/ajay9177/medium/blob/master/offline/common/dist/index.js"
    click CommonPkg "https://github.com/ajay9177/medium/blob/master/offline/common/package.json"
    click CommonTSConfig "https://github.com/ajay9177/medium/blob/master/offline/common/tsconfig.json"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#007ACC,color:#000
    classDef infra fill:#E2F0D9,stroke:#2E7D32,color:#000
    classDef code fill:#F5F5F5,stroke:#CCCCCC,color:#333
    class Browser,CDN client
    class FE_Root,IndexHTML,ViteConfig,VercelConfig,MainEntry,AppComp,Pages,Components,Styles code
    class BE_Root,BE_Entrypoint,BlogRoutes,UserRoutes,WranglerConfig,BE_TSConfig code
    class DB_Root,SchemaDef,Migrations,MigrationLock code
    class Common_Root,CommonSrc,CommonDist,CommonPkg,CommonTSConfig code
```
