Skip to content

Commit d5f10f9

Browse files
committed
Architecture: Updating Format
1 parent a82a02a commit d5f10f9

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

ARCHITECTURE.md

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,33 @@ Throughout the entire architecture design process, we've priorized several key c
6969
CoreData interactions are contained within the Storage framework. A set of protocols has been defined, which would, in theory, allow us to
7070
replace CoreData with any other database. Key notes:
7171

72-
1. CoreDataManager
72+
73+
1. **CoreDataManager**
74+
7375
In charge of bootstrapping the entire CoreData stack: contains a NSPersistentContainer instance, and
7476
is responsible for loading both, the Data Model and the actual `.sqlite` file.
7577

76-
2. StorageManagerType
78+
2. **StorageManagerType**
79+
7780
Defines the public API that's expected to be conformed by any actual implementation that intends to contain
7881
and grant access to StorageType instances.
7982
8083
**Conformed by CoreDatManager.**
8184

82-
2. StorageType
85+
3. **StorageType**
86+
8387
Defines a set of framework-agnostic API's for CRUD operations over collections of Objects.
8488
Every instance of this type is expected to be associated with a particular GCD Queue (Thread).
8589
8690
**Conformed by NSManagedObjectContext**
8791
88-
3. Object
92+
4. **Object**
93+
8994
Defines required methods / properties, to be implemented by Stored Objects.
9095
9196
**Conformed by NSManagedObject.**
9297

93-
4. StorageType+Extensions
98+
5. **StorageType+Extensions**
9499

95100
The extension `StorageType+Extensions` defines a set of convenience methods, aimed at easing out WC specific
96101
tasks (such as: `loadOrder(orderID:)`).
@@ -134,13 +139,13 @@ Since our Model entities conform to `Decodable`, this results in small-footprint
134139

135140
The networking layer is **entirely decoupled** from third party frameworks. We rely upon component injection to actually perform network requests:
136141

137-
1. NetworkType
142+
1. **NetworkType**
138143
Defines a set of API's, to be implemented by any class that offers actual Network Access.
139144

140-
2. AlamofireNetwork
145+
2. **AlamofireNetwork**
141146
Thin wrapper around the Alamofire library.
142147

143-
3. MockupNetwork
148+
3. **MockupNetwork**
144149
As the name implies, the Mockup Network is extensively used in Unit Tests. Allows us to simulate backend
145150
responses without requiring third party tools. No more NSURLSession swizzling!
146151

@@ -151,15 +156,15 @@ The networking layer is **entirely decoupled** from third party frameworks. We r
151156
Rather than building URL instances in multiple spots, we've opted for implementing three core tools, that, once fully initialized, are capable
152157
of performing this task for us:
153158

154-
1. DotcomRequest
159+
1. **DotcomRequest**
155160
Represents a WordPress.com request. Set the proper API Version, method, path and parameters, and this structure
156161
will generate a URLRequest for you.
157162

158-
2. JetpackRequest
163+
2. **JetpackRequest**
159164
Analog to DotcomRequest, this structure represents a Jetpack Endpoint request. Capable of building a ready-to-use
160165
URLRequest for a "Jetpack Tunneled" endpoint.
161166

162-
3. AuthenticatedRequest
167+
3. **AuthenticatedRequest**
163168
Injects a set of Credentials into anything that conforms to the URLConvertible protocol. Usually wraps up
164169
a DotcomRequest (OR) JetpackRequest.
165170

@@ -188,13 +193,16 @@ Storage layers.
188193
We've borrowed several concepts from the [WordPress's FluxC library](https://github.com/wordpress-mobile/WordPress-FluxC-Android), and tailored them down
189194
for the iOS platform (and our specific requirements):
190195

191-
1. Actions
196+
197+
1. **Actions**
198+
192199
Lightweight entities expected to contain anything required to perform a specific task.
193200
Usually implemented by means of Swift enums, but can be literally any type that conforms to the Action protocol.
194201

195202
*Allowed* to have a Closure Callback to indicate Success / Failure scenarios.
196203
197-
2. Stores
204+
2. **Stores**
205+
198206
Stores offer sets of related API's that allow you to perform related tasks. Typically each Model Entity will have an
199207
associated Store.
200208
@@ -204,20 +212,23 @@ for the iOS platform (and our specific requirements):
204212
Differing from our Android counterpart, Yosemite.Stores are *only expected process Actions*, and do not expose
205213
Public API's to retrieve / observe objects. The name has been kept *for historic reasons*.
206214
207-
3. Dispatcher
215+
3. **Dispatcher**
216+
208217
Binds together Actions and ActionProcessors (Stores), with key differences from FluxC:
209218

210219
- ActionProcessors must register themselves to handle a specific ActionType.
211220
- Each ActionType may only have one ActionProcessor associated.
212221
- Since each ActionType may be only handled by a single ActionProcessor, a Yosemite.Action is *allowed* to have
213222
a Callback Closure.
214223

215-
4. ResultsController
224+
4. **ResultsController**
225+
216226
Associated with a Stored.Entity, allows you to query the Storage layer, but grants you access to the *ReadOnly* version
217227
of the Observed Entities.
218228
Internally, implemented as a thin wrapper around NSFetchedResultsController.
219229
220-
5. EntityListener
230+
5. **EntityListener**
231+
221232
Allows you to observe changes performed over DataModel Entities. Whenever the observed entity is Updated / Deleted,
222233
callbacks will be executed.
223234

@@ -257,19 +268,21 @@ for the iOS platform (and our specific requirements):
257268

258269
It's important to note that in the proposed architecture Model Entities must be defined in two spots:
259270

260-
A. Storage.framework
271+
A. **Storage.framework**
272+
261273
New entities are defined in the CoreData Model, and it's code is generated thru the Model Editor.
262274
263-
B. Networking.framework
275+
B. **Networking.framework**
276+
264277
Entities are typically implemented as `structs` with readonly properties, and Decodable conformance.
265278

266-
In order to avoid code duplication we've taken a shortcut:
279+
In order to avoid code duplication we've taken a few shortcuts:
267280

268-
1. All of the 'Networking Entities' are typealiased as 'Yosemite Entities', and exposed publicly (Model.swift).
281+
* All of the 'Networking Entities' are typealiased as 'Yosemite Entities', and exposed publicly (Model.swift).
269282
This allows us to avoid the need for importing `Networking` in the main app, and also lets us avoid reimplementing, yet again,
270283
the same entities that have been defined twice.
271284

272-
2. Since ResultsController uses internally a FRC, the Storage.Model *TYPE* is required for it's initialization.
285+
* Since ResultsController uses internally a FRC, the Storage.Model *TYPE* is required for it's initialization.
273286
We may revisit and fix this shortcoming in upcoming iterations.
274287

275288
As a workaround to prevent the need for `import Storage` statements, all of the Storage.Entities that are used in
@@ -283,12 +296,14 @@ It's important to note that the Main App is only expected to interact with ReadO
283296
into a ReadOnly instance:
284297

285298

286-
1. ReadOnlyConvertible
299+
* **ReadOnlyConvertible**
300+
287301
Protocol conformed by all of the Storage.Entities, allows us to obtain a ReadOnly Type matching the Receiver's Payload.
288302
Additionally, this protocol define an API to update the receiver's fields, given a ReadOnly instance (potentially a Backend
289303
response we've received from the Networking layer)
290304

291-
2. ReadOnlyType
305+
* **ReadOnlyType**
306+
292307
Protocol conformed by *STRONG* Storage.Entities. Allows us to determine if a ReadOnly type represents a given Mutable instance.
293308
Few notes that led us to this approach:
294309

0 commit comments

Comments
 (0)