CookLoop is an iOS social cooking platform where users can publish recipes, discover new dishes, engage with other cooks, and compete through a gamified leaderboard system.
This README documents the implemented functionality across the app in detail.
- Project Overview
- Architecture
- Authentication and Session Flows
- Main App Navigation
- Feature Details by Screen
- Recipe Lifecycle (End to End)
- Social Features
- Gamification and Leaderboard
- Admin Panel and Moderation
- Data Models
- Firestore Data Layout
- Service Layer Responsibilities
- ViewModel Responsibilities
- External APIs and Integrations
- Theme System
- Current Constraints and Known Limitations
- Run and Build Notes
CookLoop is built with SwiftUI using an MVVM structure.
Core capabilities:
- Account creation and login with Firebase Authentication.
- User-generated recipes with image, ingredients, steps, difficulty, time, and tags.
- Global and following feeds with filtering and sorting.
- Likes, comments, replies, reposts, bookmarks, and follows.
- Profile management, recipe editing/deletion, and password change.
- In-app activity notifications.
- Weekly leaderboard with engagement scoring.
- Admin dashboard for user, recipe, and report moderation.
- External recipe discovery via TheMealDB API.
The codebase is organized into these layers:
Views: Screen-level SwiftUI views.Components: Reusable UI pieces (cards, image picker, remote image renderer, profile header, admin panel components).ViewModels: Feature logic, asynchronous operations, state management, and Firestore listeners.Models: Codable entities and Firestore mapping utilities.Services: Infrastructure and domain services for Firebase setup, notifications, and gamification.
Runtime flow:
- App launch initializes Firebase in
FirebaseManager. AuthViewModelresolves auth session and current user document.- If authenticated user is admin, app routes to Admin Panel.
- Otherwise app routes to the 5-tab user app experience.
Implemented in SignupView + AuthViewModel.signup(...):
- Collects name, email, password.
- Creates Firebase Auth account.
- Creates Firestore user profile under
/users/{uid}with default gamification fields:xp = 0level = "Beginner Cook"badges = []- counters initialized to zero (
totalRecipesPosted,totalLikesReceived,totalComments,totalBookmarks).
- Stores session in
userSessionand loadscurrentUser.
Implemented in LoginView + AuthViewModel.login(...):
- Authenticates with Firebase Auth email/password.
- Loads user profile document (
fetchUser). - Enforces ban policy:
- If
isBanned == true, user is forcibly logged out and shown an access error.
- If
- Triggers weekly gamification recalculation check.
Implemented in AuthViewModel.signOut():
- Signs out through Firebase Auth.
- Clears in-memory user/session state.
- Routes back to login screen.
- Session comes from
auth.currentUseron app start. - Profile document is fetched to hydrate app state.
- Legacy fallback is supported when user docs have missing/empty
idby using document ID/UID.
Standard users are routed to a tabbed experience:
- Feed
- Discover
- Upload (floating action button behavior)
- Profile
- Activity
Additional navigation:
- Global recipe/user search sheet is available from primary surfaces.
- Recipe cards navigate to detailed recipe view.
- User names/profile actions navigate to user profiles.
Admin users bypass tabs and are routed to the admin dashboard.
- Email/password input.
- Sign-in action with loading and error state feedback.
- Opens sign-up sheet.
- Access to global search overlay entry points.
- Name/email/password registration form.
- Account creation with Firestore bootstrap of profile and game stats.
- Automatic post-signup login/session initialization.
Primary features:
- Feed mode switch:
For You: global feed.Following: only users that current user follows.
- Filter controls:
- Difficulty filter (including easy recipes).
- Cooking time filter (quick recipes).
- Bookmark-focused filtering.
- Sort options:
- Newest first.
- Oldest first.
- Most liked.
- Real-time updates from Firestore listeners.
Recipe card interactions:
- Like/unlike recipe.
- Bookmark/unbookmark recipe.
- Repost recipe.
- Quote repost (repost with comment text).
- View creator profile.
- Navigate to recipe detail.
- Show unread indicators (
New,New comment) where applicable.
- Curated collection tiles based on cooking themes/tags.
- Tag-specific discovery view for community recipes.
- External API recipe browsing (
Classic Recipes). - API cards show image/title/category/region and navigate to API detail view.
Curated categories implemented include:
- Cozy Breakfasts
- Spicy Dinners
- Sweet Treats
- Quick Fixes
- Healthy Bowls
- Displays read-only details for external recipe:
- Hero image
- Recipe name
- Category
- Region/area
- Full instructions
Recipe creation form supports:
- Title.
- Image input:
- Device image picker.
- Optional remote URL path.
- Dynamic ingredient list (add/remove rows).
- Dynamic step list (add/remove rows).
- Cooking time selector.
- Difficulty selector:
- Easy
- Intermediate
- Hard
- Multi-select tags.
Submit behavior:
- Validates required fields.
- Persists recipe to Firestore.
- Awards gamification points for posting.
- Updates profile-level posting counters.
Full recipe experience includes:
- Hero image and primary metadata.
- Creator name with navigation to creator profile.
- Time, difficulty, tags.
- Like button and total like count.
- Structured ingredients section.
- Step-by-step cooking instructions.
- Contextual visual tips in long instructions sections.
- Comment system with reply support.
- Comment composer for current user.
- CTA to start cooking flow.
For current user:
- Profile header with avatar, name, bio.
- XP level and badge display.
- Theme selector.
- Edit profile action.
- Logout action.
- Two content tabs:
- My Recipes
- Saved Recipes
- Recipe management from grid:
- Edit recipe
- Delete recipe
For other users:
- Same identity and stats display.
- Follow/unfollow action.
- Their posted recipes.
Profile management features:
- Update name, bio, and profile image.
- Change password with re-authentication.
Two major modes:
Notifications mode:
- Real-time stream of user activities:
- likes
- comments
- follows
- reposts
- Per-notification iconography and relative timestamps.
- Optional attached text for relevant events.
Leaderboard mode:
- Weekly top users ranking.
- Ordered by engagement score and consistency.
- Shows top entries and current user rank context.
Dashboard metrics:
- Total users
- Total recipes
- Total reports
- Pending reports
Management surfaces:
Users management:
- Search/filter users.
- See account summary (email, content counts, admin/banned state).
- Ban/unban actions.
Recipes management:
- Browse uploaded recipes.
- Review metadata and engagement.
- Delete problematic recipes.
Reports management:
- View report queue and status.
- Resolve report.
- Delete target content depending on report type.
- Ban user for user-targeted reports.
- Creation:
- User builds recipe in Upload screen and submits.
- Firestore document is created with metadata and timestamps.
- Distribution:
- Recipe appears in global feed listeners.
- Can appear in tag-based discovery views.
- Can be reposted by other users.
- Engagement:
- Others can like, bookmark, comment, and reply.
- Notifications are sent to owner for key actions.
- Owner receives gamification points based on interactions.
- Persistence and retrieval:
- Recipe supports detail view, feed cards, profile lists, and saved lists.
- Maintenance:
- Owner can edit or delete from profile.
- Admin can remove recipe from admin panel.
- Implemented via reciprocal subcollections:
/users/{me}/following/{target}/users/{target}/followers/{me}
- Supports follow/unfollow toggle.
- Tracks follower/following counts.
- Sends follow notification to target user.
- Like presence tracked in
/recipes/{recipeId}/likes/{uid}. - Aggregate count mirrored in recipe
likesfield. - Uses transactions/batches for consistency.
- Like action can trigger owner XP award.
- Stored in
/users/{uid}/savedRecipes/{recipeId}withsavedAttimestamp. - Profile Saved Recipes tab reconstructs recipe list by IDs.
- Bookmark actions can award user XP.
- Top-level comments in
/recipes/{recipeId}/comments/{commentId}. - Replies nested under comment
repliessubcollection. - Real-time listener updates comment tree.
- Comment and reply creation can award XP and send notifications.
- Repost documents in
/reposts/{repostId}. - Supports plain repost and quote repost.
- Feed view merges repost activity with recipe content.
- Repost sends notification to original creator.
Gamification events tracked for actions:
- Recipe posted
- Like received
- Comment added
- Bookmark action
XP and levels:
- XP accumulates over user actions.
- Level resolves from XP thresholds:
- Beginner Cook
- Home Chef
- Pro Chef
- Master Chef
Badges currently awarded include:
- Recipe Creator
- Top Contributor
- Trending Chef
- Community Helper
- Loved Chef
Weekly stats:
- Stored under
/weeklyStats/{weekId}/users/{userId}. - Engagement score and active-day consistency are updated.
- Leaderboard ranks users weekly from this dataset.
Admin-only access is enforced through currentUser.isAdmin routing at app launch.
Moderation capabilities:
- User bans (
isBanned). - Recipe deletion.
- Report triage and resolution.
- Target-content deletion by report type (user/recipe/comment).
Real-time admin listeners keep dashboard lists current for users, recipes, and reports.
Core fields:
idnameemailprofileImagebioisAdminisBannedxplevelbadges
Supplementary analytics fields in Firestore:
totalRecipesPostedtotalLikesReceivedtotalCommentstotalBookmarks
Core fields:
iduserIdtitleimageUrllegacyImageDataingredientsstepslikescreatedAtcookingTimeMinutesdifficultytags
Comment:
iduserIdusernametextcreatedAtreplies
Reply:
iduserIdusernametextcreatedAtparentCommentId
Fields:
idactorUserIdactorNamerecipientUserIdtype(like,comment,follow,repost)recipeId(optional)text(optional)createdAt
Fields from TheMealDB payload:
idMealstrMealstrMealThumbstrInstructionsstrCategorystrArea
Primary collections used:
-
/users/{uid}- profile fields and gamification counters
/following/{targetUid}/followers/{followerUid}/savedRecipes/{recipeId}/notifications/{notificationId}/gamificationEvents/{eventId}
-
/recipes/{recipeId}- recipe document fields
/likes/{userId}/comments/{commentId}/replies/{replyId}
-
/reposts/{repostId} -
/weeklyStats/{weekId}/users/{uid} -
/reports/{reportId}
- Initializes Firebase app once.
- Exposes shared
AuthandFirestoreinstances.
- Applies XP deltas for user actions.
- Resolves and updates levels.
- Awards badges based on thresholds and weekly performance.
- Writes gamification event history.
- Maintains weekly leaderboard stats.
- Creates activity notifications in recipient user document space.
- Enforces guard rails (no self-notification, invalid payload checks).
- Login, signup, logout.
- Current session/current user loading.
- Ban-state enforcement and auth error handling.
- Upload recipes.
- Real-time feed listeners (global/following).
- Like handling, repost creation, seen-state tracking.
- Firestore-to-model conversion helpers.
- Fetches and decodes TheMealDB search results.
- Exposes loading and error state.
- Real-time saved recipe tracking.
- Add/remove bookmarks.
- Resolve saved IDs into recipe objects.
- Real-time comments/replies observation.
- Create comments/replies.
- Manage submission state and listener lifecycle.
- User profile fetch/update.
- Password change.
- User recipes query.
- Recipe update/delete for owner.
- Follow/unfollow and follow stats.
- Real-time notifications feed listener.
- Maps Firestore docs into activity UI state.
- Real-time users/recipes/reports listeners.
- Ban users, delete recipes, resolve reports.
- Delete report targets by report type.
- Computes dashboard summary counts.
- Loads recipe creator metadata.
- Loads and toggles like state.
- Sends notifications and triggers rewards on interactions.
- Authentication: email/password identity and session.
- Firestore: primary persistence for users, recipes, social graph, notifications, reports, weekly stats.
- Endpoint used:
https://www.themealdb.com/api/json/v1/1/search.php?s={term} - Provides external read-only recipe discovery content shown in Discover and API detail screens.
User-selectable themes are persisted locally and impact app-wide visual styling.
Current themes:
- Warm Classic
- Mint Garden
- Ocean Breeze
- Deployment target is iOS 14.5; avoids iOS 15-only APIs.
- Firebase Storage is not integrated; image handling relies on URL/base64 data strings.
- Legacy user docs may have missing
id; code handles fallback to auth UID. - Legacy image fallback field exists (
legacyImageData) indicating migration-era compatibility. - Feed has a page limit and no explicit infinite pagination implementation.
- Some moderation/report paths rely on specific target ID formatting.
- Badge and level thresholds are currently hardcoded.
- Open the Xcode project workspace and run the iOS target.
- Ensure Firebase configuration is present and valid for your environment.
- New Swift files must be registered in project build phases/references in Xcode project metadata.
If you want, this README can be expanded further with:
- setup-by-step local environment instructions,
- Firestore security rules examples,
- API contract tables for every collection field,
- screenshots and user journeys by role (user/admin).