How moshahat1/medify4u works
Project Type and Purpose
• Medify Backend is a monolithic, full‐stack application’s backend API, built with Node.js/Express, exposing REST endpoints to support a medical assistance platform. It connects clients (web/mobile) to core services (appointments, messaging, AI analysis, file storage, push notifications) and persists data in MongoDB via Prisma.
File Structure Analysis
• Top‐level:
• api/index.js: Entry point for Vercel serverless deployment
• src/: Application code (app.js, config, controllers, middleware, models, routes, services, utils, validators, scripts)
• prisma/: Database schema (Prisma ORM)
• package.json, vercel.json, Postman docs
• Layers identified:
• Configuration (firebase.js, prisma.js, logging.js, upload.js)
• Routing & Controllers (routes/* → controllers/*)
• Business Logic (services/*)
• Data Layer (models/* + Prisma ORM)
• Cross‐cutting concerns (middleware, validators, utils)
Key Components
a. Clients
• Web / Mobile Frontend (React, Flutter, etc.)
b. API Gateway / Load Balancer
• Vercel Serverless Functions / API Gateway
c. Application Server (Node.js/Express)
• Routing Layer (src/routes)
• Controllers Layer (src/controllers)
• Middleware (Auth, Error Handling, Rate Limiter, CORS, Helmet)
• Services Layer (Business logic, external integrations)
d. Data Persistence
• MongoDB (hosted externally)
• Prisma ORM (prisma/schema.prisma + generated client)
e. External Services
• Firebase Admin SDK (Push Notifications)
• Vercel Blob Storage (File Uploads)
• Nodemailer/SMTP (Email Notifications)
• AI Service API (Health data analysis)
f. Ancillary Components
• Redis or in‐memory store (optional for rate limiting or sessions)
• Postman Collection for API documentation
Relationships & Data Flows
• Client → API Gateway (HTTPS Request) → Express Router → Controller → Service
• Service → Prisma Client → MongoDB (CRUD operations)
• Service → External API (Firebase, AI Service, SMTP, Blob Storage)
• Middleware intercepts requests for authentication (JWT), validation (Yup), rate limiting, error handling.
• Logging layer (Winston) captures request/response and errors.
Architectural Patterns & Principles
• Layered (Onion) Architecture: controllers → services → data layer
• MVC‐ish separation for Request Handling vs Business Logic vs Data Access
• Single responsibility: each service handles one domain (e.g., appointment.service, message.service)
• Dependency Injection via module imports (config modules injected into services/controllers)
• Infrastructure as Code: Vercel deployment, Prisma migrations
• Secure by default: CORS, Helmet, rate limiting, input validation
• Clients (Web/Mobile)
• API Gateway / Vercel
• Node.js/Express App (group into Routing, Controllers, Middleware, Services, ORM)
• MongoDB
• External Services (Firebase, AI, Email SMTP, Blob Storage)
• From Clients → API Gateway → Express Router → Controllers → Services → Data Store / External Service
• “Auth Middleware” interceptor
• “appointment.controller.js” → “appointment.service.js”
• “Prisma Client” → “MongoDB Atlas”
e. Protocols & tech:
• HTTPS / REST
• JWT Auth token
• WebSocket (if real‐time messaging uses it) or HTTP Polling
• File upload via Vercel Blob API