How n26/flowkit-ios works
Main Components and Their Relationships
• Core FlowKit Module (found in the flowkit-ios folder)
– Components: Flow, FlowDefinition, FlowData, FlowKit, FlowKitSwiftUI.
– Role: These handle the definition, creation, and execution of flows. The FlowData (made from JSON or programmatically) is used by FlowKit to initiate flows.
• Step Handling Infrastructure (located in flowkit-ios/Classes/Step, StepHandler, and related)
– Components: Step protocols (StepProtocol.swift), concrete step implementations (AnyStep, NextStep, etc.), StepFactory, and StepHandler.
– Role: They are responsible for generating and managing individual flow steps. The step factory creates step handlers based on step type (the “if stepInfo.type == …” logic in the README).
• Flow Output Typing
– Components: FlowOutput and its associated definitions.
– Role: Provides a typed final output for the entire flow, leveraging Swift’s type safety and autocompletion.
• FlowKitAdditions Module
– Components: Additional classes such as display conditions (BoolDisplayCondition, DateDisplayCondition, etc.), next step conditions, and utility extensions.
• Example Implementations
– Components: Directory under flowkitAdditions/Example which includes projects for both UIKit and SwiftUI integrations.
– Role: Demonstrates how to instantiate FlowKit, inject the step factory, start a flow, and handle flow output. It shows clear separation between the framework’s logic (inside FlowKit) and the UI integration layers (UIKit/AppDelegate, SwiftUI/FlowKitSwiftUIView).
Relationships and Interactions
• The external data source (remote JSON, local files, or programmatic creation) feeds into FlowData – an initiator for flows.
• This FlowData is then used by FlowKit (or FlowKitSwiftUIViewModel for SwiftUI) to start the flow.
• Internally, FlowKit uses the StepFactory to map flow steps (from the JSON or definition) to specific StepHandler implementations.
• Each step handler (created via the sugar syntax provided in the README) encapsulates the logic for presenting a step, handling user interactions, and signaling when it is complete.
• As steps complete, outputs are gathered and merged into a type-safe FlowOutput that ultimately becomes the final result when the flow finishes.
• The FlowKitAdditions module extends this architecture by providing common conditions (display and next step conditions) and utility functionalities that are used within step handlers.
• The Example projects then illustrate how to wire up these components in a real-world iOS application using navigation controllers (UIKit) or SwiftUI views/modals.
Key Architectural Patterns and Design Principles
• Modularity – Separation between the flow definition, step management, output typing, and UI integration.
• Extensibility – The design (e.g., through protocols like FlowDefinition, StepHandlerDefinition, and StepFactory) makes it easy to add custom steps and conditions.
• Loose Coupling – The framework is built around composition and delegation (e.g., step handlers and step factories create and manage steps), minimizing direct dependencies.
• Type Safety – The use of Swift generics and protocols to enforce that the flow output, step outputs, and content definitions are correctly used at compile time.
• Dual UI Support – The architecture supports both UIKit and SwiftUI integrations via separate entry points: FlowKit (for UIKit) and FlowKitSwiftUI.
Final Checklist for the Engineer
• Every major component (Flow Data, Core Engine, Step Handler, Output, Extensions, Example Integration) is represented.