Django REST API powering the IoT device explorer. Provides device and sector management, CVE enrichment, and AI‑assisted threat summaries via Ollama.
- API base: http://localhost:8080/api/
- Admin: http://localhost:8080/admin/
- Username:
admin - Password:
admin
- Username:
- Swagger UI: http://localhost:8080/docs/
- ReDoc: http://localhost:8080/redoc/redoc/
- Ollama: http://localhost:11434/
- API usage details: iot_backend/api.md
- Django, Django REST Framework
- SQLite
- Ollama for AI summaries
Run the backend by itself (useful for local development without the root compose):
cd iot_backend- Build and start:
docker compose up -d --build
- Stop:
docker compose down
Prerequisites:
- Python 3.11+ recommended
- pip
- Create and activate a virtual environment
- Windows PowerShell:
python -m venv venv-backend.\venv-backend\Scripts\Activate.ps1
- macOS/Linux:
python -m venv venv-backendsource venv-backend/bin/activate
- Install dependencies
pip install -r iot_backend/requirements.txt
- Configure environment
Create a .env file (loaded by settings) and enable debug.
- Windows PowerShell:
Set-Content -Path .\.env -Value 'DJANGO_DEBUG="True"'
- macOS/Linux:
printf 'DJANGO_DEBUG="True"\n' > .env
Optional environment variables:
DJANGO_DEBUG: True/False (default False in production)ALLOWED_HOSTS: e.g.localhost,127.0.0.1CORS_ALLOWED_ORIGINS: e.g.http://localhost:5173,http://localhost:4173OLLAMA_BASE_URL: e.g.http://localhost:11434(local) orhttp://ollama:11434(Docker)
- Migrate and run
python iot_backend/manage.py migratepython iot_backend/manage.py runserver 0.0.0.0:8080
Create a superuser (optional):
python iot_backend/manage.py createsuperuser
The backend can pull CVE/threat data and generate AI summaries via Ollama.
- Ensure an Ollama model is available (example: llama3.2):
- POST
http://localhost:11434/api/pullwith body{ "model": "llama3.2" } - More examples: iot_backend/api.md
- POST
Batch update enrichment:
- Management command:
python iot_backend/manage.py update_threats
- Utility script (optional):
python iot_backend/update_all_device_threats.py
Explore the schema and try requests:
- Swagger UI: http://localhost:8080/docs/
- ReDoc: http://localhost:8080/redoc/redoc/
- API root: http://localhost:8080/api/
iot_backend/manage.py— Django entry pointiot_backend/iot_backend/— project settings and URLsiot_backend/iot/— main app (models, serializers, views, signals, management commands)iot_backend/requirements.txt— Python depsiot_backend/dockerfile,iot_backend/docker-compose.yml— containerizationiot_backend/update_all_device_threats.py— optional utility script