Skip to content

Repository files navigation

Here is the updated README.md tailored for your deployed production environment on Railway.

CRISISDESK-API

An intelligent, multilingual crisis management and triage backend designed for high-availability production environments. The system leverages AI-driven classification, geospatial weather enrichment, and semantic deduplication to process and categorize emergency reports in real-time.


🏗 System Architecture

The application follows Clean Architecture principles, isolating business logic from routing and data layers.

  • Ingress & Routing: FastAPI asynchronous endpoints with built-in Pydantic v2 schema validation and SlowAPI IP-based rate limiting.
  • Intelligence Layer (AI Service): Integrates with LLMs (e.g., Gemini) for natural language processing, automated urgency classification, and multilingual translation (English/Bangla).
  • Geospatial Enrichment (Weather Service): Dynamically fetches real-time meteorological data and flood risk analysis via OpenWeatherMap API based on report location.
  • Semantic Triage (Deduplication Service): Utilizes NLP vector embeddings and cosine similarity to detect and link duplicate incident reports, preventing redundant dispatch.
  • Data Persistence: PostgreSQL with pgvector extension for storing structured data and semantic embeddings, interfaced via an asynchronous ORM.

✨ Core Features

  • Multilingual Support: Seamlessly processes reports in both English and Bangla.
  • Automated Triage: AI automatically determines event category (fire, medical, infrastructure) and calculates urgency.
  • Smart Deduplication: Identifies identical localized events even when described using entirely different phrasing.
  • Contextual Enrichment: Appends live weather conditions (temperature, humidity, rain) to submitted locations.
  • Secure Administration: JWT-secured endpoints for status management and system analytics.
  • Production-Ready: Fully containerized, OpenAPI/Swagger documented, and protected by robust global exception handling.

🛠 Tech Stack

Component Technology
Framework Python 3.11+, FastAPI
Database PostgreSQL, pgvector
Validation Pydantic v2
Rate Limiting SlowAPI
External APIs LLM API, OpenWeatherMap
Infrastructure Docker, Docker Compose, Railway

📂 Folder Structure

/crisisdesk-api
├── app/
│   ├── api/          # Route controllers and endpoint definitions
│   ├── core/         # Global configuration, rate limiting, and exception handlers
│   ├── models/       # Database ORM entities
│   ├── schemas/      # Pydantic validation contracts (Requests/Responses)
│   ├── services/     # Business logic (AI, Weather, Deduplication, Analytics)
│   └── main.py       # Application bootstrap and middleware configuration
├── tests/            # Automated test suites
├── Dockerfile        # Production container specification
├── docker-compose.yml# Local infrastructure orchestration
├── requirements.txt  # Python dependencies
└── .env              # Environment variable configuration


🚀 Setup & Deployment

1. Environment Variables

Create a .env file in the root directory with the following configuration:

# Core Configuration
ENVIRONMENT=production
SECRET_KEY=your_super_secret_jwt_key_here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

# Database
DATABASE_URL=postgresql+asyncpg://user:password@db_host:5432/crisisdesk

# External Integrations
AI_API_KEY=your_llm_api_key_here
WEATHER_API_KEY=your_openweathermap_api_key_here

# Admin Credentials
ADMIN_USERNAME=udnfahim
ADMIN_PASSWORD=admin@fm26

2. Docker Deployment

The system is fully containerized. Spin up the API and the PostgreSQL database locally using Docker Compose.

# Build and start the services in detached mode
docker-compose up -d --build

# View container logs
docker-compose logs -f app

🔐 Administrative Access

System administration endpoints require authentication. Use the following pre-configured credentials to generate a JWT Bearer token:

  • Username: udnfahim
  • Password: admin@fm26

Authentication Request:

curl -X POST https://crisisdesk-api-production.up.railway.app/api/admin/login \
     -H "Content-Type: application/json" \
     -d '{"username": "udnfahim", "password": "admin@fm26"}'

Note: Extract the access_token from the response to use in the Authorization: Bearer <token> header for protected routes.


📖 API Usage & Endpoints

Interactive OpenAPI documentation is available at GET /docs via the production URL: [https://crisisdesk-api-production.up.railway.app/docs](https://crisisdesk-api-production.up.railway.app/docs).

Submit a Crisis Report (Public)

Triggers the AI classification, weather enrichment, and deduplication pipeline.

curl -X POST https://crisisdesk-api-production.up.railway.app/api/reports \
     -H "Content-Type: application/json" \
     -d '{
           "name": "Arif Rahman",
           "contact": "01612345678",
           "location": "Chittagong",
           "description": "The heavy monsoon rain has caused severe waterlogging in the main city area. Streets are flooded, and traffic is completely stalled.",
           "language": "en"
         }'

Retrieve Reports (Public)

Supports pagination and filtering by category or urgency.

curl -X GET "https://crisisdesk-api-production.up.railway.app/api/reports?category=infrastructure&urgency=high&page=1&size=10" \
     -H "accept: application/json"

Update Report Status (Admin Only)

Requires JWT authentication. Transitions a report state (e.g., pending -> resolved).

curl -X PATCH https://crisisdesk-api-production.up.railway.app/api/reports/{report_id}/status \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -d '{"status": "resolved"}'

System Analytics (Admin Only)

Aggregates report statistics across the entire database.

curl -X GET https://crisisdesk-api-production.up.railway.app/api/reports/stats/summary \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "accept: application/json"

About

A production-ready FastAPI backend for emergency management that uses LLMs and vector embeddings to automatically classify, enrich, and deduplicate crisis reports.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages