-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md.backup
More file actions
358 lines (282 loc) Β· 9.85 KB
/
README.md.backup
File metadata and controls
358 lines (282 loc) Β· 9.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# Azure Disaster Response Platform
A comprehensive disaster response platform built on Azure, enabling users to report emergencies and disasters in real-time. The system uses Azure Functions for serverless backend processing, Cosmos DB for data storage, and Static Web Apps for hosting the frontend.
## ποΈ Architecture
```mermaid
graph TB
subgraph "Frontend Layer"
A[Static Web App<br/>Bootstrap 5 UI]
end
subgraph "API Layer"
B[Azure Functions v4<br/>Python 3.11]
B1[SubmitAlert Function<br/>HTTP POST]
end
subgraph "Data Layer"
C[Cosmos DB<br/>Serverless]
C1[DisasterResponseDB]
C2[Alerts Container]
end
subgraph "User"
U[Web Browser]
end
U -->|HTTPS| A
A -->|fetch API<br/>POST /api/SubmitAlert| B1
B1 -->|azure-cosmos SDK| C1
C1 --> C2
style A fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
style B1 fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
style C1 fill:#00d4aa,stroke:#333,stroke-width:2px,color:#fff
style C2 fill:#00d4aa,stroke:#333,stroke-width:2px,color:#fff
```
## π Features
- **Real-time Alert Submission**: Users can submit disaster alerts with location, type, and severity
- **Serverless Architecture**: Fully serverless design using Azure Functions and Cosmos DB
- **Responsive UI**: Modern Bootstrap 5 interface that works on all devices
- **Scalable Database**: Cosmos DB with serverless capacity for cost-effective scaling
- **CORS Enabled**: Secure cross-origin resource sharing for API calls
- **Infrastructure as Code**: Complete Bicep templates for automated deployment
## π οΈ Technology Stack
### Frontend
- **HTML5** with Bootstrap 5.3
- **JavaScript** (ES6+) with Fetch API
- **Bootstrap Icons** for visual elements
- **Responsive Design** for mobile and desktop
### Backend
- **Python 3.11** with Azure Functions v4
- **azure-cosmos** SDK for database operations
- **FastAPI** for additional REST API capabilities
- **HTTP Trigger** for RESTful API
- **CORS Support** for cross-origin requests
### Infrastructure
- **Azure Static Web Apps** (Free tier)
- **Azure Functions** (Consumption plan)
- **Azure Cosmos DB** (Serverless mode with Free tier)
- **Azure Storage Account** for Functions runtime
- **Bicep** for Infrastructure as Code
## π Project Structure
```
azure-disaster-response/
βββ SubmitAlert/ # Azure Function
β βββ __init__.py # Function logic (Python)
β βββ function.json # Function configuration
βββ index.html # Frontend UI
βββ requirements.txt # Python dependencies
βββ host.json # Function App configuration
βββ main.bicep # Infrastructure as Code
βββ README.md # This file
```
## π Getting Started
### Prerequisites
- [Azure Account](https://azure.microsoft.com/free/)
- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli)
- [Azure Functions Core Tools v4](https://docs.microsoft.com/azure/azure-functions/functions-run-local)
- [Python 3.11+](https://www.python.org/downloads/)
### Local Development
1. **Clone the repository**
```bash
git clone https://github.com/MUKARRAM-ONE/azure-disaster-response.git
cd azure-disaster-response
```
2. **Install dependencies**
```bash
pip install -r requirements.txt
```
3. **Configure local settings**
Create a `local.settings.json` file:
```json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"COSMOS_ENDPOINT": "https://your-cosmos-account.documents.azure.com:443/",
"COSMOS_KEY": "your-cosmos-key",
"COSMOS_DATABASE_ID": "DisasterResponseDB",
"COSMOS_CONTAINER_ID": "Alerts"
}
}
```
4. **Run the Function App locally**
```bash
func start
```
The function will be available at `http://localhost:7071/api/SubmitAlert`
5. **Update the frontend**
Edit `index.html` and change the `FUNCTION_URL` constant to point to your local endpoint:
```javascript
const FUNCTION_URL = 'http://localhost:7071/api/SubmitAlert';
```
6. **Open the frontend**
Open `index.html` in a web browser or serve it with a local web server.
## βοΈ Deployment
### Deploy Infrastructure
1. **Login to Azure**
```bash
az login
```
2. **Create a resource group**
```bash
az group create --name disaster-response-rg --location eastus
```
3. **Deploy the Bicep template**
```bash
az deployment group create \
--resource-group disaster-response-rg \
--template-file main.bicep \
--parameters environment=prod
```
4. **Get deployment outputs**
```bash
az deployment group show \
--resource-group disaster-response-rg \
--name main \
--query properties.outputs
```
### Deploy Function App
1. **Install dependencies (if not already done)**
```bash
pip install -r requirements.txt
```
2. **Deploy to Azure Functions**
```bash
func azure functionapp publish <function-app-name>
```
### Deploy Static Web App
1. **Update the FUNCTION_URL in index.html**
Replace the `FUNCTION_URL` constant with your Azure Function URL:
```javascript
const FUNCTION_URL = 'https://your-function-app.azurewebsites.net/api/SubmitAlert';
```
2. **Deploy using Azure CLI or GitHub Actions**
```bash
az staticwebapp create \
--name <static-web-app-name> \
--resource-group disaster-response-rg \
--source https://github.com/MUKARRAM-ONE/azure-disaster-response \
--location eastus \
--branch main \
--app-location "/" \
--output-location "/"
```
## π API Documentation
### Submit Alert Endpoint
**Endpoint:** `POST /api/SubmitAlert`
**Request Body:**
```json
{
"location": "San Francisco, CA",
"type": "earthquake",
"severity": "high"
}
```
**Request Fields:**
- `location` (string, required): Location of the disaster
- `type` (string, required): Type of disaster (earthquake, flood, fire, hurricane, tornado, landslide, tsunami, drought, other)
- `severity` (string, required): Severity level (low, medium, high, critical)
**Success Response (201):**
```json
{
"success": true,
"message": "Alert submitted successfully",
"data": {
"id": "1234567890-abc123",
"location": "San Francisco, CA",
"type": "earthquake",
"severity": "high",
"timestamp": "2026-01-06T16:30:00.000Z",
"status": "new"
}
}
```
**Error Response (400):**
```json
{
"error": "Missing required fields. Please provide location, type, and severity."
}
```
**Error Response (500):**
```json
{
"success": false,
"error": "Failed to save alert",
"details": "Error message details"
}
```
## ποΈ Database Schema
### Alerts Container
**Document Structure:**
```json
{
"id": "1234567890-abc123",
"location": "San Francisco, CA",
"type": "earthquake",
"severity": "high",
"timestamp": "2026-01-06T16:30:00.000Z",
"status": "new"
}
```
**Partition Key:** `/id`
**Indexing:** Automatic indexing on all paths for optimal query performance
## π Security Considerations
- **HTTPS Only**: All endpoints enforce HTTPS
- **CORS Configuration**: Currently allows all origins (*) for development. **IMPORTANT**: Update main.bicep line 178 to restrict to your Static Web App URL for production
- **Authentication**: Currently set to anonymous for easy testing. **IMPORTANT**: Update SubmitAlert/function.json line 4 to use 'function' or 'admin' level authentication for production
- **Key Management**: Cosmos DB keys stored as Function App settings (not exposed to client)
- **Minimal Permissions**: Functions use least-privilege access patterns
- **Input Validation**: All required fields validated before database operations
- **ID Generation**: Uses timestamp + random string (consider uuid package for production high-load scenarios)
## π° Cost Optimization
- **Cosmos DB**: Serverless mode with free tier (1000 RU/s, 25 GB storage)
- **Azure Functions**: Consumption plan (1M executions free/month)
- **Static Web Apps**: Free tier (100 GB bandwidth/month)
- **Storage Account**: Minimal costs for Functions runtime
**Estimated Monthly Cost**: $0-5 for low to moderate usage
## π§ͺ Testing
### Test the Function Locally
```bash
curl -X POST http://localhost:7071/api/SubmitAlert \
-H "Content-Type: application/json" \
-d '{
"location": "New York, NY",
"type": "flood",
"severity": "medium"
}'
```
### Test the Deployed Function
```bash
curl -X POST https://your-function-app.azurewebsites.net/api/SubmitAlert \
-H "Content-Type: application/json" \
-d '{
"location": "Los Angeles, CA",
"type": "fire",
"severity": "high"
}'
```
## π Future Enhancements
- [ ] Add user authentication with Azure AD B2C
- [ ] Implement real-time notifications using Azure SignalR
- [ ] Add geospatial queries for nearby disasters
- [ ] Create admin dashboard for alert management
- [ ] Integrate with mapping services (Azure Maps)
- [ ] Add SMS/Email notifications with Azure Communication Services
- [ ] Implement data analytics with Azure Synapse
- [ ] Add mobile app support (React Native)
## π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## π License
This project is licensed under the MIT License - see the LICENSE file for details.
## π₯ Authors
- **MUKARRAM-ONE** - Initial work
## π Acknowledgments
- Azure Functions documentation
- Bootstrap 5 framework
- Cosmos DB SDK team
- Azure community
## π Support
For support, please open an issue in the GitHub repository or contact the maintainers.
---
**Built with β€οΈ using Azure Cloud Services**