How arnoldcuriano/phase-1-web-development-bge-application works
Project Type and Purpose
• The project is an internal web application built primarily for BGE employees and administrators.
• It’s a full-stack web application built on Node.js, employing a typical MVC pattern using ExpressJS, with MongoDB as the database.
• The project supports various business functions (e.g., handling announcements, projects, departments, members, services, categories, etc.) through dedicated controllers, models, and views.
File Structure
• Key top-level directories:
• “controllers”: Contains business logic for different data entities (e.g., category, client, department, etc.).
• “models”: Defines Mongoose schema-based models for the database, which maps well with MongoDB.
• “routes”: Contains ExpressJS routes that map URL endpoints to controllers.
• “views”: Holds EJS templates (and some Pug templates for emails) which render the frontend.
• “public”: Contains static assets such as fonts, images, and uploads.
• “config”: Contains configuration files including authentication settings (passport) and possibly keys.
• “middleware”: Contains custom middleware (like auth.js) that handles authentication or other request processing.
• Other supporting files include package configuration files (package.json, ecosystem.config.js), deployment scripts (start_pm2.sh), and environment-related files.
README for Additional Insights
• The README confirms that this project is built using Node.js and MongoDB, and lists other important packages such as Express, Mongoose, EJS, Multer, Passport, etc.
• It briefly outlines the installation and basic steps but also hints at a Phase I development status, showing that the architecture should account for potential future scaling and improvement.
• The README highlights the use of both EJS and Pug, meaning parts of the application (likely differing sections or email templates) might use different templating engines.
a. Main Components:
• Client/Browser: This is where the frontend interacts via EJS templates for rendering webpages.
• Web Server (Express/Node.js): Acts as the central processing unit responding to HTTP requests. Inside this, you have:
• Routes: Handle incoming HTTP requests and dispatch them to appropriate controllers.
• Controllers: Implement core business logic for different functionalities.
• Middleware: Manage authentication (using Passport and custom auth middleware) and possibly other request/response processing.
• Views: The presentation layer using EJS and Pug templates.
• Database (MongoDB): This stores all persistent data for models such as announcements, projects, departments, etc.
• External Services/Dependencies:
• Multer: For file/image uploads.
• Sharp: For image processing.
• Nodemailer (mailer) with Pug: For sending emails.
• Authentication (Passport).
• PM2 Ecosystem: For production process management.
b. Relationships and Interactions:
• Within the Server, routes map to controllers which then interact with models (via Mongoose) to query or update MongoDB.
• The middleware is positioned between routes and controllers (or as an integral part of the route processing) to handle authentication and validations.
• The views are dynamically rendered in response to requests from the controllers.
• External libraries like Multer and Sharp integrate for file handling, and services like the mailer are invoked from within the controllers when required.
• Configuration files and environment variables ensure that sensitive details (like keys and passport settings) are centrally managed and injected where needed.
c. Architectural Patterns and Design Principles:
• MVC (Model-View-Controller): Clear separation of responsibilities across models, views, and controllers.
• Modular Design: Different concerns (routes, controllers, middleware, models) are separated into distinct directories.
• Separation of Static and Dynamic Assets: “public” holds static resources, while dynamic content is rendered in the “views” layer.
• Utilization of Environment Configurations: The “config” directory ensures that global settings (like keys, passport setup) follow environment-specific adjustments.
• Scalability and Maintainability: PM2 configuration and modularity in design ease scaling and maintenance.
d. Relevant Technologies and Frameworks:
• Node.js and ExpressJS for the server.
• MongoDB as the database with Mongoose ODM.
• EJS and Pug templating engines.
• Passport for authentication.
• Multer for file uploads and Sharp for image processing.
• Session management (Express Session) and various middleware components.