Truth Document

This document is password protected

AskTheMidwife

Complete Project Truth Document · March 2026

71,567 Lines of Code
327 Source Files
5 Platforms
42+ Cloud Functions
1

What Is This Project?

AskTheMidwife is a UK-based digital health platform that connects new mothers with qualified NMC-registered midwives via async messaging. The NHS stops community midwife support by day 10 postpartum — we pick up where they leave off.

LIVE
iOS App
SwiftUI · Firebase · StoreKit 2
Files109
Lines of Code25,590
LanguageSwift
85%
Android App
Kotlin · Jetpack Compose · Material 3
Files89
Lines of Code15,008
LanguageKotlin
LIVE
Midwife Dashboard
React 18 · TypeScript · Material UI
Files37
Lines of Code14,056
LanguageTypeScript
LIVE
Cloud Functions
Node.js 20 · TypeScript · Firebase
Files24
Lines of Code10,983
Functions42+
2

System Architecture

Three client apps connect through Firebase to a shared backend of Cloud Functions, Firestore, Storage, and external integrations.

Platform Architecture Overview
Client Apps
iOS App
SwiftUI · MVVM
Android App
Compose · MVVM
Dashboard
React · MUI
↔
Firebase
Authentication
Email · Apple · RBAC
Firestore
18 Collections · Real-time
Cloud Functions
42+ Functions · Node.js 20
Storage + FCM
Photos · Audio · Push
↔
External Services
Stripe
Payments
SendGrid
Emails
Slack
Alerts
Sentry
Monitoring
3

Codebase Breakdown

Lines of Code by Platform
iOS App
25,590
Android App
15,008
Dashboard
14,056
Cloud Functions
10,983
Landing Sites
2,385
Investor Docs
3,545
Code Distribution
71.5K total lines
iOS App 35.7%
Android 21.0%
Dashboard 19.6%
Functions 15.3%
Other 8.4%
4

iOS App (MidwifeSupport)

Live on the App Store. Built with SwiftUI, MVVM architecture, Firebase backend, StoreKit 2 subscriptions. 109 Swift files totalling 25,590 lines.

iOS File Breakdown by Category
Views (52)
14,304 lines
Services (27)
5,900 lines
Components (10)
2,173 lines
ViewModels (7)
2,204 lines
Config (5)
1,031 lines
Models (12)
737 lines

iOS Top Files

FileLinesPurpose
MidwifeConversationsView.swift905Midwife-side conversation list (largest view)
MidwifeChatViewModel.swift872Chat state, messaging, photo/audio handling
ConversationDetailView.swift738Chat UI with messages, input, attachments
MidwifeSupportApp.swift529App entry, Firebase init, deep links, push
FirestoreService.swift490Core Firestore CRUD (.shared singleton)
SubscriptionService.swift420StoreKit 2, purchase flow, receipt validation
ShareConcernView.swift420New concern form with severity selection
OnboardingView.swift420Multi-step onboarding wizard
AuthService.swift380Firebase Auth, Apple Sign-In, sessions
HealthDashboardView.swift350Health tracking hub
5

Android App (MyMidwife)

85% complete. Kotlin with Jetpack Compose, Material 3, Hilt DI, Firebase backend. 89 Kotlin files, 15,008 lines.

Android File Breakdown by Category
Screens (22)
7,903 lines
ViewModels (14)
2,821 lines
Services (12)
2,041 lines
Utilities (3)
650 lines
Theme (5)
500 lines
Components (4)
330 lines

Key Android Services

🔍

Red Flag Detection

17 keywords, 3 severity levels (critical, high, medium). Scans all messages client-side.

🎤

Audio Recorder

M4A recording, AAC codec 44.1kHz/128kbps, max 5 min, auto-upload to Firebase Storage.

📸

Photo Upload

Auto-compression to max 2MB, JPEG quality 80, scales to 2048x2048. Batch upload support.

👍

Message Reactions

10 emoji reactions with real-time sync. Max 100 reactions per message.

6

Midwife Dashboard

React web app for midwives and admins. Real-time conversation queue, patient context, messaging, analytics, security monitoring. 37 files, 14,056 lines.

Dashboard Pages by Lines of Code
Conversations
2,001
Admin
1,200
Users
1,124
Queue
938
Analytics
547
Compliance
496
Testing
446

Dashboard Features

💬

Real-Time Queue

Live conversation queue with severity prioritisation, ETA calculation, red flag alerts, and one-click claiming.

🛡

Security Command Centre

6-tab security dashboard: KPIs, events, health, auth, audit chain integrity, performance metrics.

📊

Analytics

Conversation trends, response times, satisfaction scores, resolution rates. Export to CSV/PDF.

🧪

Testing Suite

60+ automated tests covering Cloud Functions, Firestore, Storage, messaging, red flags, GDPR.

7

Firebase Backend

24 TypeScript files, 10,983 lines. 42+ Cloud Functions covering auth, messaging, payments, GDPR, monitoring, and more.

Cloud Functions by Category
Auth & Accounts
8 functions
Notifications
6 functions
Email (SendGrid)
7 functions
GDPR & Consent
8 functions
Security & Health
8 functions
Payments
4 functions
Slack & Messaging
7 functions

Firestore Collections (18)

CollectionRead AccessWrite AccessPurpose
users/{userId}Owner, StaffOwner (≤50KB)User profiles + subcollections
conversations/{id}Participant, StaffLimited fieldsChat conversations
conversations/{id}/messagesParticipant, StaffCreate only (≤5000 chars)Chat messages
midwives/{id}StaffSelf or AdminMidwife profiles
audit-logs/{id}AdminFunctions onlySHA256 hash chain audit
consents/{userId}/recordsOwner, StaffAppend onlyGDPR consent tracking
conversationRatings/{id}Owner, StaffOwner (1-5 stars)Star ratings & feedback
security-logs/{id}DisabledAuth users (UID match)Security events
8

App Screenshots

Real screenshots from the live iOS app. The Android app mirrors these screens in Jetpack Compose with Material 3 styling.

9

User Journey Flow

New User → First Conversation
Download App
Disclaimer
Medical safety
Sign Up
Email or Apple
Onboarding
Baby info, feeding
Home Screen
one introductory conversation
Chat Flow — Share Concern to Resolution
Share Concern
Red Flag
Scan
Join Queue
Severity-based
Midwife
Claims
Live Chat
Text, photos, voice
Resolved
Rating prompt
Midwife Dashboard Flow
Login
Email + RBAC
Queue View
Severity priority
Claim & Chat
Full patient context
Red Flag?
Escalate
Slack + priority
Message Lifecycle
User Sends
Message
Firestore
Write
Red Flag
Check
Push
Notification
Dashboard
Real-time
Midwife
Reads
10

Red Flag Detection System

Dual-layer safety system: client-side scanning (iOS + Android) and server-side Cloud Function verification. 17 keywords across 3 severity levels trigger automatic escalation.

Red Flag Detection Pipeline
User Types
Message
Client-Side
Scan (17 kw)
Message
Sent
Server-Side
Scan
Flag &
Escalate

Emergency Keywords

baby not breathing blue baby severe bleeding can't breathe chest pain seizure unconscious

Urgent Keywords

suicidal self-harm thoughts of harming high fever heavy bleeding soaking pads bright red blood

Warning Keywords

severe headache blurred vision fits
Server-Side Actions: Sets metadata.hasRedFlag: true on message, auto-bumps unassigned conversations to severe, sends urgent Slack alert with red colour code to #askthemidwife-queue.
11

Subscription & Pricing

Free Taster
£0
forever
  • One introductory text conversation
  • Text only
  • Queue response time
  • No card required
Premium
£159/mo
£1,299/year (save 17%)
  • 60 new conversations per calendar month
  • 15 min guaranteed response
  • Personal midwife
  • Voice notes
  • Expert specialist booking
Unit Economics — Standard Plan
£79 per month
Midwife Pay £36
Gross Profit £31.15
Apple Cut (15%) £11.85
Message Pack Add-Ons
5 messages
£14.99
15 messages
£34.99
30 messages
£59.99

Consumable in-app purchases. Never expire. 45-50% gross margin.

Conversion Funnel (Base Case)
650,000 UK births/year
1.2% download
8,000 app downloads
50% start trial
4,000 free trials
12% convert to paid
960 paying users
£79/mo average
£1.1M ARR
12

Security & Compliance

🔒

RBAC Custom Claims

Firebase custom claims: {role: "midwife"} or {role: "admin"}. All Firestore rules enforce role checks.

📜

GDPR Compliance

Data export (signed URL, 7-day expiry), right-to-be-forgotten deletion, append-only consent records with IP/user-agent.

🔗

SHA256 Audit Chain

Blockchain-style hash chain for tamper detection. Sequence numbering + previous hash tracking. Integrity verification on demand.

⏱

Rate Limiting

Firestore-backed per-endpoint limits. 60/min for messages, 10/hr for conversations, 1/24hr for data exports.

🏥

NHS DTAC

Separate _auditLog collection for NHS Digital Technology Assessment Criteria. Clinical safety disclaimer on launch.

🔍

Health Checks

Every 30 min: validate Firestore, Auth, Storage, queue stats. Heartbeat every 15 min for uptime tracking.

Authentication & Authorization Flow
User Login
Email / Apple
Firebase Auth
ID Token
Custom
Claims Check
RBAC
user/midwife/admin
Firestore
Rules Enforce
13

CI/CD & Testing

GitHub Actions Pipeline
Push / PR
iOS CI
Build + Test
Security
Gates
Merge to
Main?
Deploy
TestFlight + Firebase

Workflows

WorkflowTriggerPurpose
ios-ci.ymlPull RequestBuild + test iOS app
ios-testflight.ymlMerge to mainDeploy to TestFlight
firebase-hosting-pull-request.ymlPull RequestPreview deploy web apps
firebase-hosting-merge.ymlMerge to mainDeploy web apps to production
security-gates.ymlPull RequestRun security checks

Testing Coverage

📱

E2E Tests (Maestro)

28 YAML test specs covering login, navigation, chat, health tracking, subscriptions, edge cases, and complete user journeys.

🛡

Security Rules Tests

Firestore security rules test suite validating CRUD permissions for all 18 collections against user roles.

☁

Server-Side Tests

Cloud Function runTestSuite with 18+ integration tests: Auth, Firestore, Storage, Red Flags.

📨

APNS Test Payloads

5 test notification payloads: user message, midwife reply, assignment, severe queue entry, plus send script.

14

Marketing & Investor Materials

🌐

Landing Site (HTML)

Static marketing page: hero, features, pricing (£15-99/mo), blog, referral. Google Analytics + Meta Pixel.

⚡

Landing Site (React)

React 19 + Vite + Framer Motion. Animated hero, pricing, phone mockup, Terms & Privacy pages.

📊

Pitch Deck

22-slide interactive HTML presentation. Dark theme, SVG charts, keyboard/swipe navigation. Full financial model.

📝

Investor Contract

SEIS/EIS subscription agreement with interactive equity calculator, live cap table, shareable URL params.

💰

Investor Summary

Visual 1-page overview: problem, product, market, SEIS relief, 3 investment tiers (£50k-250k), ROI scenarios.

📑

Documentation

18 markdown docs: README, Setup, Deployment, Security, Testing, System Design, Financial Model, GDPR Runbook.

15

Project Stats Summary

Code Volume by Component
ComponentFilesLinesLanguage
iOS App10925,590Swift/SwiftUI
Android App8915,008Kotlin/Compose
Dashboard3714,056React/TypeScript
Cloud Functions2410,983TypeScript
Firestore Rules1428Rules DSL
Storage Rules180Rules DSL
Landing (HTML)1~700HTML/CSS/JS
Landing (React)~15~1,685React/JSX
Pitch Deck11,025HTML/CSS/JS
Investor Contract11,293HTML/CSS/JS
Investor Summary11,227HTML/CSS/JS
E2E Tests28~600YAML
Scripts15~1,500JavaScript
CI/CD5~300YAML
TOTAL~327~71,567
Firebase Infrastructure
Callable Funcs
45+
Collections
18
DB Triggers
12
Rate Limiters
10
Scheduled
8
Storage Paths
7
Email Templates
6

Largest Files (Top 10)

ConversationsPage.tsx
2,001
investor-contract
1,293
TestingContext.tsx
1,238
investor-summary
1,227
AdminPage.tsx
1,200
UsersPage.tsx
1,124
pitch-deck
1,025
DashboardPage.tsx
938
MidwifeConversationsView
905
MidwifeChatViewModel
872