How harshs490/pulsechat-backend works
Project’s type and purpose
• This is a backend-focused, real-time chat service built on Express.js and TypeScript.
• It exposes REST endpoints (auth, users, friends, conversations) and a WebSocket interface for real-time messaging.
• It uses Prisma to manage a relational database, Kafka for event streaming, and Redis for caching or pub/sub.
File structure
Top-level files
• package.json / package-lock.json – Node dependencies.
• tsconfig.json – TypeScript compiler settings.
• .gitignore, ca.pem – git and certificates.
prisma/
• schema.prisma – data model.
• migrations/ – SQL migrations tracking chat, users, messages, indexing.
src/
• config/ – kafka.ts, prisma.ts, redis.config.ts (connectors for external services).
• controllers/ – business logic for auth, users, friends, conversations.
• middlewares/ – AuthMiddleware to protect routes.
• models/ – input/output schemas.
• routes/ – routes.ts binds controllers to URLs.
• socket.ts – WebSocket server setup for real-time events.
• index.ts – application entrypoint (HTTP server and WebSocket attachment).
README
• Describes it as an “Express JS With Typescript Starter KIT” meant to run at localhost:8000.
Main components
1. Clients
– Browser or mobile client (REST + WebSocket).
2. API Layer (Express.js)
– HTTP server (index.ts)
– Routes → Controllers → Services
– AuthMiddleware enforces security
3. WebSocket Layer
– socket.ts manages real-time connections
– Emits and listens for chat events
4. Business Logic
– Controllers handle requests and events
– Models/schemas validate payloads
5. Data Persistence
– Prisma Client (prisma.ts)
– PostgreSQL (or other SQL) behind prisma/schema.prisma
6. Messaging & Caching
– Kafka cluster (kafka.ts) for event streaming (e.g., message queuing, notifications)
– Redis (redis.config.ts) for caching session data, pub/sub
7. Migrations
– prisma/migrations track schema changes
Relationships and interactions
• Client → HTTP endpoints → Express router → Controller → Prisma → Database
• Client → WebSocket → socket.ts → Controller → Kafka (publish/subscribe)
• Controllers or socket handlers → Redis for caching or to coordinate pub/sub
• Kafka consumers (could be separate workers) → process events → write back to DB or emit to WebSocket clients
Architectural patterns and design principles
• Layered architecture: Presentation (Routes/Socket), Business (Controllers), Data (Prisma/DB)
• Single service approach (monolith) with event-driven elements (Kafka)
• Use of middleware for cross-cutting concerns (authentication)
• Schema-first data modeling via Prisma