Skip to content
dkabduliPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Ibtida ๐Ÿ•Œ

Ibtida is a native iOS app built with SwiftUI that encourages consistent prayer, intentional worship, and charitable giving. Users track daily prayers, build streaks, earn credits, and donate to verified charities โ€” including card payments in CAD via Stripe and donation receipts stored in their profile. Admin features (global requests, credit conversion settings, moderation) are gated by Firebase Auth custom claims and Firestore rules; regular users see only their own data.

Repo layout: iOS app in Ibtida/ (Xcode project); Firebase (Functions, Firestore rules, scripts) in firebase/.


Purpose

Ibtida (โ€œa beginningโ€) connects two acts of worship:

  • Prayer (Salah) โ€” consistency and awareness through daily tracking
  • Charity (Sadaqah) โ€” giving via credits or card (CAD) to verified organizations

By combining prayer tracking with a credit-based system and real card donations, the app helps turn intention into action and build lasting spiritual habits.


Core Features (Current Build)

  • Auth โ€” Email/password (Firebase Auth); optional Google Sign-In
  • Onboarding โ€” Gender selection (brother/sister) once at sign-up; no redundant popup; gender drives prayer options and credit rules
  • Prayer tracking โ€” Log 5 daily prayers with gender-specific status options:
    • Brothers: In masjid (jamat), On time, Qada, Missed, Not logged; Jumuโ€™ah replaces Dhuhr on Friday (distinct status options)
    • Sisters: At home (on time), Qada, Missed, Not applicable ๐Ÿฉธ (streak-safe)
    • Sunnah and Witr (Isha) logged where applicable; status stored as enum raw value in Firestore; legacy values migrated on read (PrayerStatus.fromFirestore)
  • Fasting & Hijri โ€” Optional fasting prompt (Monday/Thursday, White Days); Hijri date display (Civil or Umm al-Qura); daily log and bonus credits via CreditRules
  • Last 5 weeks โ€” Horizontal progress grid: current week first (left), older weeks to the right; โ€œThis Weekโ€ highlighted
  • Prayer status sheet โ€” Full-height bottom sheet; first tap opens correctly (no blank screen); Duas tab: Ameen and Done buttons spaced (no overlap)
  • Streaks & credits โ€” Credits per prayer status (see table below); streak calculator; menstrual / โ€œNot applicable ๐Ÿฉธโ€ does not break streak
  • Journey โ€” Single โ€œJourneyโ€ title (nav bar); proportions and padding; milestones by total credits; week progress (5 squares); day detail sheet with gender-aware labels
  • Ramadan tab (optional) โ€” Shown when server enables via app_config/calendar_flags and date range is set; per-day fasting log (brothers: Yes/No; sisters: Yes / No / Not applicable ๐Ÿฉธ). See firebase/RAMADAN_CONFIG.md
  • Donate tab โ€” Overview, My Requests (userโ€™s own requests only: users/{uid}/requests), Charities (by category), Convert Credits; card donations via Stripe PaymentSheet (CAD only). No global community request feed for regular users.
  • Card donations โ€” Per-charity intake โ†’ createPaymentIntent (CAD) โ†’ Stripe PaymentSheet โ†’ finalizeDonation โ†’ receipt in users/{uid}/donations. If finalizeDonation fails after retries, user sees pending receipt state (no misleading โ€œThank Youโ€ until receipt is persisted).
  • Donation receipts โ€” Server-only writes (webhook + finalizeDonation); list and detail in Profile โ†’ Donations; all amounts and storage in CAD
  • Credit conversion โ€” Convert credits to dollar value (100 credits = $1 default); CreditConversionView; userโ€™s conversion requests in Firestore; admin can edit rate in Admin โ†’ Credit Conversion
  • Dua wall โ€” Global community duas; Ameen toggle (tap to add, tap again to remove); submit anonymous or public
  • Profile โ€” Name, email, credits, streak, member since; Donations history; theme; menstrual mode; About, Privacy, Terms; Diagnostics (dev)
  • Admin (when isAdmin) โ€” Admin tab visible; Dashboard (counts), All Requests (global requests), Credit Conversion (edit rate in admin/settings), Moderation (reports). Enforced by custom claim admin: true and Firestore rules.
  • Theme โ€” Warm design system; light/dark/system; muted gold accent; accessible typography
  • Network & errors โ€” Network status banner; centralized error handling; gentle language and time-aware UI

Admin Overlay (Security & Privacy)

  • Role โ€” Admin is determined only by Firebase Auth custom claim { admin: true }. No email or client-side flag in the app for who is admin.
  • Setting the first admin โ€” Use the local script (recommended) or deploy the callable and have an existing admin call it:
    1. Script: From firebase/functions:
      GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json node ../scripts/set-admin-claims.js admin@example.com
      User must sign out and sign in again for the claim to take effect.
    2. Callable โ€” Deploy setAdminRole; an existing admin can call it with { email: "newadmin@example.com" }.
  • What admins can do โ€” See Admin tab: Dashboard (overview counts), All Requests (global requests), Credit Conversion (edit admin/settings), Moderation (reports). All admin reads/writes go through Firestore rules that require request.auth.token.admin == true.
  • What regular users cannot do โ€” No Admin tab; no read/write to global requests, admin/*, or other usersโ€™ data. Donate tab shows only My Requests (users/{uid}/requests).
  • Testing โ€” See Ibtida/ADMIN_OVERLAY_TEST_CHECKLIST.md for step-by-step checks (non-admin vs admin, token refresh, CAD, privacy).

Credits & Scoring

Credits are earned by logging prayer status and are used for motivation and conversion to donations.

Status Credits
On Time 10
Late 6
Qada (made up) 4
Missed 0
Brothers โ€“ Masjid 18
Sisters โ€“ Home 12
Sisters โ€“ Not applicable ๐Ÿฉธ 0 (no streak break)
  • Daily max โ€” 50 credits (5 ร— 10).
  • New user bonus โ€” First 14 days get a 1.5ร— multiplier (see CreditRules).
  • Conversion โ€” 100 credits = $1.00 (default; admin can change in Admin โ†’ Credit Conversion).

Milestones (Journey)

Milestone Arabic Credits
Getting Started ุงู„ุจุฏุงูŠุฉ 0
Consistent ู…ูˆุงุธุจ 100
Steady ุซุงุจุช 250
Committed ู…ู„ุชุฒู… 500
Devoted ู…ุชูุงู†ูŠ 1,000
Elite ู…ุชู…ูŠุฒ 2,500
Master ุฎุจูŠุฑ 5,000
Legend ุฃุณุทูˆุฑุฉ 10,000

Donations (Card โ€“ CAD)

  • Currency โ€” CAD only (client, Cloud Functions, Stripe, Firestore, UI).
  • Flow โ€” Choose charity โ†’ intake form (name, email, amount โ‰ฅ $0.50 CAD) โ†’ createPaymentIntent (Cloud Function) โ†’ Stripe PaymentSheet โ†’ on success, finalizeDonation (Cloud Function) โ†’ receipt written to users/{uid}/donations/{intakeId}.
  • Receipts โ€” Server-only writes (webhook payment_intent.succeeded + finalizeDonation). Schema: amountCents, currency: "cad", createdAt, organizationId, organizationName, intakeId, paymentIntentId, status, etc.
  • Pending receipt โ€” If finalizeDonation fails after retries, the app shows a pending receipt state (e.g. โ€œPayment received; receipt may take a moment โ€” check Profile โ†’ Donationsโ€) instead of a full โ€œThank Youโ€ so the UX stays honest and transparent.
  • Profile โ†’ Donations โ€” Lists receipts (newest first); tap for detail (reference ID, amount in CAD, receipt URL if present).

Navigation

Five bottom tabs (fixed): Home, Journey, Donate, Dua, Profile. Profile is also reachable via toolbar button on each tab.

  • Regular users: Home, Journey, Donate, Dua, Profile. (Ramadan tab appears when server enables it via app_config/calendar_flags.)
  • Admin users: Same 5 tabs plus Admin when authService.isAdmin (Firebase Auth custom claim).

Tab contents:

  1. Home โ€” Todayโ€™s prayers (5 circles; Jumuโ€™ah replaces Dhuhr for brothers on Friday), Last 5 Weeks grid (current week left), progress summary; fasting prompt and Sunnah/Witr where applicable.
  2. Journey โ€” Milestones, week progress (5 squares), credit summary; single nav title โ€œJourneyโ€; day detail sheet; Last 5 Weeks horizontal scroll (current week first).
  3. Donate โ€” Overview, My Requests (userโ€™s own requests), Charities (by category), Convert Credits; card donation via Stripe (CAD).
  4. Dua โ€” Community dua wall; submit and view duas; Dua of the Day with Ameen toggle (tap to add, tap again to remove).
  5. Profile โ€” User info, credits, streak; Donations history; theme; settings; About; Diagnostics (dev).
  6. Ramadan (optional) โ€” Visible when server config enables it and date range is set; daily fasting log (brothers: Yes/No; sisters: Yes / No / Not applicable ๐Ÿฉธ).
  7. Admin (if isAdmin) โ€” Dashboard, All Requests, Credit Conversion, Moderation.

Tech Stack

  • iOS โ€” SwiftUI, iOS 17+
  • Backend โ€” Firebase (Auth, Firestore, Cloud Functions)
  • Payments โ€” Stripe (PaymentSheet); CAD only; test mode via pk_test_ / Stripe test cards
  • Key paths โ€” All Firestore paths are centralized in Core/FirestorePaths.swift. Main ones: users/{uid}, users/{uid}/donations, users/{uid}/receipts, users/{uid}/requests, users/{uid}/prayerDays, users/{uid}/prayers, users/{uid}/ramadanLogs, users/{uid}/dailyLogs, users/{uid}/journey; organizationIntakes, payments; global duas, daily_duas, charities, donation_requests; app_config (e.g. calendar_flags); admin-only: admin/*, global requests, reports, credit_conversion_requests.

Firestore Rules (Summary)

  • Users โ€” Read/write only own users/{userId} and subcollections (donations, requests, prayers, prayerDays, dailyLogs, ramadanLogs).
  • Donations โ€” Read-only for user on users/{uid}/donations; writes only by backend.
  • app_config โ€” Read for authenticated users; write only by admin (e.g. Ramadan calendar flags).
  • Global requests โ€” Read/write only if request.auth.token.admin == true.
  • Reports โ€” Any authenticated user can create; only admin can read/delete.
  • credit_conversion_requests โ€” User can create/read/update/delete only docs where userId == request.auth.uid; admin can read all.
  • admin โ€” Read/write only if request.auth.token.admin == true.

Full rules in firebase/firestore.rules.


Setup (Developers)

  • Requirements โ€” Xcode 15+, iOS 17+ target.
  1. Xcode โ€” Open Ibtida/Ibtida.xcodeproj; use the Ibtida scheme.
  2. Firebase โ€” Add GoogleService-Info.plist; enable Auth (email/password, optional Google) and Firestore.
  3. Stripe โ€” In Info.plist set StripePublishableKey to your test key (pk_test_...). Backend: Stripe secret and webhook secret (Cloud Functions config/secrets).
  4. Cloud Functions โ€” Deploy from firebase/functions. Deployed functions: createPaymentIntent (CAD), finalizeDonation, stripeWebhook, health, setAdminRole (callable, admin-only). Set secrets for Stripe.
  5. Firestore rules โ€” Deploy from firebase/: firebase deploy --only firestore:rules.
  6. First admin (optional) โ€” Run from firebase/functions:
    GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json node ../scripts/set-admin-claims.js your-admin@example.com
    Then have that user sign out and sign in again.

Stripe test (donations)

  • Use test card 4242 4242 4242 4242 for success.
  • Receipts appear under Profile โ†’ Donations after finalizeDonation (and/or webhook).

Project Structure (High Level)

Ibtida/Ibtida/Ibtida/          # iOS app (Xcode: Ibtida/Ibtida.xcodeproj)
โ”œโ”€โ”€ IbtidaApp.swift
โ”œโ”€โ”€ Core/
โ”‚   โ”œโ”€โ”€ FirestorePaths.swift  (single source for all collection/document paths)
โ”‚   โ”œโ”€โ”€ BEHAVIOR_LOCK.md      (behaviors that must not change; in-code checklist refs)
โ”‚   โ”œโ”€โ”€ LoadState.swift       (shared loading state for list screens)
โ”‚   โ”œโ”€โ”€ StripeConfig.swift, DateUtils.swift, DonationAmountParser.swift
โ”‚   โ”œโ”€โ”€ DesignSystem.swift, SemanticDesignSystem.swift, AppTheme.swift
โ”‚   โ”œโ”€โ”€ CreditRules.swift, PrayerStatusColors.swift, HijriCalendar.swift
โ”‚   โ”œโ”€โ”€ ThemeManager.swift, GentleLanguage.swift, TimeAwareUI.swift, LogLevel.swift
โ”‚   โ””โ”€โ”€ NetworkErrorHandler.swift, PerformanceCache.swift, AppStrings.swift
โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ Charity.swift, Donation.swift, DonationError.swift, DonationType.swift
โ”‚   โ”œโ”€โ”€ CreditConversionRequest.swift, DailyLog.swift, RamadanConfig.swift, RamadanLog.swift
โ”‚   โ”œโ”€โ”€ Prayer.swift (PrayerStatus.fromFirestore, gender-specific lists)
โ”‚   โ”œโ”€โ”€ PrayerModels.swift, UserProfile.swift, RequestModel.swift
โ”‚   โ”œโ”€โ”€ Dua.swift, DuaRequest.swift
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ AuthService.swift (isAdmin, refreshAdminClaim)
โ”‚   โ”œโ”€โ”€ FirestoreService.swift, UserProfileFirestoreService.swift (profile cache 60s, clear on sign-out)
โ”‚   โ”œโ”€โ”€ UserRequestsFirestoreService.swift (user requests: load/create)
โ”‚   โ”œโ”€โ”€ PrayerLogFirestoreService.swift, PrayerDayFirestoreService.swift, DailyLogFirestoreService.swift
โ”‚   โ”œโ”€โ”€ StreakCalculator.swift, CalendarConfigManager.swift, RamadanLogFirestoreService.swift
โ”‚   โ”œโ”€โ”€ NetworkMonitor.swift
โ”‚   โ”œโ”€โ”€ FirebaseFunctionsService.swift, UserDonationsFirestoreService.swift
โ”‚   โ”œโ”€โ”€ OrganizationIntakeService.swift, CharityService.swift, DonationService.swift
โ”‚   โ”œโ”€โ”€ CreditConversionService.swift, DuaFirestoreService.swift
โ”‚   โ””โ”€โ”€ LocalStorageService.swift, UIStateFirestoreService.swift
โ”œโ”€โ”€ ViewModels/
โ”‚   โ”œโ”€โ”€ HomeViewModel.swift, HomePrayerViewModel.swift
โ”‚   โ”œโ”€โ”€ JourneyViewModel.swift, JourneyProgressViewModel.swift, JourneyMilestoneViewModel.swift
โ”‚   โ”œโ”€โ”€ RamadanViewModel.swift
โ”‚   โ”œโ”€โ”€ DonationViewModel.swift, CreditConversionViewModel.swift, PaymentFlowCoordinator.swift
โ”‚   โ”œโ”€โ”€ CategoryCharitiesViewModel.swift, CommunityRequestsViewModel.swift (admin-only use)
โ”‚   โ””โ”€โ”€ DuaViewModel.swift
โ”œโ”€โ”€ Views/
โ”‚   โ”œโ”€โ”€ Home/       (HomeView, HomePrayerView โ€” prayer grid, status sheets)
โ”‚   โ”œโ”€โ”€ Journey/    (JourneyView, JourneyHomeView, JourneyMilestoneView)
โ”‚   โ”œโ”€โ”€ Ramadan/    (RamadanTabView, RamadanDaySheet โ€” optional tab)
โ”‚   โ”œโ”€โ”€ Donate/     (DonationsPage [My Requests], OrganizationIntakeView, CategoryCharitiesView, CreditConversionView)
โ”‚   โ”œโ”€โ”€ Dua/        (DuaWallView)
โ”‚   โ”œโ”€โ”€ Profile/    (ProfileView, DonationsHistoryView)
โ”‚   โ”œโ”€โ”€ Requests/   (RequestsView โ€” userโ€™s own requests; LoadState + UserRequestsFirestoreService)
โ”‚   โ”œโ”€โ”€ Admin/      (AdminTabView, AdminDashboardView, AdminRequestsView, AdminCreditConversionView, AdminModerationToolsView)
โ”‚   โ”œโ”€โ”€ Auth/       (LoginView)
โ”‚   โ”œโ”€โ”€ Onboarding/ (GenderOnboardingView)
โ”‚   โ”œโ”€โ”€ Settings/   (SettingsView, AppSettingsView, DiagnosticsView)
โ”‚   โ”œโ”€โ”€ Components/ (DuaComponents, EmptyStates, ErrorHandling, NetworkStatusBanner)
โ”‚   โ””โ”€โ”€ RootTabView.swift (tab order: Home, Journey, Donate, Duas, Profile; persist selected tab)
โ”œโ”€โ”€ REFACTOR_PLAN.md, QUALITY_GATE_CHECKLIST.md
โ””โ”€โ”€ Resources/      charities.json; Assets.xcassets

firebase/
โ”œโ”€โ”€ firestore.rules           (user-only + admin-only)
โ”œโ”€โ”€ RAMADAN_CONFIG.md         (how to enable Ramadan tab via app_config/calendar_flags)
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ set-admin-claims.js   (set admin custom claim by email; run locally)
โ””โ”€โ”€ functions/
    โ””โ”€โ”€ index.js              createPaymentIntent (CAD), finalizeDonation, stripeWebhook, health, setAdminRole (callable)

Code quality & refinement

  • Firestore paths โ€” All collection/document strings live in Core/FirestorePaths.swift; use these constants instead of literals. No hardcoded collection names in ViewModels or services.
  • Behavior lock โ€” Core/BEHAVIOR_LOCK.md and in-code comments define behaviors that must stay identical across refactors (navigation, sheets, credits, dates, privacy). Check before changing flows or data.
  • Loading state โ€” List screens use LoadState (idle, loading, loaded, empty, error) and LoadState.showLoadingPlaceholder(loadState, isEmpty) to avoid blank-first-tap and double-fetch.
  • Logging โ€” Use AppLog (error, network, state, verbose) in Core/LogLevel.swift for debug output; respect LogLevel.current to reduce console noise.
  • Services โ€” Firestore access is centralized in services (e.g. UserRequestsFirestoreService, UserProfileFirestoreService with optional 60s profile cache). Views/ViewModels orchestrate; services perform reads/writes.
  • Quality gate โ€” After changes, run through Ibtida/QUALITY_GATE_CHECKLIST.md (build, no behavior change, no clipping, no blank first-tap, no fetch loops).

Notes

  • Credits are for in-app motivation and conversion only; they do not represent religious reward.
  • Donation receipts are written only by the backend; client never writes to users/{uid}/donations.
  • Prayer status is stored as enum raw value in Firestore; display labels are gender-specific in the UI; legacy strings (e.g. "later", "made up") are mapped on read via PrayerStatus.fromFirestore.
  • Last 5 Weeks order: index 0 = current week (left); data from DateUtils.lastNWeekStarts(5); โ€œThis Weekโ€ emphasized.
  • Islamic guidelines โ€” Prayer terminology (e.g. Jamaโ€™ah, Qada, โ€œNot applicable ๐Ÿฉธโ€) and donation flows are aligned with mainstream fiqh; โ€œNot applicable ๐Ÿฉธโ€ does not penalize streaks; donations are transparent (CAD, receipt state, no misleading success until receipt is saved).
  • App icon โ€” Use the same in-app logo for the iOS App Icon (see Ibtida/JOURNEY_DEBUG_CHECKLIST.md for App Icon consistency notes).

Related docs (in repo)

  • Ibtida/Core/BEHAVIOR_LOCK.md โ€” Behaviors that must remain identical; module inventory; in-code checklist references
  • Ibtida/REFACTOR_PLAN.md โ€” Refinement passes: path centralization, LoadState, services, profile cache; file-by-file rationale
  • Ibtida/REFINEMENT_PASS_SUMMARY.md โ€” Latest refinement pass: FirestorePaths, dead code removal, logging, UI consistency
  • Ibtida/QUALITY_GATE_CHECKLIST.md โ€” Post-refactor verification: build, no behavior change, no clipping, no blank first-tap, no fetch loops
  • Ibtida/ADMIN_OVERLAY_TEST_CHECKLIST.md โ€” How to set admin, test non-admin vs admin, token refresh, CAD, privacy
  • Ibtida/JOURNEY_DEBUG_CHECKLIST.md โ€” Production QA checklist, App Icon consistency, Islamic guidelines section
  • firebase/RAMADAN_CONFIG.md โ€” Enable Ramadan tab via app_config/calendar_flags
  • firebase/functions/README.md โ€” Cloud Functions setup

Ibtida โ€” a beginning.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages