How mscopa/cse340 works
Main Components
• Server/Entry Point: The application starts from server.js, which sets up the Express server. It defines the port and uses values from a .env file (mentioned in the README).
• Controllers: These include baseController.js and invController.js located in the controllers directory. They process incoming requests, control business logic, and coordinate data flow between models and views.
• Routes: In the routes folder, files like inventoryRoute.js and static.js map HTTP request URLs to specific controller methods.
• Models: The models directory (with inventory-model.js) is in charge of interacting with the database—encapsulating the business data and handling validation or transformation as needed.
• Database: The database folder contains SQL scripts, a database index (likely configuring connection details), and sample data (inventory-data.txt). This represents a PostgreSQL database backend that the application uses.
• Views: Using EJS templates, the views folder contains the presentation layer, with layouts, partials (header, footer, etc.), and view files for errors and inventory pages.
• Public Assets: The public directory holds static files like CSS, JavaScript, and images which are directly served to clients.
• Utilities: A set of helper functions or miscellaneous modules meant to assist various components of the application.
• Package Management & Configuration: The package.json and pnpm-lock.yaml files manage dependencies, with instructions in the README for using PNPM as the package manager.
Relationships and Data Flow
• The client (browser) sends HTTP requests to the server.
• The Express server (in server.js) listens for these client requests.
• The request URL is handled by a route (defined in routes folder), which determines the controller to invoke.
• The controller performs application logic, potentially interacting with the model for data retrieval or updates against the PostgreSQL database.
• The controller then loads an appropriate EJS view (from the views folder) to render the dynamic response, often embedding data from the models.
• Static content (CSS, JS, images) is delivered from the public directory independently.
• Utilities may be called by different parts of the system to manage tasks such as formatting data or handling error logging.
Architectural Patterns and Important Design Principles
• Separation of Concerns: The application’s structure separates the frontend presentation layer (EJS views & public assets) from the backend logic (controllers, routes, and models) and data persistence (database).
• Dependency Management: Use of Node, Express, and PNPM defines how the third-party packages are managed and integrated.