How varun-chakraborty/blog-post works
Project Type and Purpose
• This is a full-stack blogging platform (“Blog Post App”) with:
• A React/TypeScript SPA (frontend)
• A Node.js/Express/TypeScript API (backend)
• Persistent storage via PostgreSQL (managed through Prisma)
• In-memory caching/session store via Redis
• Real-time chat via Socket.IO
Top-Level Components
a. Frontend (frontend/)
• Built with Vite + React + TypeScript + Tailwind CSS
• Core pieces:
• App shell (src/main.tsx → App.tsx)
• Pages (src/pages/*)
• UI components, forms, cards, buttons (src/components/*)
• State management (src/redux/*)
• HTTP services (src/services/http/*)
• WebSocket client (src/services/socket)
b. Backend (backend/)
• Node.js + Express + TypeScript
• Dockerized (Dockerfile + docker-compose.yml)
• Key subcomponents:
• HTTP server entrypoint (src/server.ts + src/index.ts)
• Routing layer (src/router/v1.route/*)
• Controllers (src/controllers/*)
• Database layer (Prisma ORM in src/db/prisma.ts)
• Caching/session layer (Redis in src/db/redis.ts)
• Middleware (auth checks, user resolution)
• Socket.IO server (src/socket + src/socketListenerHandlers)
• Utility modules (token utils, response wrapper, cookie setter)
c. Datastores
• PostgreSQL (Prisma migrations + schema.prisma)
• Redis (session, token blacklisting, pub/sub for notifications)
d. External Infrastructure
• Docker / Docker Compose for local dev
• Vercel (frontend deployment via vercel.json)
• CI pipeline (GitHub Actions: .github/workflows/ci.yml)
• Sonar for code quality (sonar-project.properties)
Component Interactions & Data Flows
1. Browser → React SPA (served via Vite/hosted on CDN)
2. SPA → HTTP API
• REST calls to /api/v1/auth, /posts, /comments, /users, etc.
• HTTP flows through Express router → middleware → controllers → Prisma → Postgres
3. SPA ↔ WebSocket
• Real-time message events via Socket.IO client/server
• socketListenerHandlers handle events like “newMessage” and broadcast via Redis pub/sub if clustered
4. API → Redis
• Store/retrieve access & refresh tokens
• Invalidate tokens on sign-out
• Possibly pub/sub for real-time notifications
5. API → Postgres
• Prisma client issues queries (CRUD for posts, comments, likes, follows)
Architectural Patterns & Principles
• Layered architecture:
• Presentation → Routing → Controllers → Data Access (Prisma) → Database
• Cross-cutting concerns handled by middleware (authentication, authorization)
• Separation of concerns: HTTP vs. WebSocket vs. DB vs. Cache
• Twelve-factor app principles (environment config via .env.sample, 12-factor logging, etc.)
• Containerization: encapsulate backend dependencies in Docker images
1. Client Layer (Browser / Mobile)
2. CDN / Static Hosting (serving SPA assets)
3. Backend Services
4. Datastores & Caches
• HTTP API Service (Express)
• Real-time Service (Socket.IO)
• Browser → CDN → SPA → HTTP API
• SPA ↔ Socket.IO endpoint
• HTTP API → Middleware → Controllers → Prisma Client → Postgres
• HTTP API → Redis
• Socket.IO → Redis Pub/Sub (if applicable)
d. Component with technologies:
• React + Vite + Tailwind (frontend)
• Express + TypeScript + Jest (backend tests)
• Prisma + PostgreSQL
• Redis
• Docker + Docker-Compose
e. Environment overlays:
• Docker Compose orchestrating API, Postgres, Redis in dev
• CI/CD pipeline invoking tests & deployments (GitHub Actions → Vercel)