Architecture
MVVM
Aidly follows a strict Model-View-ViewModel (MVVM) architecture to clearly separate business logic, data handling, and UI presentation. Dependencies are injected at init‑time.
ViewController (chat example)
ChatViewController
manages user interface interactions and updates, responding directly to changes in the associated ChatModel
. By delegating all business logic to the ViewModel, the controller remains focused solely on UI responsibilities, achieving clarity and simplifying UI maintenance.
The ChatModel
encapsulates all core business logic, conversation state management, and data persistence. By isolating these functions from the UI layer, it ensures testability and keeps the presentation layer (ChatViewController
) free from complex logic, enabling straightforward updates and enhancements.
Dependency Injection & Protocol-Oriented Services
Service Protocols (example)
Protocols define explicit blueprints for services such as speech handling, token management, and membership handling, enabling easy mocking for tests, clear dependency boundaries, and promoting modularity across the app.
Dependency Injection via Shared Services (example)
Implemented shared singleton services like AuthenticationHandler, UserManager, and ConversationHandler, injected through a centralized configuration. This approach ensures consistent access to app-wide dependencies, proper initialization order, and streamlined cross-service communication.
AI Integration & Function-Calling Architecture
Implemented a robust, protocol-oriented AI integration utilizing OpenAI's advanced function-calling capabilities. This architecture allows structured AI-driven interactions, including dynamic itinerary creation, recipe generation, and personalized workout routines, ensuring consistency, extensibility, and optimal user experience.
Highlights
Protocol-Oriented Design
Defined clear interfaces (AIFunction
protocol) and concrete implementations (AIItineraryFunction
, AIRecipeFunction
, AIWorkoutFunction
) for structured AI response handling.
Function Type System
Employed an enum-based function type system (AIFunctionType
) with automatic JSON schema generation to facilitate structured communication with OpenAI’s function-calling API.
UX Design and Theming
Aidly supports 10 different color schemes, each made with distinct color variations and subtle characteristics. This is done by implementing an extensible theming system supporting dynamic persona-based styling, multiple color schemes (e.g., Brand, Warm, Cold, Hacker), and seamless light/dark mode transitions. Centralized definitions ensure consistency, personalization, and instant UI updates, enhancing both accessibility and user experience.
Centralized Color Scheme Management
Defined unified color and gradient palettes in Color.swift
, Gradient.swift
, and Palette.swift
, enabling cohesive UI across the entire app.
Switching color schemes becomes easy with Palette.swift
through the use of ColorScheme
.
Layers
Presentation
Home UI
HomeViewController
Chat UI
ChatViewController
Settings UI
SettingsViewController
Training UI
TrainingViewController
Paywall UI
PaywallViewController
Navigation
NavigationViewController
Business Logic
AI Service
AIService
...
Persona Management
PersonaHandler
...
Membership
MembershipManager
...
Conversation
ConversationHandler
...
Speech
SpeechHandler
...
Training
TrainingHelper
...
Integrations

OpenAI
Implemented via REST API calls to OpenAI's completion endpoint (api.openai.com/v1/chat/completions), secured by Bearer token authentication. Supports structured responses through function calling (e.g., recipes, workouts, itineraries), tracks usage cost per request.

RevenueCat
Integrated RevenueCat during app initialization, managing subscriptions (monthly/annual). Supports automatic entitlement checks, seamless purchase restoration, and real-time updates on membership status through Purchases.shared.purchase()
and associated callbacks.

Flagsmith
Implemented via REST API calls to Flagsmith (api.flagsmith.com/api/v1/flags/
) authenticated by environment keys. Enables feature gating based on user tiers (free vs. premium), caches feature flags locally, and automatically refreshes flags upon app activation.

Yelp
Integrated Yelp Fusion API (v3) via REST calls secured by Bearer token authentication for robust business search. Implemented within BusinessHelper
, providing location-based recommendations (restaurants, venues) with structured JSON parsing and precise URL query parameters for efficient term and location filtering.
All screenshots, assets, and content on this page are property of Fernando Cervantes and are not authorized for any usage or distribution.