This is a comprehensive program designed to automate the processing and management of live scan and alert data. It showcases advanced techniques in middleware extension, error handling, and data processing, making it a robust and effective tool for various industries that require real-time data monitoring and management.
- Data Ingestion: Continuously monitors incoming data for live scans and alerts.
- Data Processing: Validates and processes incoming data, including geocoding and payload validation.
- Database Interaction: Updates the SQL database with processed data.
- Middleware Extension: Extends Express' built-in middleware for improved request validation and error handling.
- Error Handling: Implements advanced error handling and logging mechanisms.
This system ensures that real-time scan and alert data is accurately captured, processed, and stored, facilitating efficient data management and operational efficiency.
- Node.js: The primary programming language used for this project.
- Express.js: For building the web server and handling HTTP requests.
- Asynchronous Programming: Utilized for handling I/O-bound operations efficiently.
- Environment Variables: Managed using
dotenv
for configuration settings. - SQL: For database interactions and queries.
- API Integration: For making requests to third-party services.
- Error Handling: Implemented to manage errors and ensure the robustness of the application.
- Logging: For tracking and debugging the process.
- Middleware Extension: Custom middleware for request validation and error handling.
- Dependency Management: Managed using
npm
.
- Automated Data Ingestion: Continuously monitors and ingests live scan and alert data.
- Integration with Third-Party Services: Utilizes API integration for geocoding services.
- Advanced Error Handling: Custom error classes and middleware for robust error management.
- Asynchronous Operations: Efficient handling of I/O-bound operations.
- Modular Architecture: Organized code structure for maintainability and scalability.
- Comprehensive Logging: Detailed logging for tracking and debugging.
- Email Notifications: Sends notifications for critical errors.
- Strategy Pattern Implementation: Uses the Strategy Pattern to handle different types of payloads for
LiveScan
andLiveAlert
.
The project extends Express middleware to enhance request validation and error handling. Custom middleware functions are used to validate HTTP methods, paths, and request bodies, ensuring that only valid data is processed.
Advanced error handling is implemented using custom error classes and middleware. Errors are categorized and handled based on their type, with specific responses and logging mechanisms in place. Critical errors trigger email notifications for immediate awareness.
Data processing involves several steps:
- Payload Validation: Incoming data is validated against predefined schemas to ensure it meets the required format.
- Geocoding: The Fetch API is used to make HTTP requests to the OpenStreetMap Nominatim service for reverse geocoding.
- Database Interaction: Processed data is updated in the SQL database using parameterized queries to prevent SQL injection.
The project leverages several Object-Oriented Programming (OOP) design patterns to enhance modularity, maintainability, and scalability:
-
Strategy Pattern:
- Usage: Different strategies are implemented for handling
LiveScan
andLiveAlert
payloads. ThePayloadContext
class dynamically selects the appropriate strategy based on the path. - Example:
LiveScanStrategy
andLiveAlertStrategy
classes implement specific logic for handling their respective payloads.
- Usage: Different strategies are implemented for handling
-
Factory Pattern:
- Usage: The
PayloadContext
class acts as a factory to instantiate the appropriate strategy based on the path. - Example: The constructor of
PayloadContext
selects and initializes the correct strategy (LiveScanStrategy
orLiveAlertStrategy
).
- Usage: The
-
Template Method Pattern:
- Usage: The
PayloadStrategy
base class defines the skeleton of the payload processing algorithm, deferring specific steps to subclasses. - Example: Methods like
getFieldList
,navigateFields
, andaddDataToObj
are defined inPayloadStrategy
and implemented inLiveScanStrategy
andLiveAlertStrategy
.
- Usage: The
-
Chain of Responsibility Pattern:
- Usage: Middleware functions in Express form a chain of responsibility, where each function processes the request and either handles it or passes it to the next middleware in the chain.
- Example: Middleware functions for request validation and error handling.
Comprehensive logging is implemented to track the flow of data and capture any errors or anomalies. Logs are stored in a structured format for easy analysis and debugging.
Email notifications are sent for critical errors using the SendGrid API. This ensures that any significant issues are promptly reported and can be addressed in a timely manner.
The project is organized into the following files and directories:
src/app.js
: Main application file.src/bookends/
: Contains middleware for the beginning and end of request processing.begin.js
end.js
index.js
src/common/
: Common utility functions and constants.payloadFields.js
utility.js
src/controllers/
: Controllers for handling business logic.control.js
controllers.js
index.js
src/email/
: Email notification functionality.emailer.js
src/errors/
: Error handling classes and functions.classes/
classes.js
controllers.js
database.js
index.js
middleware.js
normalizer.js
payload.js
email.js
index.js
log.js
responses.js
setter.js
write.js
src/extenders/
: Middleware extenders for additional functionality.errors.js
index.js
middleware.js
src/handlers/
: Handlers for specific operations.index.js
sql.js
src/middleware/
: Middleware for request validation and processing.extension.js
validate.js
src/models/
: Database models and schemas.database.js
index.js
schemas.js
src/routes/
: API routes.index.js
liveAlert.js
liveScan.js
src/services/
: Services for processing data.geocode.js
index.js
payload.js
sql.js
strategies/
context.js
index.js
liveAlert.js
liveScan.js
payload.js
src/storage/
: Data storage and management.holders.js
stores.js
- Node.js 14 or higher
- Access to a SQL database
- SendGrid API key for email notifications
-
Clone the repository:
git clone https://github.com/ryanlevee/real-time-scan-and-alert-system.git
-
Navigate to the project directory:
cd real-time-scan-and-alert-system
-
Install the dependencies:
npm install
-
Set up environment variables in a
.env
file based on the providedconfig/.env.example
.
To run the main application, use:
node src/app.js
Here's a brief example of how the software works:
- The program monitors incoming data for live scans and alerts.
- When new data is detected, it processes the data, including geocoding and payload validation.
- The processed data is then updated in the SQL database.
- Any errors encountered during processing are sent through a comprehensive flow.
The project extends Express middleware to enhance request validation and error handling. Custom middleware functions are used to validate HTTP methods, paths, and request bodies, ensuring that only valid data is processed.
Advanced error handling is implemented using custom error classes and middleware. Errors are categorized and handled based on their type, with specific responses and logging mechanisms in place. Critical errors trigger email notifications for immediate awareness.
Data processing involves several steps:
- Payload Validation: Incoming data is validated against predefined schemas to ensure it meets the required format.
- Geocoding: The Fetch API is used to make HTTP requests to the OpenStreetMap Nominatim service for reverse geocoding.
- Database Interaction: Processed data is updated in the SQL database using parameterized queries to prevent SQL injection.
Comprehensive logging is implemented to track the flow of data and capture any errors or anomalies. Logs are stored in a structured format for easy analysis and debugging.
Email notifications are sent for critical errors using the SendGrid API. This ensures that any significant issues are promptly reported and can be addressed in a timely manner.
Main application file that sets up the Express server and routes.
Contains middleware for the beginning and end of request processing.
Common utility functions and constants used throughout the project.
Controllers for handling business logic and orchestrating operations.
Email notification functionality using SendGrid.
Error handling classes and functions to manage and log errors.
Middleware extenders for additional functionality.
Handlers for specific operations such as SQL queries.
Middleware for request validation and processing.
Database models and schemas for interacting with the SQL database.
API routes for handling HTTP requests.
Services for processing data, including geocoding and payload validation.
Data storage and management classes.
Contributions are welcome! Please open an issue or submit a pull request.
This project includes code for geocoding from OpenStreetMap.
Your Name
This project is licensed under the GNU General Public License. See the LICENSE
file for details.