DEV Community

Abhishek Khanra
Abhishek Khanra

Posted on AI-assisted

Before It Turns White: Predicting 48-Hour Saltwater Reef Crashes with TabPFN

Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle Submission 💸

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle

What I Built

Before It Turns White is a 48-hour predictive water chemistry crash guard for marine reef aquariums. It monitors coupled ionic balances and rate-of-change velocities across eight chemical parameters to detect systemic crashes before coral tissue melts.

The Origin & Who Pays

I am an 18-year-old student living in an apartment in India. I do not own a 100-gallon marine reef tank. In India, recurring electrical outages and ambient summer heat make keeping delicate stony corals difficult and expensive.

The idea came from late-night reading on r/ReefTank, Reef2Reef, and Bulk Reef Supply video archives.

Reef hobbyists are some of the most dedicated amateur biochemists in the world. They do not view their aquariums as simple fish tanks. They treat them like critical-care medical systems. A typical 75-gallon Small Polyp Stony (SPS) coral system represents a capital investment between $5,000 and $12,000:

  • High-PAR LED lighting (Radion / Hydra): $800 to $1,600
  • Filtration and dosing hardware: $900 to $1,800
  • Coral livestock (Acropora frags, Torch colonies): $1,500 to $6,000+

A single premier coral fragment costs between $150 and $600.

The Problem It Solves: Rapid Tissue Necrosis (RTN)

Corals do not die slowly. When water chemistry destabilizes, corals experience Rapid Tissue Necrosis. Living tissue sloughs off like melting skin within 12 to 24 hours, leaving bare white calcium carbonate skeletons.

Standard aquarium applications act as digital logbooks. They plot single parameters on separate 2D line charts. If alkalinity reads 8.4 dKH, the app paints it green.

Marine chemistry does not operate in silos. It is a coupled chemical equilibrium:

  1. The Magnesium Shield Collapse: Dissolved magnesium ions (~1350 ppm) poison calcium carbonate crystal growth sites. This keeps calcium (420 ppm) and alkalinity (8.4 dKH) dissolved at supersaturated levels. If magnesium drops below 1200 ppm (ratio under 2.85:1), this shield breaks.
  2. Abiotic Snowstorm: Calcium and alkalinity spontaneously bind together, precipitating out of solution.
  3. The Velocity Shock: Alkalinity plummets over 48 hours. Carbonate ion starvation causes severe osmotic cellular shock, stripping coral tissue.

Keepers see green numbers on Saturday and wake up to white skeletons on Tuesday.

Before It Turns White catches this non-linear coupling 48 hours early. It provides a volume-calibrated, biologically clamped recovery protocol to stop panic overdosing.

Monetization: India-Viable Cross-Border SaaS

Building a global subscription from India faces payment barriers: Stripe Atlas costs $500+, domestic gateways have foreign card restrictions, and PayPal takes heavy currency conversion cuts.

I integrated Dodo Payments as the legal Merchant of Record. Dodo Payments handles international credit card processing, currency conversion, and global tax compliance (US sales tax and EU VAT).

  • Free Tier: Manual test kit logging, standard unit normalization, and baseline threshold monitoring.
  • Guardian Pro ($4.99/mo or $39/year): Continuous TabPFN 48-hour crash prediction, coupled biological radar matrices, volume-scaled safe dosing ramps, and direct controller polling.

Hobbyists already spend $250 to $400 each year on reagents and testing standards. Paying $4.99 per month to protect a $6,000 livestock investment is an immediate financial return.


Demo


Code

The repository contains:

  • backend/: FastAPI service with TabPFN foundation model client, 16-D feature pipeline, and biological rate clamp algorithms.
  • client/: Single-page console built in React 19 and Vite with custom high-contrast dark telemetry tokens.
  • tests/: 23 automated unit and integration tests passing with 100% success rate.
  • render.yaml: Declarative production deployment blueprint.

How I Built It

1. Open-Source AI: Prior Labs TabPFN-3.5

Hobbyists do not have millions of data points. A typical keeper logs one manual test per week, generating roughly 25 rows per year with irregular sampling intervals.

Traditional machine learning struggles on sparse tabular data:

  • Deep neural networks overfit immediately on 25 rows.
  • Gradient-boosted trees (XGBoost/LightGBM) struggle with sparse tabular derivative velocities.
  • Statistical autoregression misses non-linear threshold collapses.

TabPFN-3.5 is a foundation model trained on synthetic tabular datasets. It evaluates tabular data in-context in a single forward pass without gradient descent or hyperparameter tuning.

I supplied TabPFN with an in-context reference memory of 500 validated marine trajectories (250 verified crashes across five collapse modes, and 250 stable baselines). The model evaluates incoming multi-parameter trajectories and returns calibrated crash probabilities in under 200 milliseconds.

2. 16-Dimensional Biochemical Feature Pipeline

The backend transforms raw inputs into sixteen physiological indicators:

  • Base Parameters (8): Salinity, Alkalinity, Calcium, Magnesium, Nitrate, Phosphate, Temperature, and pH.
  • Velocity Indicators (3): 24-hour rate of change ($\Delta \text{Param} / \Delta t$) across foundation buffer minerals.
  • Ionic Coupling Indicators (3):
    • $Mg:Ca$ Ratio: Detects shield degradation before precipitation starts.
    • Ionic Product Index: Evaluates spontaneous precipitation pressure.
    • Aragonite Saturation Proxy: Measures skeleton dissolution risk when pH drops.
  • Biological Starvation Flags (2): Redfield ratio ($NO_3 : PO_4$) and Burnt-Tip Starvation Flag (high alkalinity with zero phosphate under intense lighting).

3. Biological Rate Clamp Engine

When keepers discover depleted numbers, they frequently panic and dump concentrated chemicals into the sump. Rapid swings cause tissue necrosis faster than low numbers.

The engine enforces strict biological clamps:

  • Alkalinity: Maximum $+0.50\text{ dKH}$ per 24 hours.
  • Calcium: Maximum $+20.0\text{ ppm}$ per 24 hours.
  • Magnesium: Maximum $+50.0\text{ ppm}$ per 24 hours.

Dosages scale strictly by water volume. If a 450-liter tank has a $1.5\text{ dKH}$ deficit, the engine forbids single-day correction and outputs a 3-day staggered schedule of $180.0\text{ ml}$ per day.

4. Hardware Controller & Webhook Ingestion

The platform connects directly to hardware controllers on the user's local network:

  • Neptune Apex: Polls http://{host}:{port}/cgi-bin/status.json and status.xml.
  • GHL Profilux & CoralVue Hydros: Polls local status endpoints.
  • REST Webhook (POST /api/hardware/ingest): Accepts JSON payloads from Home Assistant or custom Raspberry Pi / reef-pi setups.

5. Deterministic Offline Fallback

If the network drops while a keeper is standing in front of their aquarium, the system switches to local deterministic marine guardrails implemented in both Python and JavaScript. The app remains functional with zero cloud dependency.


Why Does Open Innovation Matter?

Building with open ecosystem tools mattered for two specific reasons:

  1. Closed LLMs Fail at Tabular Numerical Chemistry:
    Closed commercial LLM APIs (OpenAI, Anthropic) charge per-token, hallucinate floating-point numbers, and cannot perform rigorous numerical time-series inference across small, sparse tabular datasets ($N=25$). Passing high-frequency hardware probe streams into closed language models is financially impractical and biochemically unreliable.
    Open foundation models like Prior Labs TabPFN bring transformer architectures directly to tabular numerical tensors, enabling sub-200ms predictions with zero token fees.

  2. Auditable Biological Safety:
    Reef keepers manage living animals worth thousands of dollars. They will not trust closed black-box models with their dosing calculations. Open-source implementation allows the community, marine biologists, and hobbyists to audit every equation, safety clamp, and feature extraction formula. Furthermore, open algorithms allow running these calculations locally on low-power devices (such as a Raspberry Pi running reef-pi) directly next to the aquarium without external corporate dependencies.


Prize Categories

  • Prior Labs TabPFN

Top comments (0)