← Back to Hub|Technical Documentation

SiteWise Platform - Handover Documentation

Executive Summary

Project Overview

Project Name: SiteWise SaaS Platform
Client: Multi-tenant (MTN Nigeria as first tenant)
Platform Owner: SiteWise Technologies
Handover Date: 2026-02-18
Document Version: 1.0
Classification: Confidential

Platform Description

SiteWise is a multi-tenant SaaS platform for telecommunications site infrastructure audit management. It enables telecom operators to assign, track, and verify field maintenance audits through a suite of integrated applications.

Application Suite

| Application | Type | Users | Status | |-------------|------|-------|--------| | SiteWise Admin | Next.js Web App | Platform Admins, Org Admins | Production | | SiteSense Field Audit | Next.js PWA | Field Engineers | Production | | VendorView | Next.js Web App | Vendor Admins | Production | | Field Audit Mobile | Flutter (Android/iOS) | Field Engineers | Development |

Key Stakeholders

| Role | Name | Contact | Responsibility | |------|------|---------|----------------| | Project Lead | [NAME] | [EMAIL] | Overall delivery | | Lead Engineer | [NAME] | [EMAIL] | Architecture & code | | Database Admin | [NAME] | [EMAIL] | Supabase management | | DevOps | [NAME] | [EMAIL] | Deployment & CI/CD | | Product Owner | [NAME] | [EMAIL] | Requirements & UAT |

Technology Stack Summary

| Layer | Technology | Version | |-------|------------|---------| | Frontend | Next.js (App Router) | 15.x | | Mobile | Flutter | 3.x | | Backend | Supabase (PostgreSQL) | Latest | | AI | Google Genkit + Gemini | 1.13 | | Auth | Supabase Auth | Latest | | Storage | Supabase Storage | Latest | | Hosting | Firebase App Hosting / Cloud Run | Latest | | CI/CD | GitHub Actions | Latest |

2. Platform Architecture

2.1 High-Level Architecture

[MERMAID DIAGRAM: Platform architecture showing all 4 apps, shared Supabase backend, AI layer, storage, and auth]

2.2 Multi-Tenant Architecture

[MERMAID DIAGRAM: Organization → Vendor → Engineer hierarchy]

Tenant Isolation Strategy

  • Model: Pool (shared database with logical isolation)
  • Mechanism: Row Level Security (RLS) on all tables
  • Key Function: get_active_organization() returns the current user's active organization UUID
  • Enforcement: All tables have organization_id column with RLS policies that filter by active organization

Entity Hierarchy

  1. Platform Level: SiteWise super admins
  2. Organization Level: Client companies (MTN, Airtel, etc.)
  3. Vendor Level: Third-party audit companies
  4. Engineer Level: Individual field auditors

2.3 Data Flow

[MERMAID DIAGRAM: Data flow from assignment creation to audit submission]

  1. Org Admin creates assignment in Site Admin app
  2. Assignment appears in VendorView for vendor admin
  3. Vendor admin assigns engineer
  4. Engineer sees assignment in Field Audit app
  5. Engineer completes audit with photos and GPS
  6. AI analyzes images and generates reports
  7. Reports visible in Site Admin and VendorView

2.4 Authentication Architecture

| Component | Implementation | |-----------|---------------| | Auth Provider | Supabase Auth | | Token Type | JWT (access + refresh) | | Token Lifetime | 1 hour (configurable) | | Refresh Strategy | 5 minutes before expiry | | Session Storage | localStorage (web), SecureStorage (mobile) | | Multi-Factor | Not implemented (roadmap) | | Biometric | Flutter app only (fingerprint/face) |

2.5 AI Architecture

| Flow | Model | Purpose | Runtime | |------|-------|---------|---------| | analyze-equipment-image | Gemini 1.5 Flash | Equipment image scoring | Cloud | | damage-detection-flow | Gemini 1.5 Flash | Damage identification | Cloud | | generate-audit-report | Gemini 1.5 Flash | Pre/Post comparison | Cloud | | site-feedback-flow | Gemini 1.5 Flash | Chat support | Cloud | | suggest-image-quality-flow | Gemini 1.5 Flash | Quality suggestions | Cloud | | validate-image-quality | Gemini 1.5 Flash | Technical validation | Cloud | | verify-equipment | Gemini 1.5 Flash | Equipment verification | Cloud | | on-device-ml | TensorFlow Lite | Basic offline analysis | On-Device |

3. Database Schema

3.1 Supabase Project Details

| Property | Value | |----------|-------| | Project URL | https://ocibalcrfnzujnotdwpz.supabase.co | | Region | [REGION] | | PostgreSQL Version | 15.x | | RLS Enabled | Yes (all tables) |

3.2 Table Inventory

organizations

| Column | Type | Nullable | Default | Description | |--------|------|----------|---------|-------------| | id | UUID | NO | gen_random_uuid() | Primary key | | name | VARCHAR(255) | NO | — | Organization display name | | slug | VARCHAR(100) | NO | — | URL-safe identifier (unique) | | tenant_code | VARCHAR(20) | NO | — | Short code (unique) | | logo_url | TEXT | YES | — | Organization logo URL | | primary_color | VARCHAR(7) | YES | #3B82F6 | Brand primary color | | secondary_color | VARCHAR(7) | YES | #1E40AF | Brand secondary color | | settings | JSONB | YES | {} | Custom settings | | features | JSONB | YES | {} | Feature flags | | subscription_tier | VARCHAR(50) | YES | basic | Subscription level | | subscription_status | VARCHAR(50) | YES | trial | Billing status | | billing_type | VARCHAR(50) | YES | usage | Billing model | | deployment_type | VARCHAR(50) | YES | shared | Deployment model | | is_active | BOOLEAN | YES | true | Active flag | | created_at | TIMESTAMP | YES | NOW() | Creation timestamp | | updated_at | TIMESTAMP | YES | NOW() | Last update |

3.3 Entity Relationship Diagram

[MERMAID ER DIAGRAM: All tables with relationships]

3.4 RLS Policies

Example: sites table

| Policy Name | Operation | Using Clause | With Check | |-------------|-----------|-------------|------------| | sites_tenant_isolation | ALL | organization_id = get_active_organization() OR is_platform_admin() | Same |

3.5 Database Functions

| Function | Returns | Purpose | |----------|---------|---------| | get_active_organization() | UUID | Returns current user's active org | | is_platform_admin() | BOOLEAN | Checks if user is platform super admin | | get_user_org_role() | VARCHAR | Returns user's role in active org | | get_user_vendor_id() | UUID | Returns user's vendor association |

3.6 Edge Functions

| Function | Endpoint | Purpose | |----------|----------|---------| | submit-audit | POST /submit-audit | Process audit submissions | | send-verification-email | POST /send-verification | Email verification | | send-otp-email | POST /send-otp | Magic link auth |

3.7 Storage Buckets

| Bucket | Purpose | Max Size | Allowed Types | |--------|---------|----------|---------------| | audit-media | Audit photos/videos | 50MB | image/, video/ | | organization-assets | Logos, branding | 5MB | image/* | | form-templates | Template files | 10MB | application/json |

4. Application Details

4.1 SiteWise Admin

Repository & Deployment

| Property | Value | |----------|-------| | Repository | github.com/Toksey/studio | | Branch | main | | Hosting | Firebase App Hosting | | URL | [PRODUCTION_URL] | | Build Command | npm run build | | Node Version | 20.x |

Directory Structure

[Complete directory tree with descriptions]

Key Files

| File | Purpose | |------|---------| | lib/supabase-config.ts | Supabase client initialization | | lib/organization-context.tsx | Multi-tenant organization provider | | lib/auth-utils.ts | Token management and debug utilities | | app/login/page.tsx | Authentication page | | app/(app)/dashboard/page.tsx | Main dashboard | | app/api/sites/route.ts | Sites API endpoint |

Environment Variables

| Variable | Required | Description | |----------|----------|-------------| | NEXT_PUBLIC_SUPABASE_URL | Yes | Supabase project URL | | NEXT_PUBLIC_SUPABASE_ANON_KEY | Yes | Supabase anonymous key | | NEXT_PUBLIC_GOOGLE_MAPS_API_KEY | Yes | Google Maps API key | | RESEND_API_KEY | Yes | Email service API key |

5. Deployment & Infrastructure

5.1 Deployment Architecture

[MERMAID DIAGRAM: CI/CD pipeline for each app]

5.2 Deployment Procedures

Site Admin Deployment

# Step 1: Ensure all tests pass
npm run test:all

# Step 2: Build
npm run build

# Step 3: Deploy
gcloud run deploy site-admin \
  --image gcr.io/PROJECT/site-admin:latest \
  --region us-central1

# Step 4: Verify
curl https://site-admin-URL/api/health

Rollback Procedure

# Get previous revision
gcloud run revisions list --service site-admin

# Rollback to previous
gcloud run services update-traffic site-admin \
  --to-revisions PREVIOUS_REVISION=100

5.3 Environment Matrix

| Environment | Purpose | URL | Database | |-------------|---------|-----|----------| | Development | Local development | localhost:3000 | Supabase (dev) | | Staging | Pre-production testing | staging.sitewise.ng | Supabase (staging) | | Production | Live application | app.sitewise.ng | Supabase (prod) |

5.4 Monitoring & Alerting

| Service | Tool | Dashboard URL | |---------|------|---------------| | Application Logs | Google Cloud Logging | [URL] | | Error Tracking | (Recommend Sentry) | [URL] | | Uptime Monitoring | Google Cloud Monitoring | [URL] | | Database | Supabase Dashboard | https://supabase.com/dashboard |

5.5 Backup & Recovery

| Component | Backup Frequency | Retention | Recovery Procedure | |-----------|-----------------|-----------|-------------------| | Database | Daily (automatic) | 30 days | Supabase point-in-time recovery | | Storage | Real-time | — | Supabase Storage versioning | | Code | Git | Permanent | git checkout [commit] |

6. Known Issues & Technical Debt

6.1 Known Issues

| ID | Severity | Application | Description | Workaround | |----|----------|-------------|-------------|------------| | KI-001 | High | Field Audit PWA | Auth timeout on re-login causes infinite loading | Fixed in auth-provider.tsx v2.0 — verify deployment | | KI-002 | Medium | Site Admin | Google Maps API key not passed during Docker build | Set fallback in next.config.js | | KI-003 | Low | VendorView | AI insights use mock data | Pending Supabase integration | | KI-004 | Medium | All Apps | No error boundaries — provider failures crash entire app | Implement React error boundaries | | KI-005 | Low | Flutter | Deep links not configured for magic link auth | Configure URL schemes |

6.2 Technical Debt

| Item | Priority | Effort | Description | |------|----------|--------|-------------| | TD-001 | High | Medium | VendorView still uses mock data — needs full Supabase integration | | TD-002 | High | Large | Multi-tenant RLS policies need penetration testing | | TD-003 | Medium | Medium | No automated test suite in any application | | TD-004 | Medium | Small | Token refresh timer can create multiple timers on re-mount | | TD-005 | Low | Large | Flutter mobile app not yet feature-complete | | TD-006 | Low | Medium | No internationalization (i18n) support |

6.3 Security Considerations

| Area | Status | Notes | |------|--------|-------| | RLS Policies | Implemented | Needs security audit | | API Key Exposure | Risk | NEXT_PUBLIC keys in client bundle | | Token Storage | Adequate | localStorage (web), SecureStorage (mobile) | | Password Policy | Basic | Minimum 8 characters, no complexity rules | | Rate Limiting | Not Implemented | Recommend adding for auth endpoints | | CORS | Configured | Supabase default settings |

7. Operational Runbooks

Runbook 7.1: New Tenant Onboarding

-- Step 1: Create organization
INSERT INTO organizations (name, slug, tenant_code, subscription_tier)
VALUES ('New Company', 'new-company', 'NEWCO1', 'basic');

-- Step 2: Create admin user in Supabase Auth Dashboard

-- Step 3: Create organization membership
INSERT INTO organization_members (user_id, organization_id, role, is_default, status)
VALUES ('[NEW_USER_ID]', '[NEW_ORG_ID]', 'org_admin', true, 'active');

-- Step 4: Create profile
INSERT INTO profiles (user_id, role, name, email)
VALUES ('[NEW_USER_ID]', 'admin', 'Admin Name', 'admin@newcompany.com');

Runbook 7.2: User Locked Out

  1. Check user exists: SELECT * FROM auth.users WHERE email = 'user@example.com';
  2. Check for expired tokens in browser (ask user to run debugAuth())
  3. If token expired: Ask user to clear browser data or run emergencyClear()
  4. If account locked: Reset via Supabase Dashboard → Authentication → Users
  5. If password forgotten: Send password reset from Supabase Dashboard

Runbook 7.3: Database Migration

  1. Always backup first: Supabase Dashboard → Database → Backups
  2. Test on staging: Run migration on staging environment first
  3. Use additive changes: Never drop columns in production
  4. Verify all apps: Test all 4 applications after migration
  5. Monitor for 24 hours: Watch error logs after deployment

Runbook 7.4: Emergency Rollback

# 1. Identify the issue
gcloud logging read "severity>=ERROR" --limit=50

# 2. Rollback application
gcloud run services update-traffic [SERVICE] \
  --to-revisions [PREVIOUS_REVISION]=100

# 3. If database issue, restore from backup
# Use Supabase Dashboard → Database → Backups → Restore

# 4. Notify stakeholders
# Send incident report to team

Runbook 7.5: Adding a New Vendor to an Organization

-- Step 1: Create vendor
INSERT INTO vendors (name, organization_id, contact_email, status)
VALUES ('New Vendor', '[ORG_ID]', 'contact@vendor.com', 'active');

-- Step 2: Create vendor admin user in Supabase Auth

-- Step 3: Create organization membership with vendor association
INSERT INTO organization_members (
  user_id, organization_id, vendor_id, role, is_default, status
) VALUES (
  '[VENDOR_ADMIN_USER_ID]', '[ORG_ID]', '[VENDOR_ID]', 
  'vendor_admin', true, 'active'
);

8. Handover Acceptance Checklist

Documentation Delivered

  • [ ] Architecture documentation (this document)
  • [ ] Database schema with all tables documented
  • [ ] API documentation for all endpoints
  • [ ] Environment variable inventory
  • [ ] Deployment procedures for all 4 apps
  • [ ] Operational runbooks
  • [ ] User guide for field engineers

Access Transferred

  • [ ] GitHub repository access (all repos)
  • [ ] Supabase project owner access
  • [ ] Google Cloud project access
  • [ ] Firebase project access
  • [ ] Google Maps API key ownership
  • [ ] Resend (email) account access
  • [ ] Domain registrar access (if applicable)

Knowledge Transfer Sessions

  • [ ] Architecture walkthrough (2 hours)
  • [ ] Database schema and RLS review (2 hours)
  • [ ] Deployment pipeline demo (1 hour)
  • [ ] Multi-tenant architecture deep dive (2 hours)
  • [ ] AI/Genkit flows review (1 hour)
  • [ ] Known issues and workarounds (1 hour)

Acceptance Sign-Off

| Role | Name | Signature | Date | |------|------|-----------|------| | Outgoing Lead | | | | | Incoming Lead | | | | | Product Owner | | | | | DevOps | | | |