# π¨ Alerto24 - Emergency Response Platform
A real-time emergency response and alert system built with Django, GraphQL, and PostgreSQL. Connects citizens with emergency services through a modern API-first architecture.
[](https://www.djangoproject.com/)
[](https://graphql.org/)
[](https://www.postgresql.org/)
[](https://www.python.org/)
## π Table of Contents
- [Features](#-features)
- [Tech Stack](#-tech-stack)
- [Architecture](#-architecture)
- [Quick Start](#-quick-start)
- [API Documentation](#-api-documentation)
- [Database Models](#-database-models)
- [Development](#-development)
- [Testing](#-testing)
- [Deployment](#-deployment)
- [Contributing](#-contributing)
- [License](#-license)
## β¨ Features
### π¨ Emergency Management
- Real-time emergency reporting with geolocation
- Multiple emergency types: Medical, Fire, Police, Accidents, Natural Disasters
- Priority levels (Low β Medium β High β Critical)
- Anonymous reporting support
- Multimedia attachments (photos, documents)
- Patient medical information storage
### π₯ User System
- Multi-type user roles: Citizen, Provider, First Responder, Admin
- Emergency contacts and medical profiles
- Location tracking and status indicators
- Push notification preferences
- Blood type and medical condition storage
### π₯ Provider Network
- Verified emergency service providers
- Service type classification (Ambulance, Fire Truck, Police, etc.)
- Real-time availability status
- Performance metrics and ratings
- Geographic service coverage
- Scheduling and capacity management
### π§ Technical Features
- Modern GraphQL API with real-time capabilities
- JWT authentication and authorization
- PostgreSQL with JSON field support
- Comprehensive error handling
- Health monitoring endpoints
- Docker containerization
- Extensive testing suite
## π Tech Stack
### Backend
- **Framework**: Django 4.2+
- **API**: GraphQL (graphene-django)
- **Authentication**: JWT (graphql-jwt)
- **Database**: PostgreSQL 18.1
- **Task Queue**: Celery (planned)
- **Real-time**: WebSockets (planned)
### Frontend (Future)
- **Mobile**: React Native / Flutter
- **Web Dashboard**: React.js / Next.js
- **Maps**: Mapbox / Google Maps API
### DevOps
- **Container**: Docker & Docker Compose
- **CI/CD**: GitHub Actions
- **Monitoring**: Prometheus + Grafana (planned)
## π Architecture
Alerto24 Architecture βββ API Layer (GraphQL) β βββ Queries (Read operations) β βββ Mutations (Write operations) β βββ Subscriptions (Real-time updates - planned) βββ Business Logic β βββ Emergency Dispatch System β βββ Provider Matching Algorithm β βββ Notification Service β βββ Location Services βββ Data Layer β βββ PostgreSQL Database β βββ Redis Cache (planned) β βββ File Storage (S3/MinIO) βββ Client Applications βββ Citizen Mobile App βββ Provider Mobile App βββ Admin Web Dashboard
## π Quick Start
### Prerequisites
- Python 3.9+
- PostgreSQL 14+ (or Docker)
- Node.js 16+ (for frontend development)
- Git
### 1. Clone the Repository
```bash
git clone https://github.com/yourusername/alerto24.git
cd alerto24/backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtcp .env.example .env
# Edit .env with your configurationRequired environment variables:
# Django
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# Database
POSTGRES_DB=alerto24
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432# Start PostgreSQL container
docker run --name alerto24-postgres \
-e POSTGRES_DB=alerto24 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=123456 \
-p 5432:5432 \
-d postgres:latest
# Verify it's running
docker ps | grep postgres# Create database
createdb alerto24
# Or via psql
psql -U postgres -c "CREATE DATABASE alerto24;"python manage.py makemigrations
python manage.py migratepython manage.py createsuperuser# Create realistic test data
python scripts/testing/create_alerto_test_data.pypython manage.py runserverVisit:
- API Explorer: http://localhost:8000/graphql/
- Admin Panel: http://localhost:8000/admin/
- Health Check: http://localhost:8000/health/
POST http://localhost:8000/graphql/
# Get JWT token
mutation {
tokenAuth(username: "admin", password: "admin123") {
token
refreshToken
user {
id
username
email
}
}
}
# Use token in headers
Authorization: JWT <your_token_here>query {
emergencies {
id
code
emergencyType
priority
status
city
latitude
longitude
isAnonymous
createdAt
user {
firstName
lastName
phone
}
}
}query {
providers(status: "AVAILABLE") {
id
user {
firstName
lastName
email
}
serviceTypes
status
latitude
longitude
rating
vehicleType
vehicleCapacity
maxDistance
}
}mutation {
createEmergency(
emergencyType: "medical"
latitude: 14.5995
longitude: 120.9842
priority: "high"
description: "Chest pain and difficulty breathing"
city: "Manila"
) {
emergency {
id
code
emergencyType
priority
status
latitude
longitude
createdAt
}
}
}query {
emergencyStats {
total
byType {
type
count
}
byStatus {
status
count
}
byCity {
city
count
}
}
}class User(AbstractUser):
# Custom fields
phone = models.CharField(max_length=20, unique=True)
user_type = models.CharField(max_length=20) # CITIZEN, PROVIDER, ADMIN
emergency_contacts = models.JSONField()
medical_info = models.JSONField()
blood_type = models.CharField(max_length=5)
last_known_location = models.CharField(max_length=100)
is_online = models.BooleanField(default=False)class Emergency(models.Model):
code = models.CharField(max_length=50, unique=True)
user = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
provider = models.ForeignKey(Provider, null=True, on_delete=models.SET_NULL)
emergency_type = models.CharField(max_length=50) # medical, fire, police
priority = models.CharField(max_length=20) # low, medium, high, critical
status = models.CharField(max_length=20) # pending, dispatched, arrived, resolved
latitude = models.FloatField()
longitude = models.FloatField()
address = models.TextField()
city = models.CharField(max_length=100)
symptoms = models.JSONField()
patient_info = models.JSONField()
attachments = models.JSONField()
is_anonymous = models.BooleanField(default=False)class Provider(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
service_types = models.JSONField() # [AMBULANCE, FIRE_TRUCK, POLICE_CAR]
status = models.CharField(max_length=20) # AVAILABLE, ON_DUTY, IN_EMERGENCY
latitude = models.FloatField()
longitude = models.FloatField()
certification_level = models.CharField(max_length=50)
is_verified = models.BooleanField(default=False)
rating = models.DecimalField(max_digits=3, decimal_places=2)
total_emergencies = models.IntegerField(default=0)
completed_emergencies = models.IntegerField(default=0)
vehicle_type = models.CharField(max_length=50)
vehicle_capacity = models.IntegerField(default=1)alerto24/
βββ backend/ # Django backend
β βββ config/ # Project configuration
β β βββ settings.py # Django settings
β β βββ urls.py # URL routing
β β βββ schema.py # GraphQL schema
β βββ emergencies/ # Emergency management app
β βββ providers/ # Provider management app
β βββ users/ # Custom user management
β βββ scripts/ # Utility scripts
β βββ manage.py
βββ frontend/ # React frontend (planned)
βββ docker-compose.yml # Multi-container setup
βββ Dockerfile # Backend container
βββ requirements.txt # Python dependencies
βββ README.md # This file
# Run all tests
python manage.py test
# Run specific app tests
python manage.py test emergencies
# Run with coverage
coverage run manage.py test
coverage report# Run linter
flake8 .
# Check imports
isort --check-only .
# Type checking
mypy .# Create migrations
python manage.py makemigrations
# Apply migrations
python manage.py migrate
# Check migration status
python manage.py showmigrations
# Create database backup
python manage.py dumpdata --indent 2 > backup.json
# Load database backup
python manage.py loaddata backup.json# Generate comprehensive test data
python scripts/testing/create_alerto_test_data.py
# Generate minimal test data
python scripts/testing/create_minimal_data.py
# Clear test data
python scripts/testing/clear_test_data.py# Test GraphQL endpoints
python scripts/testing/test_graphql_endpoints.py
# Test authentication
python scripts/testing/test_auth.py
# Load test with k6 (planned)
k6 run scripts/load_tests/emergency_report.js# Test emergency creation
curl -X POST http://localhost:8000/graphql/ \
-H "Content-Type: application/json" \
-d '{"query": "mutation { createEmergency(emergencyType: \"medical\", latitude: 14.5, longitude: 121.0) { emergency { code } } }"}'
# Test provider query
curl -X POST http://localhost:8000/graphql/ \
-H "Content-Type: application/json" \
-d '{"query": "{ providers { user { firstName } serviceTypes status } }"}'# Build and run with Docker Compose
docker-compose up --build
# Run in background
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down- Set
DEBUG=Falsein production - Configure proper
ALLOWED_HOSTS - Set up HTTPS with SSL certificates
- Configure production database (AWS RDS, etc.)
- Set up monitoring (Prometheus, Grafana)
- Configure backup strategy
- Set up CI/CD pipeline
- Configure error tracking (Sentry)
- Set up logging aggregation
# Required
SECRET_KEY=your-production-secret-key
DEBUG=False
DATABASE_URL=postgres://user:password@host:port/database
ALLOWED_HOSTS=alerto24.com,api.alerto24.com
# Optional but recommended
REDIS_URL=redis://localhost:6379/0
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your-email-password
SENTRY_DSN=your-sentry-dsn- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
python manage.py test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 for Python code
- Use descriptive variable names
- Write docstrings for functions and classes
- Add type hints where applicable
- Write tests for new features
- Update documentation for API changes
feature/- New featuresbugfix/- Bug fixeshotfix/- Critical production fixesrelease/- Release preparationdocs/- Documentation updates
This project is licensed under the MIT License - see the LICENSE file for details.
- Django community for the excellent web framework
- GraphQL community for the flexible API specification
- PostgreSQL team for the robust database system
- All contributors who help improve Alerto24
For support, please:
- Check the documentation
- Search existing issues
- Create a new issue with detailed information
- Website: https://alerto24.com
- API Documentation: https://docs.alerto24.com/api
- Issue Tracker: https://github.com/yourusername/alerto24/issues
- Changelog: https://github.com/yourusername/alerto24/releases
This comprehensive README includes:
- Project overview with badges
- Detailed features of the emergency response system
- Complete tech stack information
- Quick start guide with step-by-step instructions
- API documentation with GraphQL examples
- Database model explanations
- Development guidelines and project structure
- Testing instructions with scripts
- Deployment checklist for production
- Contributing guidelines and coding standards
- License information and acknowledgments