HostQ Documentation

A complete guide to the architecture, database schema, and API endpoints powering HostQ — the ultimate management platform for Kenyan short-stay hosts and agents.

Platform Goal: HostQ allows property owners (Hosts) to list their units, and allows agents to manage bookings and generate commissions. It handles everything from multi-property listings to M-Pesa instant payouts.

User Roles

Role Description Key Capabilities
Host The property owner. They list the properties. Can create listings, manage own units, add agents, view analytics. (Cannot manage properties assigned to them by other hosts).
Agent Manages properties on behalf of a Host. Can manage assigned properties, view bookings, earn commissions instantly via M-Pesa. (Cannot create their own listings).
Both (Hybrid) Users who are both a Host and an Agent. Can create their own listings, and also manage assigned properties.

Page Structure

The platform is divided into three main areas: Public Pages, Host Dashboard, and Admin Panel.

1. Public Pages

PathDescription
/index.htmlLanding page. Detects auth state and shows/hides navigation.
/pricing/index.htmlDisplays subscription plans (Host, Agent, Both) dynamically from the DB.
/auth/become-a-host.htmlHost onboarding. Includes form for business details, county, and location.

2. Authentication

PathDescription
/auth/login.htmlLogin page (email or phone).
/auth/signup.htmlRegistration page (creates a 'user', not a host).
/auth/forgot-password.htmlPassword reset request.

3. Host Dashboard (Protected)

PathDescription
/host/index.htmlMain dashboard summary.
/host/listings/add-new/index.html11-step wizard to create a new listing.
/host/settings/index.htmlAccount, payout, and security settings.
/host/dashboard.htmlPWA Redirect target.

4. Admin Panel (Protected)

PathDescription
/admin/dashboard.htmlAdmin overview.
/admin/pricing/index.htmlManage pricing plans and feature comparisons.
/admin/setup/house-rules/index.htmlManage property house rules.

Database Schema

HostQ uses a MySQL database. Here are the core tables you need to know about.

1. `users`

Stores all users (hosts, agents, and admins).

CREATE TABLE users (
  user_id INT AUTO_INCREMENT PRIMARY KEY,
  first_name VARCHAR(100),
  last_name VARCHAR(100),
  email VARCHAR(150) UNIQUE,
  phone VARCHAR(20) UNIQUE,
  password_hash VARCHAR(255),
  user_type ENUM('user', 'host', 'agent', 'admin'),
  status ENUM('active', 'suspended')
);

2. `hosts`

Stores business details for users who have upgraded to a Host account.

CREATE TABLE hosts (
  host_id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT UNIQUE,
  host_display_id VARCHAR(20) UNIQUE, -- e.g. H123456
  business_name VARCHAR(255),
  phone VARCHAR(20) UNIQUE,
  alt_phone VARCHAR(20),
  whatsapp VARCHAR(20) UNIQUE,
  national_id VARCHAR(50) UNIQUE,
  county VARCHAR(100),
  location VARCHAR(255),
  description TEXT,
  status ENUM('pending', 'active', 'suspended')
);

3. `properties`

Stores the actual listings created by hosts.

CREATE TABLE properties (
  property_id INT AUTO_INCREMENT PRIMARY KEY,
  display_id VARCHAR(20) UNIQUE, -- e.g. P688247
  host_id INT,
  property_name VARCHAR(255),
  property_type VARCHAR(50),
  room_type VARCHAR(50),
  price_per_night DECIMAL(10,2),
  weekend_price DECIMAL(10,2),
  county INT,
  location_id INT,
  main_image VARCHAR(255),
  listing_status ENUM('pending', 'active', 'suspended')
);

4. `pricing_plans` & `pricing_features`

Stores the subscription tiers managed by the Admin.

CREATE TABLE pricing_plans (
  id INT AUTO_INCREMENT PRIMARY KEY,
  role ENUM('host', 'agent', 'both'),
  name VARCHAR(100),
  units VARCHAR(100),
  monthly_price DECIMAL(10,2),
  is_popular BOOLEAN
);

Public APIs

These APIs do not require authentication and are used by the public-facing pages.

`GET /api/public/locations/counties.php`

Returns a list of all Kenyan counties.

{
  "success": true,
  "data": [
    { "id": 1, "name": "Mombasa" },
    { "id": 47, "name": "Nairobi" }
  ]
}

`GET /api/public/locations/locations.php?county_id=47`

Returns the areas/locations within a specific county.

`GET /api/public/pricing/get.php`

Returns the live pricing plans and features to display on the `/pricing` page.

Host APIs (Protected)

These APIs require a valid user token or session.

`POST /api/host/listings/create.php`

Receives a `multipart/form-data` request to create a new property. It handles image uploads (storing them in `/uploads/properties/{property_id}/`) and saves the listing to the database.

Required Fields: `host_id`, `property_name`, `property_type`, `room_type`, `price_per_night`, `county`, `location_id`, `main_image` (file), etc.

`POST /api/auth/become-host.php`

Upgrades a standard user to a host. It validates duplicates (phone, WhatsApp, National ID) and generates a unique Host ID (e.g., `H648736`).

Authentication APIs

`POST /api/auth/signup.php`

Creates a standard user account (`user_type = 'user'`). Accepts JSON payload.

// Request
{
  "first_name": "John",
  "last_name": "Doe",
  "email": "john@example.com",
  "phone": "0712345678",
  "password": "securepassword"
}

`POST /api/auth/login.php`

Authenticates a user via email or phone and returns a session token.

`GET /api/auth/check-host-status.php?user_id=3`

Checks if the logged-in user already has a Host account. Used to prevent duplicate form submissions on the "Become a Host" page.

M-Pesa Payment Flow

HostQ uses Safaricom's Daraja API to handle payments for subscriptions and guest bookings.

  1. Initiation: The frontend sends a request to /api/mpesa/stk-push.php with the phone number and amount.
  2. STK Push: The backend sends the request to Safaricom, which triggers a PIN prompt on the user's phone.
  3. Waiting: The frontend polls /api/mpesa/status.php every 3 seconds to check if the user has entered their PIN.
  4. Callback: Safaricom sends the transaction details to /api/mpesa/callback.php. This script verifies the payment, updates the database, and assigns a booking ID or activates the subscription.
  5. Success: The polling detects the successful callback and displays the receipt to the user.
Important: The `callback.php` must be accessible via a public HTTPS URL and whitelisted in your Safaricom Daraja Developer Portal.