{"slug": "ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint", "title": "\"EcoSphere AI: Why I separated 'logic' from 'AI' when building a carbon footprint assistant\"", "summary": "EcoSphere AI separates its carbon footprint calculation logic from its AI layer, using a deterministic TypeScript engine for consistent, auditable emissions numbers and Google Gemini AI only for natural language explanations. The approach ensures reliable tracking and enables thorough unit testing, with deployment on Vercel and Google Cloud Run.", "body_md": "When you say \"build a carbon footprint app,\" the obvious move is: collect some inputs,\n\nask an LLM \"how much CO2 does this produce,\" and display whatever it says.\n\nThat's a trap. LLMs are not reliable calculators. Ask the same model the same emissions\n\nquestion twice and you'll get two different numbers. For a \"track your carbon footprint\"\n\ntool, that's disqualifying — the entire premise of tracking requires consistent,\n\nauditable numbers.\n\nEcoSphere AI splits the problem in two:\n\n**1. A deterministic carbon engine** — pure TypeScript functions using documented\n\nemission factors (diet type, transport mode, energy use, shopping habits). Same input,\n\nsame output, every time. Fully unit tested. This is what computes your actual footprint,\n\nyour Carbon DNA archetype, your Risk Score, and your ranked recommendations.\n\n**2. Google Gemini AI** — used only for what LLMs are actually good at: natural language\n\nexplanation, contextual conversation, and pattern narration. The AI coach receives the\n\nengine's real computed numbers as context and explains them — it never invents the\n\nmath itself.\n\nThis split mattered more than any single feature. It's the difference between a project\n\nthat *looks* AI-powered and one that *is* genuinely intelligent.\n\n**Gemini API** powers the conversational coach and weekly AI-generated summaries — always\n\nfed real context, never guessing.\n\n**Firebase Firestore** stores monthly profile snapshots, enabling a deterministic\n\nhabit-change detector that flags \"+17% this month, likely from increased food delivery\"\n\n— again, computed, not hallucinated.\n\n**Deployment**: Initially deployed on Vercel for rapid iteration, with a Dockerized Google Cloud Run architecture staging for final production.\n\nBecause the carbon engine is pure functions, it was trivial to write 20+ meaningful\n\nunit tests — ordering checks (vegan footprint < high-meat footprint), boundary checks\n\n(risk score clamped 0-100), and invariant checks (Carbon Twin always projects lower\n\nthan current). This is testing that actually validates logic, not just \"does it render.\"\n\nSix structured master prompts: scaffold + security → deterministic engine → Firebase/AI\n\nlayer → core UI → coach/gamification UI → tests/Docker/README. Each prompt built on\n\nthe last, intent-driven the whole way.\n\n🔗 Live: [https://ecosphere-ai-tan.vercel.app/](https://ecosphere-ai-tan.vercel.app/)\n\n💻 GitHub: [https://github.com/ajx1tech/ecosphere-ai](https://github.com/ajx1tech/ecosphere-ai)", "url": "https://wpnews.pro/news/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint", "canonical_source": "https://dev.to/ajx1tech/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint-assistant-1m6a", "published_at": "2026-06-21 05:48:30+00:00", "updated_at": "2026-06-21 06:37:14.526561+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "developer-tools", "ai-products", "ai-agents"], "entities": ["EcoSphere AI", "Google Gemini", "Firebase Firestore", "Vercel", "Google Cloud Run", "TypeScript"], "alternates": {"html": "https://wpnews.pro/news/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint", "markdown": "https://wpnews.pro/news/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint.md", "text": "https://wpnews.pro/news/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint.txt", "jsonld": "https://wpnews.pro/news/ecosphere-ai-why-i-separated-logic-from-ai-when-building-a-carbon-footprint.jsonld"}}