An AI-powered threat monitoring system that automatically processes real-world news articles to identify, categorize, and track security threats. Built with Python, FastAPI, and Google's Gemini AI.
- Automated Threat Detection: Processes news articles hourly using Google's Gemini AI to identify potential threats
- Smart Filtering: AI analyzes threat level (1-10), category, confidence scores, and provides detailed summaries
- Duplicate Prevention: Automatically filters out previously analyzed articles to optimize API usage
- REST API: 8+ endpoints for threat retrieval, filtering, and human review
- Human-in-the-Loop: Review system with override capabilities for AI assessments
- Rolling Database: Automatically maintains a 5-day window of current threats
- Scheduled Monitoring: Runs every hour to keep threat intelligence up-to-date
NewsAPI β Data Pipeline β Gemini AI Analysis β SQLite Database β FastAPI Endpoints
β β
Duplicate Check Human Review System
- Backend: Python 3.13, FastAPI
- Database: SQLite, SQLAlchemy ORM
- AI: Google Gemini 2.0 Flash
- News Source: NewsAPI
- Validation: Pydantic
- Scheduling: APScheduler
- Server: Uvicorn
- Python 3.13+
- NewsAPI API Key (Get one here)
- Google Gemini API Key (Get one here)
- Clone the repository
git clone https://github.com/aamogh16/shield-threat-analysis.git
cd shield-threat-analysis- Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Set up environment variables
Create a .env file in the root directory:
NEWS_API_KEY=your_newsapi_key_here
GEMINI_API_KEY=your_gemini_key_here- Initialize the database
python scripts/create_tables.pyuvicorn app.main:app --reloadAccess the interactive API documentation at http://127.0.0.1:8000/docs
One-time execution:
python scripts/full_threat_pipeline.pyScheduled hourly monitoring:
python scripts/full_threat_pipeline.py
# The scheduler runs continuously, processing threats every hourpython -m tests.test_pipelineGET /- Health check and system statusGET /api/threats- Get all threatsGET /api/threats/count- Get total threat countGET /api/threats/{threat_id}- Get specific threat by ID
GET /api/threats/recent?days=3- Get threats from last N daysGET /api/threats/level/{min_level}- Get threats at or above threat levelGET /api/threats/search?q=keyword- Search threats by keywords
GET /api/threats/fury-overview- Director Fury's executive overviewGET /api/threats/pending_review- Get threats needing human reviewPUT /api/threats/{threat_id}/review- Submit human review/override
- Retrieves top headlines from NewsAPI (US focus)
- Can be configured for multiple countries/categories
- Checks article URLs against database
- Prevents redundant API calls and processing
- Sends articles to Gemini AI for threat assessment
- Batch processes up to 20 articles per request for efficiency
- AI evaluates: threat level, category, confidence, summary, keywords
- Only stores articles identified as threats (level 3+)
- Maintains both AI assessments and optional human overrides
- Auto-cleans threats older than 5 days
- Low-confidence threats flagged for review
- Humans can override AI assessments
- Full audit trail maintained
- Article Info: title, description, source, URL, published date
- AI Analysis: threat_level, category, summary, confidence, keywords, reason
- Human Override: human_threat_level, category, notes, reviewer, review date
- Metadata: created_at, updated_at, is_active, requires_review
shield-threat-analysis/
βββ app/
β βββ main.py # FastAPI application & endpoints
β βββ database.py # Database configuration
β βββ models/
β β βββ threat.py # SQLAlchemy Threat model
β βββ schemas/
β β βββ threat.py # Pydantic validation schemas
β βββ services/
β βββ news_fetcher.py # NewsAPI integration
β βββ ai_analyzer.py # Gemini AI integration
β βββ threat_processor.py # Core processing logic
βββ scripts/
β βββ create_tables.py # Database initialization
β βββ full_threat_pipeline.py # Automated monitoring
βββ tests/
β βββ test_pipeline.py # Pipeline testing
βββ .env # Environment variables
βββ requirements.txt # Python dependencies
βββ README.md
- API keys stored in environment variables
- Database includes soft-delete functionality
- Human review system for oversight
- Rate limiting on external APIs
- Deploy to cloud platform (Railway/Render)
- Add WebSocket for real-time threat notifications
- Implement user authentication
- Add data visualization dashboard
- Expand to multiple news sources
- Add threat trending analysis
- Email notifications for high-priority threats
This is a personal project, but feedback and suggestions are welcome! Feel free to open an issue or submit a pull request.
This project is open source and available under the MIT License.
Amogh Athimamula
- GitHub: @aamogh16
- LinkedIn: Amogh Athimamula
- Email: athimamula.a@northeastern.edu
- NewsAPI for providing real-time news data
- Google Gemini AI for advanced threat analysis
- Northeastern University for academic support
- Marvel's S.H.I.E.L.D. for the inspiration π¦
Built with β€οΈ by Amogh Athimamula | Northeastern University CS '28