DEVELOPER REFERENCE • PHASE II (v4)

SAARETOOLS Hybrid Modular Architecture Guide

Bookmark this page for future reference. It documents how tool.php, tools/, includes/tools.php, and assets/js/app.js work together—plus a live status tracker of all 42 tools.

1. How Every Tool Request Works (Step-by-Step)

1. Visitor URLtool.php?slug=emi-calculator
2. tool.php RouterReads $_GET['slug']
3. includes/tools.phpLoads Title, Tier, FAQs
4. Free / Pro Gatecan_access_tool($tool)
5A. tools/{slug}.phpIf file exists (Modular)
OR
5B. assets/js/app.jsFallback if not migrated yet

Why this Hybrid design is ideal: You manage header, footer, SEO meta tags, breadcrumbs, Free/Pro login gating, AdSense slots, and FAQs in one single file (tool.php), while each calculator's UI & JavaScript lives in its own isolated file inside tools/. A bug in one calculator can never break another calculator.

2. Project Folder & File Map

File / Folder Purpose & When to Edit
includes/tools.php Master Tool Catalog. Stores every tool's slug, name, category, type, tier ('free' or 'pro'), formula, guide, and FAQs. Powers homepage cards, search, filters, related tools, and sitemap.php.
tool.php Shared Wrapper & Hybrid Router. Checks Free/Pro access, loads tools/{slug}.php if present, otherwise falls back to assets/js/app.js. Edit this only when changing the global layout or AdSense slots.
tools/{slug}.php Individual Modular Tools. Self-contained HTML + CSS + JS for one specific calculator (e.g., tools/emi-calculator.php). Always starts with the SAARETOOLS_TOOL_CONTEXT security check.
tools/_template.php Starter Template. Copy and rename this file whenever you want to create a new modular tool.
tools/.htaccess Security Shield. Blocks direct browser URLs like /tools/gratuity-calculator.php so visitors cannot bypass the Pro login gate in tool.php.
assets/js/app.js Legacy Fallback Engine. Automatically runs any tool that hasn't been moved to tools/{slug}.php yet.
includes/auth.php Visitor Auth & Tier Helpers. Provides is_logged_in(), is_pro_user(), and can_access_tool($tool).
index.php & stopwatch.php Homepage & Stopwatch. Self-contained modern homepage featuring the top Stopwatch banner, Smart Arithmetic/Scientific Calculator, Length Converter, Weight Converter, and AdSense compliance brief.

3. How to Add a Brand New Calculator (3 Minutes)

  1. Register in includes/tools.php: Add an array entry with a unique slug (e.g., 'slug' => 'hra-calculator'), 'tier' => 'free' (or 'pro'), title, summary, formula, guide, and FAQs.
  2. Create tools/hra-calculator.php: Copy tools/_template.php, rename it to hra-calculator.php, and write your HTML inputs + JS calculation inside an IIFE (function(){ ... })();.
  3. Done! Your new tool automatically appears on the homepage, live search, category chips, Free/Pro comparison page, sitemap.php, and works at both tool.php?slug=hra-calculator and /tool/hra-calculator.
// Security header required at top of every tools/{slug}.php file:
<?php
if (!defined('SAARETOOLS_TOOL_CONTEXT')) {
    http_response_code(403);
    exit('Direct access not permitted.');
}
?>

4. Live Tool Status Tracker

4 Modular (tools/*.php) 38 Fallback (app.js)

Active Modular Tools (Isolated Files in tools/)

Fallback Tools (Running via fixed assets/js/app.js — Ready to migrate anytime)

5. Troubleshooting Checklist (XAMPP & Hostinger)