How varunprajapatii/pencraft_app works
Project Type and Purpose
• This is a full-stack blog website comprising:
• Frontend: React SPA built with Vite, TypeScript, Redux, Tailwind CSS
• Backend: Cloudflare Workers (Hono) serverless API in TypeScript
• Shared module (“common”): Zod schemas for validation
• Database: PostgreSQL (Aiven) with Prisma ORM
• Auth: JWT for user sign-up/sign-in and route protection
Main Components
a. Frontend
– React application (src/pages, src/components)
– Redux store (authSlice, userProfileSlice)
– Fetch wrappers/hooks calling /api/v1/... endpoints
– Static assets served by your hosting (e.g., Cloudflare Pages)
b. Backend (Cloudflare Workers)
– Entry point: src/index.ts, routes registered under /api/v1/{auth|user|blog}
– Routers: authRouter, userRouter, blogRouter
– Middleware for JWT verification and context injection
– Prisma client connects to PostgreSQL using schema.prisma migrations
– Zod validation imported from the common package
c. Shared “common” Package
– Published to npm, consumed by backend (and potentially by frontend)
d. Database
– PostgreSQL instance managed on Aiven
– Tables: User, Blog (formerly Post), UserRelation, etc.
– Prisma migrations directory tracks schema changes
e. External Services
– Cloudflare Workers runtime
– Aiven PostgreSQL
– Wrangler for deployment
Relationships & Data Flow
1. Browser → Frontend: User navigates, JS bundle loads.
2. Frontend → Backend: HTTP calls (fetch/XHR) to Cloudflare Workers endpoints under /api/v1.
• On protected routes, Authorization header carries JWT.
3. Backend Router → Middleware: JWT validated, userId added to context.
4. Backend → Validation: Incoming payloads validated against Zod schemas from common.
5. Backend → Database (Prisma): Queries/mutations (createUser, getBlogs, follow/unfollow).
6. Database → Backend → Frontend: JSON responses with typed data.
7. Frontend (Redux): Updates application state, triggers UI updates.
Architectural Patterns & Design Principles
• Separation of concerns: clear boundary between UI, API, data layer, and validation logic
• Serverless micro-API: each endpoint is stateless, deployed to Cloudflare Workers
• Shared contract: Zod schemas in “common” ensure type-safe validation across layers
• RESTful routing under /api/v1/{resource} namespace
• Atomic database migrations via Prisma
• Client-side state management using Redux
Essential Elements to Capture
• Frontend build and serve process (Vite → static assets)
• API gateway (Cloudflare Workers entry) and route grouping
• Middleware for authentication and Zod validation
• Business logic routers: auth, user, blog
• Prisma migrations and client interactions
• PostgreSQL schema and tables
• JWT flow: issuance on signup/signin, verification on protected endpoints
• Follow/unfollow transactions and clap operations