How gicehajunior/myexpress-framework works
Project Type & Purpose
• MyExpress is a Node.js framework built on top of Express.js tailored for rapid web application development. It is designed following the MVC (Model-View-Controller) architecture.
• The purpose is to provide developers with a modular, configurable, and secure starting point including authentication, routing, and asset bundling using Webpack.
Main Components
a. Application Core:
– server.js: The main entry point running the Express server.
– app/controllers: Contains controllers split into subcategories for “auth” and “other”. These manage incoming HTTP requests (e.g., AuthController, DashboardController, JournalController, and WebController).
– app/models: Represents business data objects like User and Journal.
– app/mwares: Custom middleware (e.g., authMiddleware) to protect routes or manage additional logic.
– app/utils: Utility functions (e.g., UserUtil, Util) that assist handling various business or data-related operations.
b. Routing:
– routes folder (with files like auth.js and app.js) defining the API endpoints and how requests are mapped to controllers.
– Configured routes in these files represent the connection between requests and their respective controller actions.
c. Configuration & Environment:
– config folder: Holds configuration files (e.g., for database, application settings, CORS, exceptions, and services). This defines how the system should behave in different environments.
– .env-example file: Outlines environment-specific variables which are critical for deployment configuration.
d. View Layer:
– resources folder: Contains EJS templates for rendering views such as pages for authentication, CRM dashboard, and web layouts.
– public folder: Contains static assets like CSS, JavaScript, and images used by the view layer.
e. Assets & Bundling:
– Webpack configuration file (webpack.config.js): Used for bundling front-end assets.
– Babel configuration (babel.config.json) to support modern JavaScript features.
f. Database Integration:
– db folder: Contains SQL dumps and table definitions, indicating use of a relational database system likely interfaced via an ORM (Sequelize is mentioned in the README).
g. Testing:
– tests folder: Contains unit tests for various components such as controllers and parsers which ensures the integrity of the framework during changes.
Relationships & Interactions
• HTTP requests flow into the Express application via server.js, then through the relevant routes defined in the routes folder.
• Incoming requests pass through middleware (like authMiddleware) and are then dispatched to the appropriate controllers. Controllers interact with models to retrieve or manipulate data.
• The controller then invokes the view logic by rendering EJS templates located within resources/views. Public directory assets (CSS, JS) are served statically to support the UI.
• Configuration files provide overarching settings affecting all components (e.g., database connections, service integrations, and security configurations).
• The asset bundling process via webpack integrates with the public folder to produce optimized JavaScript and CSS bundles.
Architectural Patterns & Design Principles
• MVC Pattern: Clear separation of concerns between Models (data), Views (presentation), and Controllers (logic).
• Modular Structure: Directories such as controllers, models, middleware, and utilities are well organized and promote separation of concerns.
• Configuration Driven: A dedicated config folder allows for environment-specific adjustments, enhancing maintainability.
• Testing Layer: The presence of unit tests ensures reliability and facilitates continuous integration.