Data Models and ER Diagrams
Overview
The backend uses Pydantic models for data validation and schema definition, which map to Firestore documents.
Entity Relationship Diagram
erDiagram
User ||--o{ Request : "creates"
User ||--o{ Resource : "owns"
User ||--o{ Task : "assigned_to"
User ||--o{ Message : "sends"
User ||--o{ Observation : "reports"
Disaster ||--o{ Request : "associated_with"
Disaster ||--o{ Task : "part_of"
Disaster ||--o{ Observation : "context"
Disaster ||--o| ChatSession : "has"
ChatSession ||--o{ Message : "contains"
Request ||--o| Task : "triggers"
Task }|--|{ Resource : "utilizes"
User {
string uid PK
string email
string display_name
string role_id
GeoPoint location
}
Request {
string id PK
string disaster_id FK
string created_by FK
string type_of_need
string status
string assigned_task_id FK
GeoPoint location
}
Disaster {
string id PK
string name
string type
string severity
string chat_session_id
GeoPoint location
}
Task {
string id PK
string source_request_id FK
string disaster_id FK
string assigned_to FK
string status
int priority
string list_resource_ids
}
Resource {
string resource_id PK
string uid FK
string category
int quantity_available
string status
float location_lat
float location_lng
}
Message {
string id PK
string sender_id FK
string text
timestamp created_at
}
Observation {
string id PK
string disaster_id FK
string created_by FK
string title
string observation_type
float latitude
float longitude
}
WorkflowOutput {
string workflow_id PK
string request_id FK
datetime created_at
}
WorkflowTask {
string task_id PK
string workflow_id FK
string step
string priority
string approval_status
}
WorkflowResource {
string resource_id PK
string workflow_id FK
string resource_type
int total_quantity
string approval_status
}
Request ||--o| WorkflowOutput : "generates"
WorkflowOutput ||--|{ WorkflowTask : "suggests"
WorkflowOutput ||--|{ WorkflowResource : "recommends"
Schema Definitions
User (Collection: users)
| Field |
Type |
Description |
uid |
String |
Unique identifier (Firebase Auth UID). |
email |
String |
User's email address. |
display_name |
String |
User's full name. |
role_id |
String |
Role (admin, volunteer, responder, affected_individual). |
location |
GeoPoint |
Current location of the user. |
Request (Collection: requests)
| Field |
Type |
Description |
id |
String |
Unique identifier. |
disaster_id |
String |
Linked Disaster ID. |
created_by |
String |
User ID (UID) of the requester. |
type_of_need |
String |
E.g., food, medical, rescue. |
description |
String |
Detailed description of the need. |
status |
String |
open, in_progress, fulfilled, closed. |
assigned_task_id |
String |
ID of the task created to handle this request. |
media |
List[Media] |
List of image/video URLs. |
location |
GeoPoint |
Location where help is needed. |
Disaster (Collection: disasters)
| Field |
Type |
Description |
id |
String |
Unique identifier. |
name |
String |
Name of the event. |
description |
String |
Description of the event. |
type |
String |
E.g., Flood, Earthquake. |
severity |
String |
Severity level. |
affected_count |
Int |
Estimated number of people affected. |
chat_session_id |
String |
ID for the event's group chat. |
location |
GeoPoint |
Epicenter coordinates. |
Task (Collection: tasks)
| Field |
Type |
Description |
id |
String |
Unique identifier. |
source_request_id |
String |
ID of the request that triggered this task. |
disaster_id |
String |
Linked Disaster ID. |
assigned_to |
String |
UID of the volunteer/responder assigned. |
status |
String |
pending, on_route, completed, failed. |
priority |
Int |
1 (High), 2 (Medium), 3 (Low). |
instructions |
String |
Specific instructions for the responder. |
resource_ids |
List[String] |
IDs of resources allocated to this task. |
eta_minutes |
Int |
Estimated time of arrival. |
Resource (Collection: resources)
| Field |
Type |
Description |
resource_id |
String |
Unique identifier. |
uid |
String |
Owner's User ID. |
category |
String |
VEHICLE, FOOD, MEDICINE, etc. |
quantity_total |
Int |
Total quantity. |
quantity_available |
Int |
Currently available quantity. |
status |
String |
available, not_available. |
location_lat |
Float |
Latitude. |
location_lng |
Float |
Longitude. |
Message (Sub-collection of Chat)
| Field |
Type |
Description |
id |
String |
Unique identifier. |
sender_id |
String |
UID of the sender. |
text |
String |
Content of the message. |
created_at |
DateTime |
Timestamp. |
Observation (Collection: observations)
| Field |
Type |
Description |
id |
String |
Unique identifier. |
disaster_id |
String |
Linked Disaster ID. |
created_by |
String |
Reporter's User ID. |
title |
String |
Short title of the report. |
description |
String |
Detailed description. |
observation_type |
String |
Type of observation. |
urgency |
String |
Urgency level. |
image_urls |
List[String] |
Photos of the observation. |
latitude |
Float |
Location Latitude. |
longitude |
Float |
Location Longitude. |
WorkflowOutput (AI Generated Plans)
| Field |
Type |
Description |
workflow_id |
String |
Unique identifier (alias for workflow_run_id). |
request_id |
String |
ID of the request triggering this workflow. |
tasks |
List[WorkflowTask] |
List of suggested tasks. |
resource_suggestions |
List[WorkflowResource] |
List of suggested resources. |
manpower |
WorkflowManpower |
Estimated manpower requirements. |
created_at |
DateTime |
Timestamp of generation. |
WorkflowTask
| Field |
Type |
Description |
task_id |
String |
Unique identifier. |
step |
String |
Description of the task step. |
priority |
String |
Priority level (e.g., "High", "Medium"). |
approval_status |
String |
Status of moderation (pending, approved, etc.). |
WorkflowResource
| Field |
Type |
Description |
resource_id |
String |
Unique identifier. |
resource_type |
String |
Type of resource (e.g., "Food", "Medical Kit"). |
total_quantity |
Int |
Total quantity recommended. |
approval_status |
String |
Status of moderation. |
| Field |
Type |
Description |
user |
User |
User context (ID, Name, Role, Location). |
prompt |
String |
The user's message/query. |
chat_history |
List[ChatHistoryItem] |
Previous messages for context. |