As AI becomes more critical in decision-making systems, tracking AI safety incidents is essential. Here’s a simple RESTful API to log, retrieve, and manage such incidents using Node.js, Express, and MongoDB.

Workflow of Api

🔧 Features

  • Log incidents with title, description, and severity.
  • Retrieve all or specific incidents.
  • Delete incidents.
  • Input validation with Joi.
  • MongoDB (Mongoose) for data storage.
  • Custom error handling.
  • CORS support.

🚀 Quick Start

1. Clone & Install

git clone https://github.com/surendergupta/AI-Safety-Incident-Log-Service.git
cd AI-Safety-Incident-Log-Service
npm install

Install required packages:

npm i cors dotenv express http-status joi mongoose path
npm i nodemon --save-dev

Installed packages

2. Setup .env

PORT=5000
MONGO_URI=mongodb://localhost:27017/ai_safety_log_api_db
NODE_ENV=development

3. Run the Server

npm run dev

Server will be live at: http://localhost:5000

🔁 Endpoints

✅ GET /incidents

Get all logged incidents.

📝 POST /incidents

{
  "title": "System Crash",
  "description": "AI failed due to memory leak.",
  "severity": "High"
}

Output

Incident Create

🔍 GET /incidents/:id

❌ DELETE /incidents/:id

🧠 Schema

const incidentSchema = new mongoose.Schema({
  title: String,
  description: String,
  severity: { type: String, enum: ["Low", "Medium", "High"] }
}, { timestamps: true });

✅ Why This Project?

  • 🚦 Demonstrates validation with Joi.
  • 🚫 Handles errors cleanly.
  • 📦 Uses scalable document storage (MongoDB).
  • 🧪 Great for API testing, learning, or as a boilerplate.

Check it out 👉

AI Safety Incident Log Service

Overview

This is a simple RESTful API service built with Node.js, Express.js, and MongoDB to log and manage AI safety incidents.

Flow of the API

Backend Flow Diagram

Features

  • Create, retrieve, and delete AI safety incidents.
  • Uses MongoDB for persistent storage.
  • MongoDB as the database with Mongoose ORM.
  • Request validation using Joi.
  • Implements basic validation and error handling.
  • API error handling with custom error classes.
  • Supports CORS for cross-origin requests.

Prerequisites

  • Node.js (>= 14.x recommended)
  • MongoDB (running locally or in the cloud, e.g., MongoDB Atlas)

Clone the Repository

git clone https://github.com/surendergupta/AI-Safety-Incident-Log-Service.git
cd AI-Safety-Incident-Log-Service
Enter fullscreen mode Exit fullscreen mode

Install Dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

Install Packages

npm i cors
npm i dotenv --save
npm i express
npm i http-status
npm i joi
npm i mongoose
npm i nodemon --save-dev
npm i path
Enter fullscreen mode Exit fullscreen mode

npm list

Set Up Environment

Create a .env file in the project root with:

PORT=5000
MONGO_URI=mongodb://localhost:27017/ai_safety_log_api_db  # Update this if using
Enter fullscreen mode Exit fullscreen mode

✨ Thank you for reading! ✨ I hope this article helped simplify the process and gave you valuable insights. As I continue to explore the ever-evolving world of technology, I’m excited to share more guides, tips, and updates with you. 🚀 Stay tuned for more content that breaks down complex concepts and makes them easier to grasp. Let’s keep learning and growing together! 💡

Found this useful? Give it a ❤️ or leave a comment with suggestions!