How fercracix33/back-master works
Project Type and Purpose
• Type: A standalone backend service providing RESTful HTTP APIs plus real-time features via WebSockets (Socket.IO).
• Purpose: Manage users, communities, boards, chat, files, events, notifications, etc., with data stored in a relational database via Prisma ORM.
File Structure
• Top-level:
– prisma/schema.prisma → DB schema definitions
– api-documentation.yaml → OpenAPI spec
– src/index.ts → Express + Socket.IO server bootstrap
– tsconfig.json, package.json
• src/middleware/auth.ts → authentication/authorization layer for both HTTP and WS
• src/prisma/client.ts → Prisma client factory
• src/routes/*.ts → REST controllers by domain (auth, users, communities, chat, files, etc.)
• src/socket/ → real-time event system
– eventBus.ts → in-process pub/sub for cross-module events
– index.ts → Socket.IO handlers (chat, notifications, etc.)
– scheduledNotifier.ts → cron-style tasks generating notifications
• src/types/AuthRequest.ts → extended Request type with user context
Extract Key Architectural Insights from the README
• Express.js for HTTP pipeline
• Prisma as ORM to a relational database
• Socket.IO for WebSocket connections
• A middleware layer for authentication
• A small in-process event bus to decouple real-time notifications and scheduled tasks
Main Components
a. Clients
– Web/Mobile Apps (HTTP + WS consumers)
b. API Gateway / Server
– Express.js HTTP server
– Socket.IO server
c. Middleware
– Auth middleware (JWT/session validation)
d. Route Handlers (grouped by domain)
– Auth, Users, Communities, Boards, Chat, Files, Events, Notifications, etc.
e. Business-Logic / Service Layer (implicit in routes/eventBus)
f. Prisma ORM
g. Database
h. Real-Time Infrastructure
– eventBus (pub/sub)
– scheduledNotifier (cron-triggered events)
i. External Integrations (if any, e.g., file storage, email service)
Relationships / Data Flows
• HTTP flow:
Client → Express (index.ts) → Auth Middleware → Route Handler → Prisma Client → Database → Response
• WebSocket flow:
Client ↔ Socket.IO (index.ts) → Auth Middleware → eventBus → Route logic → eventBus → broadcast to Clients
• Scheduled notifications:
scheduledNotifier → eventBus → Socket.IO → Client notifications
• All DB access is funneled through prisma/client.ts
Architectural Patterns & Principles
• Layered architecture: Transport (HTTP/WS), Middleware, Controller (Routes), Data Access (Prisma), DB
• Separation of concerns: Each route file covers one domain, eventBus decouples producers/consumers
• Pub/Sub: In-process event bus for real-time updates and scheduling
• Single responsibility: Middleware only handles auth, routes only handle request/response