🔗 Live Production App: calzap.ashwinig.com
Calzap is an ultra-lightweight, offline-first, zero-bloat calorie and macronutrient tracking web application engineered with Svelte 5 (Runes), TypeScript, and Tailwind CSS v4.
Built for speed, efficiency, and data isolation, Calzap contains no ads, no trackers, no cloud accounts, and no paywalls. It allows athletes and lifters to track their core nutritional metrics—Calories, Protein, Carbs, Fats, and Fiber—in under 10 seconds. Calzap is designed to run entirely in the browser client with immediate responsiveness, utilizing local storage systems and secure, client-configured AI microservices.
Calzap strictly implements a zero-server data isolation model. There are no remote backends or centralized databases storing user intake histories.
src/lib/db.ts).Calzap leverages the compiler-driven reactivity of Svelte 5 to eliminate virtual-DOM diffing overhead, resulting in immediate UI updates:
$state: Manages mutable core arrays (e.g., catalog items, consumed history) and user configuration objects.$derived: Dynamically computes numerical calorie metrics, macro ratios, remaining budgets, active streaks, and statistical charts.$derived.by: Executes complex multi-step data reductions (e.g., aggregating monthly histories and generating O(N) daily calendar buckets) strictly on-demand.$props: Unpacks read-only configuration variables safely to sub-components with strict static typing.To prevent unpredictable rendering cycles, nested recalculation cascades, and Cumulative Layout Shifts (CLS), the codebase strictly avoids $effect.
addFoodLog(), deleteFood(), updateUserStats()) rather than side-effect hooks.Calzap employs a modern typography and color pipeline optimized for raw readability under harsh gym lighting:
@theme directive, implementing light/dark dark-mode adaptation via standard CSS media selectors.src/routes/layout.css to guarantee visual harmony and strict consistency:oklch(0.62 0.18 250) (Precise Sapphire Blue)oklch(0.65 0.20 35) (Vibrant Energy Orange)oklch(0.65 0.17 145) (Crisp Vitality Green)oklch(0.78 0.16 85) (Rich Golden Yellow)oklch(0.62 0.16 310) (Soft Grape Purple)Calzap features integrated AI-assisted macronutrient estimation:
gemini-3-flash:generateContent)./home/ashwini/code/food
├── .impeccable.md # Style guidelines and design token requirements
├── svelte.config.js # SvelteKit preprocessor & adapter configurations
├── vite.config.ts # Vite bundler configurations & CSS compiler setup
├── tsconfig.json # TypeScript strict path mapping and compiler settings
├── package.json # Declarative app manifests & Vite/Svelte dependencies
├── static/ # Static assets (Favicons and manifest files)
└── src/
├── app.d.ts # Global SvelteKit namespace types and declarations
├── app.html # Baseline entry HTML layout & font import structures
├── lib/ # Shared utilities, components, and state systems
│ ├── assets/ # Visual branding materials
│ ├── db.ts # Transactional client IndexedDB manager class
│ ├── index.ts # Shared libraries entry point
│ ├── store.svelte.ts# Core reactive Svelte 5 state store
│ ├── foodDraft.svelte.ts # Reactive buffer state for food creation wizard
│ └── components/ # Reusable structural ui elements
│ ├── Header.svelte # Navigation layout & title headings
│ ├── Footer.svelte # Detailed information panel & footer links
│ ├── GoalSlider.svelte # Interactive target calorie controller
│ └── MacroBar.svelte # Reusable dynamic SVG/CSS nutrient indicator
└── routes/ # File-system router layouts and screens
├── +layout.svelte # Main layout template injecting layout.css and Header
├── +layout.ts # Prerendering & Static adapter configurations
├── layout.css # OKLCH custom variables and tailwind v4 layer imports
├── +page.svelte # Landing page with interactive, local demo sandbox
├── dashboard/ # Day-to-day macro tracking core screen
├── foods/ # Custom foods library catalog management
│ ├── +page.svelte # Foods search & creation selector entry page
│ ├── macros/ # Macronutrient manual input & AI estimator screen
│ └── quantity/ # Serving size & custom food details wizard
├── log/ # Full food logging transaction screen
├── progress/ # Streak calculators, trend charts, and weight trackers
├── profile/ # Local database backups, daily targets, and API keys
├── cookies/ # Local cookie-free storage policies
├── privacy/ # Absolute offline client privacy statements
└── terms/ # Terms of use (Free & local-only open-source license)
src/lib/db.ts)The IndexedDBManager handles storage initialization, database migrations, and isolated asynchronous transactions. It defines three local object stores:
foods: Stores custom-created food objects.foodLogs: Stores chronological records of consumed foods with exact timestamps.userStats: Holds daily target metrics, current weights, and the optional Gemini API key under the 'current' record key.class IndexedDBManager {
private db: IDBDatabase | null = null;
async init(): Promise<IDBDatabase> {
if (this.db) return this.db;
return new Promise((resolve, reject) => {
const request = indexedDB.open('CalzapDB', 1);
request.onupgradeneeded = () => {
const database = request.result;
if (!database.objectStoreNames.contains('foods')) {
database.createObjectStore('foods', { keyPath: 'id' });
}
if (!database.objectStoreNames.contains('foodLogs')) {
database.createObjectStore('foodLogs', { keyPath: 'id' });
}
if (!database.objectStoreNames.contains('userStats')) {
database.createObjectStore('userStats');
}
};
request.onsuccess = () => {
this.db = request.result;
resolve(request.result);
};
request.onerror = () => reject(request.error);
});
}
// Transactional queries (getAll, put, clear) are wrapped in modern JavaScript Promises.
}
src/lib/store.svelte.ts)The core Store class serves as the single source of truth for runtime data. By combining Svelte 5 $state fields with explicit persistence writes, memory and IndexedDB stay perfectly synchronized.
class Store {
foods = $state<Food[]>([]);
foodLogs = $state<FoodLog[]>([]);
userStats = $state<UserStats>({
target_calories: 2000,
target_proteins: 150,
target_carbs: 200,
target_fats: 65,
target_fiber: 30,
target_weight: 70,
current_weight: 70,
google_ai_studio_api_key: '',
});
constructor() {
if (browser) {
this.loadIndexedDB();
}
}
save() {
if (browser && dbManager) {
dbManager.saveFoods(this.foods).catch(console.error);
dbManager.saveFoodLogs(this.foodLogs).catch(console.error);
dbManager.saveUserStats(this.userStats).catch(console.error);
}
}
// Explicit mutators add/delete records and safely trigger synchronous persistence writes.
}
src/routes/foods/macros/+page.svelte)When creating a food draft, users can request an automatic estimate of macronutrients. This bypasses high-overhead local database scraping by using a zero-temperature, structured JSON prompt with Gemini:
const prompt = `Estimate the macronutrients for the following food item. Respond with a JSON object exactly like this: {"calories": 100, "proteins": 10, "carbs": 20, "fats": 5, "fiber": 2}. Use numbers. Return ONLY valid JSON without Markdown blocks.
Food Name: ${foodDraft.name}
Quantity: ${foodDraft.quantity} ${foodDraft.units}
Special ingredients/notes: ${foodDraft.notes || 'None'}`;
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash:generateContent?key=${apiKey}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
contents: [{ parts: [{ text: prompt }] }],
generationConfig: {
temperature: 0.1,
responseMimeType: "application/json"
}
})
});
src/routes/progress/+page.svelte)Calzap features comprehensive local metric analysis computed reactively using Svelte 5's derived engine:
const loggingStreak = $derived.by(() => {
const logs = store.foodLogs;
if (logs.length === 0) return 0;
const loggedDates = new Set<string>();
for (const log of logs) {
const d = new Date(log.consumed_at);
loggedDates.add(d.toDateString());
}
let streak = 0;
const today = new Date();
today.setHours(0, 0, 0, 0);
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
let checkDate = new Date(today);
// Streak continuity check
if (!loggedDates.has(today.toDateString())) {
if (loggedDates.has(yesterday.toDateString())) {
checkDate = yesterday;
} else {
return 0;
}
}
while (true) {
if (loggedDates.has(checkDate.toDateString())) {
streak++;
checkDate.setDate(checkDate.getDate() - 1);
} else {
break;
}
}
return streak;
});
Calzap mandates Node.js v20+ and uses pnpm as its fast, deterministic dependency package manager.
Clone the repository and install the production/development dependencies:
# Clone repository
git clone https://github.com/sveltejs/cli.git calzap
cd calzap
# Install dependencies using pnpm
pnpm install
Boot up the high-speed Vite server with hot module reloading (HMR) enabled:
# Start development server and launch the browser automatically
pnpm dev --open
Calzap compiles into an ultra-fast, completely prerendered static web app (@sveltejs/adapter-static). It executes static generation during compilation:
# Type-check TypeScript parameters and run Svelte-check
pnpm check
# Build production optimized bundle
pnpm build
# Preview compiled build locally
pnpm preview
The resulting optimized static build is exported directly to the ./build folder. It can be immediately hosted on any edge server network (e.g., GitHub Pages, Vercel, Netlify, Cloudflare Pages) with absolute zero runtime server configuration. The live production instance is deployed at calzap.ashwinig.com.
Calzap is open-source software, licensed under the AGPL-3.0-or-later license.
It is provided "as is" without warranty. Because all core dietary calculations, history tracking, and database persistence run purely on the user's local hardware (with the optional AI estimation features queried directly from the browser to Google's AI Studio API via the user's own key), Calzap ensures complete user data ownership. No centralized application servers, tracking scripts, or third-party advertising cookie trackers are involved.