How linhinthehood/projectnodejs works
Main System Components
• Backend Server: The core of the application, driven by Express (server.js), handling requests through defined routes (located in the routes folder) for authentication, products (shirts, bottoms, outerwear, accessories), profile management, about us, and orders.
• Database: MongoDB Atlas is used as the primary datastore, with GridFS for file storage ("assets" content and other static files), and models defined for products, receipts, and users.
• Frontend & View Layer: Uses the EJS template engine (views folder) to render the web pages. Static assets and public files (e.g., public/load-balancer-demo.html) are served from designated directories.
• Message Broker: RabbitMQ is integrated for handling asynchronous operations (as seen by configurations in config/rabbitmq.js and usage in services like emailService.js and messageService.js). This component is critical for decoupling tasks such as sending welcome emails or order confirmation notifications.
• Worker Processes: Separate processes (worker.js and workers/messagingWorkers.js) are dedicated to processing queued tasks/messages, ensuring that non-blocking operations do not interfere with the main application flow.
• Caching & Session Management: Redis is used for managing sessions (as indicated by packages like connect-redis and configuration for session-based authentication).
• Load Balancer/Reverse Proxy: Nginx is configured (nginx.conf) to act as the load balancer to distribute incoming requests, and the Docker setup (Dockerfile and docker-compose.yml) ensures containerized deployments.
• The MongoDB database for data persistence.
• The RabbitMQ Message Broker for inter-service communication.
• Redis for session storage.
• The EJS templating engine (frontend views) to generate dynamic HTML pages.
• A separate container/block for “Worker Processes” that subscribes to the RabbitMQ queues to process asynchronous tasks.
• Nginx as a front-facing component that handles load balancing before forwarding traffic to the main application server.
• Client requests entering via Nginx.
• API calls from the Express Server to MongoDB, Redis, and RabbitMQ.
• RabbitMQ dispatching messages to the worker processes.
• The response flow from the server back to the client.
• Other minor external dependencies as needed (e.g., third-party email services if referenced through emailService.js).
Architectural Patterns and Design Principles
• Employ a microservice-inspired design even within the monolith by decoupling asynchronous tasks using message queues.
• Clearly delineate between synchronous operations (user interactions, data retrieval) and asynchronous operations (notifications, order confirmations) for improved scalability and fault tolerance.
• That Docker containers encapsulate the application, load balancer (Nginx), and supporting services (Redis, RabbitMQ), ensuring environment consistency.
• Docker-based infrastructure, as the Dockerfile and docker-compose.yml are crucial for orchestrating the different components (including Nginx for load balancing and containerized backend services).