Data Models & Serialization
Relevant source files
The following files were used as context for generating this wiki page:
This page documents the architecture and mechanisms used for data modeling, URL-based data parsing, and secure credential handling within the Social-Connect application. The system primarily focuses on processing deep link parameters into actionable service calls and managing the serialization of network requests and authentication headers.
The core of the system relies on structured communication between the DeepLinkHandler for input parsing and the APIClient for remote data persistence. Secure data, such as authentication tokens, are serialized and retrieved via a dedicated KeychainManager.
Network Communication & Request Serialization
The APIClient serves as the primary engine for serializing requests to the backend. It constructs URLRequest objects by appending specific endpoints to a base URL and injecting serialized headers for content negotiation and security.
Request Configuration
When a network request is initiated, the system serializes the following components:
- Content-Type: Standardized to
application/json. - Authorization: Serialized as a Bearer token retrieved from secure storage.
- HTTP Method: Explicitly set to "POST" for state-changing operations.
The diagram shows the serialization flow of a network request within the APIClient.
Sources: APIClient.swift:7-21, APIClient.swift:23-42
Data Extraction & Deep Link Parsing
The application utilizes a DeepLinkHandler to parse incoming URL objects into internal data identifiers, specifically userId strings. This acts as a form of URL-to-Model deserialization.
Deep Link Schema
The system supports specific host-based routing for different data domains:
| Host | Parameter | Action |
|---|---|---|
follow | userId | Triggers userService.followUser |
profile | userId | Triggers navigateToProfile |
post | N/A | Navigation only |
message | N/A | Navigation only |
Sources: DeepLinkHandler.swift:8-30, DeepLinkHandler.swift:32-47
Deep Link Processing Flow
The sequence diagram illustrates how deep link data is parsed and serialized into service method calls.
Sources: AppDelegate.swift:15-18, DeepLinkHandler.swift:32-37
Secure Data Persistence
The KeychainManager handles the retrieval of serialized binary data from the system's secure storage, converting it back into usable String formats for the APIClient.
Keychain Query Structure
To retrieve the authentication token, the system serializes a query dictionary with specific attributes:
| Attribute | Value | Description |
|---|---|---|
kSecClass | kSecClassGenericPassword | Specifies the type of item to find |
kSecAttrAccount | "authToken" | The unique identifier for the token |
kSecReturnData | true | Requests the actual data be returned |
kSecMatchLimit | kSecMatchLimitOne | Limits results to a single item |
Sources: KeychainManager.swift:11-16, KeychainManager.swift:21-26
Notification & State Synchronization
Upon successful completion of data operations (e.g., following or unfollowing a user), the system notifies the rest of the application using serialized notification names.
- Notification Name:
.userFollowStatusChanged - Trigger: Successful API response from
followUserorunfollowUser.
Sources: UserService.swift:11-14, UserService.swift:21-24
Summary
The Data Models & Serialization infrastructure in Social-Connect provides a streamlined approach to converting external inputs (Deep Links) and secure storage (Keychain) into actionable network requests. By centralizing request serialization in the APIClient and URL parsing in the DeepLinkHandler, the project ensures consistent data flow and security across its various modules.