-
Notifications
You must be signed in to change notification settings - Fork 0
Setup‐Guide
DHANUSH G edited this page Mar 4, 2026
·
1 revision
Back to Home | Architecture | API-Reference
Before you begin, ensure you have the following installed:
| Requirement | Version | Check |
|---|---|---|
| Python | 3.9 or higher | python --version |
| Node.js | 18.0 or higher | node --version |
| npm | 8.0 or higher | npm --version |
| Git | Any recent version | git --version |
git clone https://github.com/DHANUSHGCODE/AI-Powered-Security-Monitoring-Threat-Detection-Platform.git
cd AI-Powered-Security-Monitoring-Threat-Detection-Platformcd backend
# Create virtual environment
python -m venv venv
# Activate — Windows
venv\Scripts\activate
# Activate — macOS / Linux
source venv/bin/activatepip install -r requirements.txtKey packages installed:
-
fastapi— Web framework -
uvicorn— ASGI server -
sqlalchemy— ORM -
scikit-learn— ML model -
pandas,numpy— Data processing -
pydantic— Request validation -
pytest,httpx— Testing
From the root directory of the project:
python ai-model/train_model.pyThis will:
- Generate synthetic log data →
data/generated_logs.csv - Train an Isolation Forest model
- Save the model →
ai-model/isolation_forest_model.pkl
Note: The model must be trained before starting the backend server, otherwise
/predict/calls will return a 503 error.
From the root directory:
uvicorn backend.main:app --reload --port 8000| URL | Purpose |
|---|---|
http://localhost:8000 |
Base API URL |
http://localhost:8000/docs |
Interactive Swagger UI |
http://localhost:8000/redoc |
ReDoc API documentation |
You should see:
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process
INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.
Open a new terminal and run:
cd frontend
npm install
npm run devThe Next.js dashboard will be available at:
http://localhost:3000
Ensure the backend is running on port 8000 before starting the frontend, as the dashboard fetches data from the API.
From the root directory:
# Set PYTHONPATH so backend module imports work
export PYTHONPATH=. # macOS / Linux
set PYTHONPATH=. # Windows CMD
$env:PYTHONPATH="." # Windows PowerShell
# Run all tests
pytest backend/tests/ -v
# Run specific test file
pytest backend/tests/test_logs.py -v
# Run with coverage
pytest backend/tests/ --cov=backend --cov-report=term-missingExpected output:
backend/tests/test_health.py::test_health_root PASSED
backend/tests/test_logs.py::test_create_log_success PASSED
backend/tests/test_logs.py::test_list_logs_success PASSED
... (all tests passing)
Docker Compose support is on the roadmap. Once available:
# Build and start all services
docker-compose up --build
# Services:
# - backend: http://localhost:8000
# - frontend: http://localhost:3000Create a .env file in the backend/ directory for configuration:
# Database
DATABASE_URL=sqlite:///./security_logs.db
# For PostgreSQL (production):
# DATABASE_URL=postgresql://user:password@localhost:5432/security_db
# Model
MODEL_PATH=ai-model/isolation_forest_model.pkl
# API
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=true# Always run from the root directory with PYTHONPATH set:
export PYTHONPATH=.
pytest backend/tests/# Model not trained. Run:
python ai-model/train_model.py# Kill existing process:
lsof -ti:8000 | xargs kill # macOS/Linux
netstat -ano | findstr :8000 # Windows (then taskkill /PID <pid> /F)- Ensure backend is running on
http://localhost:8000 - Check browser console for CORS errors
- Verify
NEXT_PUBLIC_API_URLinfrontend/.env.localif configured
Back to Home | Architecture | Next: API-Reference