Back to Home

How Kenko Works

A seamless pipeline from user input to actionable health insights, powered by localized Machine Learning and robust backend integration.

1. Client Data Acquisition

Homeapp/page.tsx renders Vitals Formapp/components/VitalsForm.tsx, where users enter age, BMI, glucose, blood pressure, activity, diet, sleep, fatigue, and smoking inputs.

2. Secure API Bridging

API Routeapp/api/predict/route.ts receives JSON from the form, serializes it, and spawns python Python Wrapperapp/api/predict/wrapper.py with cwd pointed to Model Dir../kenko-model.

3. ML Payload Normalization

Python Wrapperapp/api/predict/wrapper.py parses argv JSON and imports Risk Enginekenko-model/risk_engine.py, where _normalize_payload handles aliases like activity -> activity_level and smoke -> smoking.

4. Risk Engine Inference

Risk Enginekenko-model/risk_engine.py loads Metabolic Modelmodels/metabolic_model.joblib and Cardio Modelmodels/cardio_model.joblib, computes metabolic/cardio/nutrition risks, calibrates youth cardio risk, and returns confidence + phenotype signature.

5. Intervention Simulation

Risk Enginekenko-model/risk_engine.py runs _simulate_interventions for sleep_recovery, movement_nutrition_boost, and metabolic_reset to estimate projected improvement percentages.

6. Dynamic UI Rendering

Results UIapp/components/ResultsDisplay.tsx renders risk bands, factor breakdown, top drivers, suggested tests, and intervention outcomes with animated UI cards and compact context pills.

IPC Bridge Stability & Security

// Problem: Python logs mixed into stdout can corrupt JSON parsing
// Solution: buffer streams, validate exit code, parse only last JSON line

import { spawn } from 'child_process'; const payloadStr = JSON.stringify(body); const pythonProcess = spawn('python', [wrapperPath, payloadStr], { cwd: path.resolve(process.cwd(), '../kenko-model'), shell: false }); let stdout = ''; let stderr = ''; pythonProcess.stdout.on('data', (chunk) => stdout += chunk.toString()); pythonProcess.stderr.on('data', (chunk) => stderr += chunk.toString()); pythonProcess.on('close', (code) => { if (code !== 0) throw new Error(stderr || 'Python failed'); const lines = stdout.trim().split('\\n'); const jsonLine = lines[lines.length - 1]; const result = JSON.parse(jsonLine); });

ML Training: Countering Data Skew

# Problem: Skewed datasets heavily biased towards healthy patients
# Solution: Balanced class weights & max depths to prevent overfitting

from sklearn.ensemble import RandomForestClassifier import joblib rf_model = RandomForestClassifier(( n_estimators=100, class_weight='balanced', # Penalize majority class errors max_depth=10, # Cap depth to prevent overfit random_state=42 ) rf_model.fit(X_train, y_train) joblib.dump(rf_model, 'models/metabolic_model.joblib')