A Comprehensive Cybersecurity Monitoring & Threat Detection Platform
A practical learning project exploring real-time security event logging, behavioral anomaly detection, and intelligent threat identification through database design and backend development.
- Project Overview
- The Problem We're Solving
- Our Approach
- Key Features
- Tech Stack
- How It's Built
- Database Design
- Getting Started
- API Documentation
- What We Learned
- Meet the Team
- About This Project
ThreatLens is a 4th-semester Database Management Systems (DBMS) capstone project from Ghulam Ishaq Khan Institute of Engineering Sciences and Technology.
We built this platform to explore how databases power real-world security applications. Instead of just studying theory, we designed a relational database system that actually detects threats, logs security events, and identifies suspicious patternsβall managed through a backend API.
This project combines database design principles, backend API development, and security best practices into one cohesive learning experience.
Imagine you're running an organization and you have no way to see what's happening:
- No Visibility β You don't know who logged in when, or from where
- Slow Detection β By the time you realize something's wrong, it's too late
- Missing Evidence β When a security incident happens, you can't investigate because there's no trail
- Invisible Red Flags β Unusual login times, strange IP addresses, privilege escalationsβall happening in the dark
- Chaos at Scale β Managing users across multiple departments with different roles gets messy fast
This is what we wanted to solve: How do we build a system that watches everything, learns what's normal, and alerts us when something's wrong?
We tackled this through proper database design and intelligent monitoring logic:
| Challenge | How We Solved It |
|---|---|
| No visibility into user activity | Built comprehensive event logging connected to real user sessions |
| Threats go unnoticed | Created automated alert rules that flag suspicious patterns |
| Can't investigate incidents | Designed immutable audit logs that capture every change |
| Don't know what's "normal" | Implemented behavioral analysis (off-hours logins, IP mismatches, etc.) |
| Managing multiple organizations | Used relational design with proper role-based access control |
The Result: A system that doesn't just store dataβit understands security.
π’ Organization & User Management
- Support multiple organizations completely isolated from each other
- Role-based access control (RBAC) so each person has exactly the permissions they need
- Secure user registration with bcrypt password hashing (no plaintext passwords!)
π Real-time Event Logging
- Every important security action gets logged automatically
- Rich metadata captured for investigation (who did it, when, from where)
- Immutable logsβonce written, they can't be changed or deleted
π€ Session Monitoring
- Track every login and active session
- Detect when the same user is logged in from impossible locations at the same time
- Manage session timeouts and automatic logouts
π¨ Smart Threat Detection
- Off-Hours Alerts β Flag logins happening at 3 AM when nobody should be working
- Location Anomalies β User logged in from New York at 2 PM, then Tokyo at 2:15 PM? That's impossible!
- Privilege Changes β Track when users get new permissions or lose access
- Concurrent Sessions β Catch when someone's account is being used in multiple places
- Access Control β Verify permissions before letting anyone do anything
π Alert Management
- Automatic alerts when threats are detected
- Track whether alerts are still open, being investigated, or resolved
- Full history of every alert change (another audit trail!)
π Security Analytics
- Query the database for trends and patterns
- Build user behavior profiles
- Categorize incidents by risk level
We chose technologies that are industry-standard and what we're learning in class:
| Component | Technology | Why We Chose It |
|---|---|---|
| Backend | Python 3.x + Flask | Easy to learn, great for APIs |
| Database | PostgreSQL | Enterprise-grade relational DB, free, powerful |
| Database Driver | psycopg2 | Direct connection to PostgreSQL |
| Security | bcrypt | Industry standard for password hashing |
| Config | Environment variables (.env) | Keeps secrets safe outside the code |
ThreatLens/
β
βββ π backend/ # The application logic
β βββ app.py # Main entry point
β βββ db.py # Database connection & queries
β βββ routes/ # API endpoints
β β βββ auth_routes.py # Register & login
β β βββ org_routes.py # Manage organizations
β β βββ user_routes.py # Manage users
β β βββ event_routes.py # Log & retrieve security events
β β βββ session_routes.py # Track active sessions
β β βββ threat_routes.py # Detect threats & create alerts
β βββ requirements.txt # Python packages we need
β βββ Credentials.env # Database login (don't commit this!)
β
βββ π database/ # The database structure
β βββ schema.sql # Database tables & relationships
β βββ triggers.sql # Automation rules in the database
β βββ queries.sql # Pre-built analysis queries
β βββ seed_data.sql # Sample data for testing
β
βββ π Files/ # Documentation & visuals
β βββ ThreatLens_ERD.png # How the database tables connect
β βββ ThreatLens_Complete_Workflow.pdf
β βββ ThreatLens.docx # Full technical report
β βββ USERS.xlsx # Example datasets
β
βββ README.md # You're reading this!
We designed our database around these key entities:
- Organizations β Each company is separate (multi-tenant design)
- Users β Employee profiles with authentication details
- Roles & Permissions β Fine-grained access control (not just "admin" or "user")
- Assets β The resources being protected (servers, files, etc.)
- Sessions β Who logged in, when, and from where
- Security Events β Everything that happens (logins, file access, permission changes)
- Alerts β Threats we've detected and flagged
- Audit Logs β A permanent record of every database change
Instead of writing code to update everything manually, we used database triggers:
- When someone logs in β automatically create a session record
- When we see suspicious activity β automatically create an alert
- When an alert status changes β automatically log that change
- These triggers ensure nothing is forgotten and everything is consistent
Everything connects for a complete picture:
- A session connects a user to a login event
- A login event connects to security events that happened during that session
- An alert connects to the events that triggered it
- Audit logs track when alerts change status
- Python 3.7 or newer
- PostgreSQL 12 or newer
- Git (to clone the repo)
- A text editor or IDE (VS Code, PyCharm, etc.)
Step 1: Get the Code
git clone https://github.com/Usman-Azhar/ThreatLens.git
cd ThreatLensStep 2: Set Up the Database
# Create a new database
createdb threatlens
# Load the database structure
psql -U your_username -d threatlens -f database/schema.sql
# Add the automation rules (triggers)
psql -U your_username -d threatlens -f database/triggers.sql
# Load some example data for testing
psql -U your_username -d threatlens -f database/seed_data.sqlStep 3: Configure Your Credentials
# Copy the template
cp backend/Credentials.env.example backend/Credentials.env
# Edit Credentials.env and add your database details:
# DB_HOST=localhost
# DB_PORT=5432
# DB_NAME=threatlens
# DB_USER=your_username
# DB_PASSWORD=your_passwordStep 4: Install Python Libraries
cd backend
pip install -r requirements.txtStep 5: Start the Server
python app.pyYour application is now running at http://localhost:5000 π
Here's what you can do with the API:
| What You Want | Endpoint | Method |
|---|---|---|
| Create a new account | /api/auth/register |
POST |
| Log in | /api/auth/login |
POST |
| View/create organizations | /api/organizations |
GET/POST |
| Manage users | /api/users |
GET/POST |
| Log security events | /api/events |
GET/POST |
| Check active sessions | /api/sessions |
GET |
| View detected threats | /api/threats |
GET |
Each endpoint returns clear responses with status codes that tell you if something worked or what went wrong.
If you want to dive deeper:
| Document | Location | Contains |
|---|---|---|
| Full Project Report | Files/ThreatLens.docx |
Everything we learned and did |
| System Workflows | Files/ThreatLens_Complete_Workflow.pdf |
Architecture diagrams and data flow |
| Database Definition | database/schema.sql |
The exact SQL table definitions |
| Test Data | Files/USERS.xlsx |
Example data to experiment with |
This isn't just a school projectβhere's how organizations actually use systems like this:
β
Security Teams β Monitor what employees access and when
β
Compliance Officers β Generate audit reports for regulatory requirements
β
Incident Response β When something goes wrong, investigate using complete logs
β
System Admins β Track who changed what permissions
β
Internal Auditors β Verify that security controls are actually working
If we were to keep developing this, here's what we'd add:
- Machine learning to detect truly weird patterns (not just rule-based alerts)
- Beautiful dashboard with graphs and real-time updates
- Connect to professional SIEM (Security Information & Event Management) platforms
- Push notifications to phones when critical threats appear
- Smarter threat correlation (connecting related events automatically)
- Automated response actions (block IPs, lock accounts, etc.)
We're three Cyber Security students from GIKI who built this together:
|
Usman Azhar @Usman-Azhar |
Fatima Ali @FatimaAlli |
Muhammad Abdullah @GhostByte101 |
What β A cybersecurity threat detection platform built on a relational database
Why β To learn how databases power real-world applications
When β 4th Semester, 2025-2026 Academic Year
Where β Ghulam Ishaq Khan Institute of Engineering Sciences and Technology (GIKIST)
Course β Database Management Systems (DBMS)
Type β Capstone Project
β¨ How to design databases that actually solve problems (not just store data)
β¨ Normalization, primary keys, foreign keys, and relational integrity
β¨ Database triggers and automation rules
β¨ Building APIs that talk to databases safely
β¨ Security practices (password hashing, access control, audit logging)
β¨ How enterprise applications really work behind the scenes
This project is shared for educational purposes. Feel free to learn from it, improve it, and adapt it for your own projects.
