Skip to main content

Command Palette

Search for a command to run...

TerraGuard: Building a Real-Time AI Disaster Simulation That Learns From You

Published
4 min read

🚨 TerraGuard — Building an AI-Powered Disaster Simulation System That Learns From You

Most AI projects today stop at one thing: generate a response → show it → done.

But real-world decision-making doesn’t work like that.

In disasters, decisions:

evolve cascade have consequences and most importantly… repeat patterns

So we asked a simple question:

What if AI didn’t just respond… but simulated reality and learned from you over time?

That’s how TerraGuard was built.

🧠 The Idea

TerraGuard is an AI-powered disaster simulation system where users make decisions under pressure and the environment reacts in real time.

But unlike typical simulations:

it’s not scripted it doesn’t reset every session and it doesn’t forget your mistakes

It evolves with you.

⚙️ How TerraGuard Works

At its core, TerraGuard is a state-driven simulation engine powered by AI.

The loop is simple:

AI generates a disaster scenario User makes a decision System evaluates impact Scenario evolves Repeat for multiple rounds

But the execution is where things get interesting.

🔄 Real-Time AI Simulation (Not Just Chat)

Instead of waiting for full responses, we implemented streaming AI responses.

AI sends output incrementally Frontend renders it using a typewriter effect Users experience a live unfolding situation

This creates:

lower perceived latency higher immersion real-time urgency 🎮 Multiple Modes = Different Realities

We didn’t want a one-dimensional experience.

So TerraGuard introduces three distinct modes:

👤 Citizen Mode Personal survival decisions Small-scale impact Emotion-driven scenarios 🚑 Coordinator Mode Resource management (ambulances, rescue teams) Multiple simultaneous emergencies Trade-offs and prioritization 🏛 Official Mode Large-scale decision making Public communication Budget and inter-agency coordination

Each mode changes:

scale complexity consequences 🧱 System Architecture Frontend React (Vite + TypeScript) Tailwind CSS Context + useReducer (state management)

The frontend acts as:

a real-time simulation controller, not just UI

Backend Node.js + Express

Used as:

secure API proxy streaming handler (SSE) memory integration layer AI Layer Google Gemini (primary) Groq (fallback)

Key decision:

enforce structured JSON output maintain consistency across rounds ⚡ Streaming with SSE (Server-Sent Events)

One of the hardest parts was implementing streaming correctly.

Instead of:

request → wait → response

We built:

request → stream → render progressively

Challenges:

handling partial data reconstructing valid JSON syncing UI updates

Result:

A real-time, responsive simulation experience

🧠 The Biggest Upgrade: Memory with Hindsight

Most AI apps are stateless.

You close the tab → everything is gone.

That’s where TerraGuard becomes different.

We integrated a memory layer using Hindsight.

🔁 What Memory Enables

  1. Retain (During Simulation)

Stores:

decisions outcomes context 2. Recall (Before Simulation)

Fetches:

past behavior repeated mistakes

Then injects into AI prompt.

  1. Reflect (After Simulation)

Generates:

behavioral insights improvement suggestions 💥 Result

The system can now:

detect patterns adapt scenarios personalize feedback

Example:

“You tend to delay evacuation decisions — this has cost lives in previous sessions.”

That’s not a feature. That’s learning behavior modeling.

📊 Final Output: After-Action Report

At the end of each simulation, TerraGuard generates a detailed report:

Lives saved vs lost Performance score and grade Round-by-round analysis Critical mistakes Best decisions Real-world insights

And with memory:

behavioral profile pattern detection improvement recommendations ⚠️ Challenges We Faced

  1. JSON Reliability

AI doesn’t always behave.

Solution:

enforce structured output add parsing fallback 2. Streaming Complexity

Handling partial responses without breaking UI.

  1. State Synchronization

Keeping frontend state aligned with AI output across rounds.

  1. Memory Integration

Making it meaningful — not just storing logs.

🧠 What We Actually Built

Not:

a chatbot a game a demo project

But:

a real-time AI simulation engine with memory-driven behavior adaptation

🚀 What’s Next

If taken further, TerraGuard can evolve into:

disaster training tools emergency response simulations decision-making training platforms 💡 Final Thought

AI shouldn’t just answer questions.

It should:

simulate environments challenge decisions and help you improve over time

TerraGuard is a step in that direction.

🔗 Tech Stack Frontend: React (Vite + TypeScript), Tailwind Backend: Node.js + Express AI: Gemini + Groq fallback Memory: Hindsight

🙌 Closing

This project started as a hackathon idea. But it turned into something deeper:

a system that doesn’t just respond — it reacts, evolves, and remembers.