Overview:
This is a console-based Critical Event Alert System. It allows users to:
- Register new alerts with critical severity. 2.View all registered critical alerts.
- Exit the application. It integrates security validation, logging, and metrics tracking using modular components.
App.java (Main Class / Entry Point):
Continuously displays a menu for the user:
Option 1: Register a new alert (user inputs a message).
Option 2: View all critical alerts.
Option 3: Exit the program.
Uses:
Scanner
to read user input.
AlertService
to manage alert creation and retrieval.
CSRFTokenValidator
to simulate security check before accepting alert.
LoggingUtil
to log activity.
MetricsPublisher
to simulate tracking metrics (e.g., alert registration count).
AlertService.java (Business Logic Layer):
Stores all alerts in memory.
Allows registering new alerts.
Can retrieve only alerts marked with "CRITICAL" severity.
CSRFTokenValidator.java (Security Utility):
Simple static class that checks if a token equals"
secure-token
".
Used to simulate protection against Cross-Site Request Forgery (CSRF) attacks.
LoggingUtil.java (Observability - Logging): Logs messages to the console with
[LOG]
prefix.
Used to track events like alert registration.
MetricsPublisher.java (Observability - Metrics):
Prints a metric to the console with
[METRIC]
prefix.
Used to simulate publishing a metric when an alert is registered.
Alert.java (Data Model): Represents an alert object with:
A message (e.g. "Disk failure detected"). A severity level (hardcoded to
"CRITICAL�
). Overrides
toString()
to print alert details in format:
[CRITICAL] message
.
Design Highlights: Modular design with clear separation of concerns:
UI/Input:
App.java
Business logic:
AlertService
Security:
CSRFTokenValidator
Observability:
LoggingUtil
,
MetricsPublisher
Data model:
Alert
Good practices used:
Simple CSRF validation simulation.
In-memory alert filtering.
Logging and metric output for observability.
Suitable as a starter project or coding demo for showcasing architecture, observability, and secure design patterns.
----------- Entry Point ----------------
package com.mickeymuller;
import java.util.Scanner;
import com.mickeymuller.model.Alert;
import com.mickeymuller.observability.LoggingUtil;
import com.mickeymuller.observability.MetricsPublisher;
import com.mickeymuller.security.CSRFTokenValidator;
import com.mickeymuller.service.AlertService;
public class App {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
AlertService alertService = new AlertService();
while (true) {
System.out.println("\n--- Critical Event Alert System ---");
System.out.println("1. Register New Alert");
System.out.println("2. Show Critical Alerts");
System.out.println("3. Exit");
System.out.print("Enter choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
handleRegisterAlert(alertService, scanner);
break;
case 2:
for (Alert alert : alertService.getCriticalAlerts()) {
System.out.println(alert);
}
break;
case 3:
System.exit(0);
default:
System.out.println("Invalid choice.");
}
}
}
private static void handleRegisterAlert(AlertService alertService, Scanner scanner) {
System.out.print("Enter alert message: ");
String message = scanner.nextLine();
Alert alert = new Alert(message, "CRITICAL");
if (CSRFTokenValidator.validate("secure-token")) {
alertService.registerAlert(alert);
LoggingUtil.log("Registered new alert: " + message);
MetricsPublisher.publish("alert.registered");
} else {
System.out.println("CSRF validation failed. Alert not registered.");
}
}
}
------------- End ----------------
------------- Alert Service ---------
package com.mickeymuller.service;
import java.util.ArrayList;
import java.util.List;
import com.mickeymuller.model.Alert;
public class AlertService {
private final List<Alert> alerts = new ArrayList<>();
public void registerAlert(Alert alert) {
alerts.add(alert);
}
public List<Alert> getCriticalAlerts() {
List<Alert> critical = new ArrayList<>();
for (Alert alert : alerts) {
if ("CRITICAL".equals(alert.getSeverity())) {
critical.add(alert);
}
}
return critical;
}
}
------------- End --------------------
------------ Token Validator -----------
package com.mickeymuller.security;
public class CSRFTokenValidator {
public static boolean validate(String token) {
// Simulate token check
return "secure-token".equals(token);
}
}
--------- End ----------------
--------- Logging Util---------
package com.mickeymuller.observability;
public class LoggingUtil {
public static void log(String message) {
System.out.println("[LOG] " + message);
}
}
----------- End ----------
-------- Metric Publisher -------
package com.mickeymuller.observability;
public class MetricsPublisher {
public static void publish(String metric) {
System.out.println("[METRIC] Published: " + metric);
}
}
----------- End --------------
------------ Model -------------
package com.mickeymuller.model;
public class Alert {
private String message;
private String severity;
public Alert(String message, String severity) {
this.message = message;
this.severity = severity;
}
public String getMessage() {
return message;
}
public String getSeverity() {
return severity;
}
@Override
public String toString() {
return "[" + severity + "] " + message;
}
}
Top comments (139)
Impressive breakdown of the Critical Event Alert System! The modular design and separation of concerns make it easy to understand and scale. Love the inclusion of security validation and metrics tracking. Great job on the code structure and documentation.
I like how this project sneaks in real-world architecture lessons under the hood of a simple console app. The CSRF token check feels like a playful nod to web security, yet it trains your mindset for layered defenses. Feels like a neat “mini enterprise app” without over-engineering.
Really appreciate the clarity and modular structure of this Java Alert System. The integration of CSRF validation, logging, and metrics makes it a great example of secure and observable design—perfect for learners and pros alike
Great post! I love how this console-based Critical Event Alert System is built with a clean modular architecture—separating UI (App.java), business logic (AlertService), security (CSRFTokenValidator), observability (LoggingUtil and MetricsPublisher), and the data model (Alert). It’s a fantastic starter project for anyone wanting to demonstrate best practices like security simulation, logging, metrics, and in-memory filtering.
This is an excellent example of a well-architected console application that demonstrates key software engineering principles in a clean, modular way. The separation of concerns between UI, business logic, security, and observability components is particularly impressive for a demo project. The inclusion of CSRF validation simulation, logging, and metrics tracking makes this more than just a simple alert system - it's a great teaching tool for showcasing secure design patterns and observability practices.
The sophisticated design and modular structure of this Java alert system is truly exemplary. The combination of CSRF protection for security, along with a smart combination of logging and metrics, makes it not only an effective, but also a reliable and observable solution. It is a great example to learn from for everyone, whether you are a student or an experienced developer.
Really appreciate the clarity and modular structure of this Java Alert System. The integration of CSRF validation, logging, and metrics makes it a great example of secure and observable design—perfect for learners and pros alike. Keep it up man.
A clean & modular Java Alert System showcasing security, logging, and metrics in action 🚨 With CSRF validation, in-memory alert management, and observability baked in, it’s a solid starter project for learning scalable design patterns.
I like how clear and modular this project is. Perfect for learning best practices in Java while simulating real-world security and monitoring scenarios. Also Your step-by-step approach makes it easy to follow and implement really thank you for sharing this post
Really appreciate the clarity and modular structure of this Java Alert System. The integration of CSRF validation, logging, and metrics makes it a great example of secure and observable design—perfect for learners and pros alike