How makanmatch/backend works
Project type and purpose
• From the file tree and README, MakanMatch Backend is a Node.js/Express full-stack application’s server component.
• Purpose: Provide a REST + WebSocket API for a community food-sharing platform, handling user identity, listings, reservations, reviews, real-time chat, analytics, file storage and admin operations.
File structure
• Top-level directories:
• config: static configs
• middleware: request lifecycle handlers (auth, analytics, file filters, logging, response processors)
• models: Sequelize ORM definitions for MySQL/SQLite (User, Host, Listing, Reservation, Review, Analytics, etc.)
• routes: Express route modules grouped by domain (cdn, chat, chatbot, identity, listings, orders, reviews, misc) and a WebSocketServer for chat
• services: business-logic layer (Analytics, TokenManager, FileManager, Logger, Emailer, OpenAIChat, Cache, etc.)
• public & views: static assets & email templates
• index.js: Express app entry point
• Auxiliary files: dbTools.js (database helpers), superuserScript.py, ConfiguringSystem.md
Extract architectural insights from the README
• Tech stack: Node.js, Express.js, Sequelize ORM, AWS RDS (MySQL), Firebase Cloud Storage, Google Cloud (Maps SDK & Geocoding), Google SMTP, OpenAI API
• Major features: JWT auth, layered middleware, service layer abstraction, real-time WebSocket chat, analytics aggregation, email templating
a. Main components
• Clients (Web SPA / mobile): HTTP(S) & WebSocket connections
• API Gateway (Express app)
• Middleware chain (auth, headersCheck, analytics, logging, file filters, response processors)
• Route handlers/controllers (routes/* modules)
• Service layer (services/*)
• Data layer (models/* via Sequelize)
• Primary database (AWS RDS MySQL, dev SQLite)
• File storage (Firebase Cloud Storage + local fallback)
• WebSocket server (for chat)
• External services: Google Maps API, Google SMTP, OpenAI GPT API
• Admin tools (superuserScript.py + admin route modules)
b. Relationships & data flows
1. Client → Express API entry (index.js)
2. Request passes through ordered middleware (auth → analytics → headersCheck → etc.)
3. Middleware may invoke TokenManager, Analytics, Logger, FileManager
4. Route handler calls service layer
5. Service layer interacts with Sequelize models (reads/writes DB) and external APIs (Firebase, SMTP, Maps, OpenAI)
6. WebSocketServer manages real-time chat channel parallel to REST flows
7. Responses go back through responseProcessors before reaching client
c. Architectural patterns & principles
• Layered architecture (Controller → Service → Data)
• MVC-style separation
• Middleware pipeline for cross-cutting concerns
• Dependency injection via services/index.js
• External adapter pattern for third-party integrations (FileManager, OpenAIChat, Emailer)
d. Key technologies & libraries
• Express.js (web framework)
• Sequelize ORM (database access)
• JWT & TokenManager (authentication)
• Firebase SDK (storage)
• AWS RDS (MySQL)
• Google Maps & SMTP APIs
• OpenAI GPT API integration