How joaquindecima/coderhouse-js-ecommerce works
Main Components
• Frontend Client:
• Represented by static assets in the “public” folder (CSS, JavaScript, images) and the Handlebars views under “views”. This is the browser-facing layer that renders pages and interacts with client-side scripts (including chat, ecommerce operations, dynamic themes, etc.).
• Backend Server:
• The “src/server.js” is the entry point to your Node.js application.
• Express is used as the server framework to handle routing, middleware and API endpoints.
• Routers & API Layer:
• Located in “src/routers/”, these handle different parts of your application (authentication, product, cart, chat, and error routes). There are both standard routes (e.g., authRouter.js for session-based flows and global and product routers) and distinct API endpoints (e.g., authRouterAPI, cartRouterAPI).
• Business Logic / Models:
• Found in “src/model/”, organized by domain (cart, chat, order, product, user) the models encapsulate business rules and interact with the data access layer directly.
• Data Access Layer:
• “src/dao/” and model-specific DAO implementations (e.g., cartMongoManager.js, productFirebaseManager.js) indicate multiple persistence mechanisms. This demonstrates an abstraction that can swap between MongoDB, Firebase, or even file-based storage.
• Middleware:
• Middleware files such as “isAuthenticated”, “isNotAuthenticated”, and “isSeller” enforce access control and other logic before requests hit the routers.
• Utility Tools:
• “src/tools/” contain helper services for logging (Winston), sending emails (Nodemailer), SMS (Twilio), token management (JWT), and other domain-specific tasks.
• Configuration & Environment:
• The “config” folder (with Firebase admin JSON) and the .env file (via .env.example) define the runtime configuration. They include details for Mongo connections, Twilio credentials, session secrets, and JWT secrets.
Relationships & Data Flows
• The Browser interacts with the server via HTTP requests, triggering appropriate routes (e.g., login, product browsing, cart actions) and also using Socket.IO for real-time functionalities like chat.
• The Express server (entry point from src/server.js) dispatches these incoming requests to proper routers which, in turn, call into the business logic (models) and then to the DAO for data interactions.
• Middleware sits between the incoming request and the routers to enforce security and access controls.
• The DAO layer abstracts the underlying databases (MongoDB, Firebase) so that the business logic remains decoupled from the data storage implementations.
• Utility tools are invoked where required, for example, when sending email confirmations, SMS notifications, or logging important event information.
• The Handlebars view engine uses templates from the “views” folder to generate dynamic HTML responses for the user interface.
Architectural Patterns & Principles
• MVC-like Separation: Although not strictly the classic MVC, the division between “views” (presentation), “routers and middleware” (controller-like functions), and “models/dao” (data/business logic) is evident.
• Abstraction for Data Persistence: Different manager implementations (Mongo, Firebase, File) allow plugging in multiple back-end storage systems without changing higher-level logic.
• Decoupling of Concerns: Middleware for security and validation, separate modular routers, and isolated utility modules reflect a system that is segmented to simplify maintenance and testing.
• Microservices-ish tendencies (or plugin architecture) in the sense that each domain (cart, chat, product, etc.) has its own set of manager files and routers.