How sagarpanchal/smur works
Main Components
• Client / Frontend: Represent the browser or client, which serves static assets from the /public folder.
• API Server: The core Node.js application that includes:
• Routes – as seen in the “routes” directory (auth.routes, docs.routes, media.routes, etc.)
• Controllers – in the “controllers” directory (auth.controller.js, media.controller.js)
• Middleware – a robust collection (error handling, auth, JSON body parsing, multer error handling, passport integration, etc.)
• Utilities – modular functionalities (JWT handling, email sending, AWS S3 helper, Redis redlock, etc.)
• Configuration – centralized config files in “config” and referenced in “config.md”
• Database: MongoDB (required per README prerequisites)
• External Services:
• AWS S3 (as evident in utils/aws/AwsS3Helper.js)
• Email services (utilities for sending emails such as password resets and verification emails)
• OAuth integrations via Passport (with Facebook and Google strategies)
• Optional Redis caching (and redlock mechanism for distributed locking)
• Logging & Monitoring: Winston-based logging (and production management with PM2)
Out Relationships and Interactions
• Client to the API Server, clearly directing traffic:
• Requests reaching API endpoints (under “/api*”) are routed through middleware (authentication, error handling, JSON parsing).
• Non-matching GET requests redirect to static files (the “/public/index.html” for frontend routing).
• Within the server, include layers:
• Middleware sits early in the request processing pipeline.
• Routes pass requests to the appropriate controllers.
• Controllers handle business logic and invoke utility services.
• Logging and error reporting across components (e.g., controllers using Winston utilities from utils/winston).
Architectural Patterns and Design Choices
• Layered Architecture: Clearly separate the API server into middleware, routing, controller, and utility/service layers.
• Use of modular, utility-based design (notice many modules in “utils”) to keep concerns separated.
• Integration Patterns: External integrations like AWS, email, and OAuth are handled by abstracted modules ensuring easier testing and maintenance.
• Optional Scalability: Production mode runs with PM2 in cluster mode indicating that the application is built to scale horizontally.