A hackathon-ready AI-powered threat detection web app. Analyzes text, URLs, and messages for phishing, scams, manipulation tactics, and malicious content.
cd ai-guardiannpm installcp .env.example .envOpen .env and add your API key(s):
PORT=3000
OPENAI_API_KEY=sk-... # Recommended – best accuracy
HUGGINGFACE_API_KEY=hf_... # Fallback optionNo API keys? The app still works with a built-in heuristic engine (keyword-based detection). Great for demos!
# Production
npm start
# Development (auto-reload)
npm run devhttp://localhost:3000
ai-guardian/
├── server.js # Express server + API routes
├── config/
│ └── db.js # JSON file DB (MongoDB-ready)
├── public/
│ ├── index.html # Single-page frontend
│ ├── style.css # Full UI styles (dark/light mode)
│ └── script.js # Frontend logic
├── data/
│ └── scans.json # Auto-created scan history
├── package.json
├── .env.example
└── README.md
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/analyze |
Analyze input, auto-saves to history |
GET |
/api/history |
Fetch all scan history |
POST |
/api/history |
Manually save a scan |
DELETE |
/api/history/:id |
Delete a scan by ID |
GET |
/api/stats |
Summary statistics |
// Request
{ "input": "Your account will be suspended. Click here." }
// Response
{
"success": true,
"scan": {
"id": "uuid",
"input": "...",
"result": {
"status": "Malicious",
"confidence": 94,
"explanation": "...",
"keywords": ["suspended", "click", "urgent"]
},
"timestamp": "2024-01-01T00:00:00.000Z"
}
}- 🤖 AI Analysis – OpenAI GPT-4o-mini / HuggingFace / Heuristic fallback
- 🎨 Dark/Light Mode – Toggle with preference saved
- 📊 Risk Meter – Animated 0–100% progress bar (green/yellow/red)
- 📜 Scan History – View, click to re-display, delete
- 🔔 Toast Notifications – Success/error feedback
- 🔊 Voice Alert – Browser TTS (+ ElevenLabs optional) on malicious detection
- 📱 Responsive – Mobile-friendly layout
- 🔐 Rate Limiting – 30 req/min per IP
- Get an API key from elevenlabs.io
- Add to
.env:ELEVENLABS_API_KEY=your-key - In
public/script.js, setwindow.ELEVENLABS_API_KEY = 'your-key'(or inject via template)
In config/db.js, uncomment the MongoDB section at the bottom and comment out the JSON file section. Then set MONGO_URI in your .env.
