How vucore/pbl5_flood_warning_system works
Project type and purpose
• This is a full-stack, real-time flood warning system combining sensor data ingestion, flood‐risk computation, and an AI‐driven chatbot.
• Backend: FastAPI micro-modules (WebSocket/data ingestion, flood-risk API, chatbot API).
• Frontend: Static HTML/CSS/JS dashboards and chat interface.
• External services: Firebase Realtime Database, Ollama LLM server, Chroma vector store.
File structure
• Top-level “be/” directory holds three FastAPI sub-modules under app/:
• data_module: WebSocket server, REST endpoints, Firebase integration.
• floodrisk_module: flood risk computation REST API.
• chatbot_module: RAG-based chatbot REST API.
• main.py can start all modules on one port.
• fake_data.py: simulates sensor feeds to the WebSocket.
• “fe/” directory holds the static front end (HTML assets, CSS styles, JS logic including WebSocket client, charting, chat UI).
README for additional insights
• Two modes: separate processes (port 8000 for data+flood, port 8001 for chatbot) or unified via main.py.
• Sensor data flows to Firebase and via WebSocket.
• Chatbot pipeline uses LangChain + Chroma + local Ollama LLaMA3.
• Flood risk module computes risk on demand.
a. Main components:
• Frontend browser (Dashboard & Chat UI)
• Backend modules:
• Data Ingestion & WebSocket Server (data_module)
• Flood Risk API (floodrisk_module)
• Chatbot API (chatbot_module)
• Orchestrator (main.py)
• Data stores:
• Firebase Realtime Database (sensor_data)
• Chroma vector store (embeddings)
• External AI service: Ollama LLM (LLaMA3)
• Fake Data Generator (fake_data.py)
b. Relationships & data flows:
1. Fake Data → WebSocket server → Broadcast to connected clients & push to Firebase.
2. Frontend subscribes via WebSocket → renders real-time charts.
3. Frontend calls Flood Risk API → returns computed risk metrics.
4. Frontend sends chat messages → Chatbot API → RAG pipeline:
• Preprocess → classify/tag → retrieve docs from Chroma → build prompt → send to Ollama → format response → return to UI.
5. Chatbot module populates/updates Chroma vector store at startup from local data files.
c. Architectural patterns & design principles:
• Layered modules: Routes → Services → Utils/ML/RAG.
• Microservice-style: each domain (data, flood risk, chatbot) can run independently.
• Event-driven real-time updates via WebSocket.
• RAG pattern for chatbot (Retrieval + Generation).
• Separation of concerns (database, business logic, API, UI).
d. Key technologies & libraries:
• FastAPI, Uvicorn
• WebSocket (Starlette)
• Firebase Admin SDK
• LangChain, Chroma, HuggingFace Transformers
• Ollama local LLM server
• Vanilla JS, Chart.js for front end