Project Finia Design Doc 1
By: Kevin Zhijun Wang
Tags: Ui Ux Design, Data Structures, Design Document, Personal Finance Apps, Algorithms

This document aims to explain the design of my side project Finia, a modern personal finance app, with a focus on the data structure and algorithm design. The second part will be dedicated to UX and UI design. If you are interested in the innovation in Finia, check out Innovation in My App Finia.

Some keen readers may notice the iconic logo “F” and “i” in the graphics

Unbalanced Tree Data Structure

In-memory data structures have started to gain popularity these days due to its flexibility. It helps to store data in the form of cache on the frontend. Frontend in-memory data structures can also be dangerous as unrecycled cache can significantly impact the efficiency of the app. Another challenge for in-memory data structures is its mapping from database and data fetching. My design aims to address these issues in this project.

A visual Representation of the unbalanced tree (presented as a list in java)

An Innovative List Representation of the tree structure

Each individual leaf is the fundamental element of the AssetsTypeTree expressed as a list in java. The idea behind a list representation of the tree is to use each leaf node to store the address of the leaf node in the tree by documenting the name of its parent and its parent’s parent.

Advantages of a list representation of the Tree structure:

A list representation of the tree is the best way to store the results from deserialization of database query results

of database query results A list is easier to manipulate in a java setting with the Tree processor objects.

Net Worth Type Tree

A tree structure that stored the item name and address.

The data structure for net worth type defines the structure of hierarchy of data. In other words, they provide information about the location of each node in the structure. The address of each node exhaustively outlines the structure itself.

The tree structure can be obtained through a deserialization of the database entity AssetsType.

A visual representation of Structure

Net Worth Value Tree

A tree structure that is mostly used to store the value of each net worth item. Note that the data structure for net worth values is highly dependent on the data structure for net worth types. Intuitively, each value node is attached to the corresponding type node via the id. These nodes contain the data and its metadata.

The relationship of the Value trees’ nodes are mapped from the Type trees’ nodes as it stored the relationship between nodes.

Each node is an AssetsValue object which contains the id, name, value, time.

A visual representation of Data

Type Tree Processor

A data processor is designed to retrieve data of a particular node or a collection of nodes.

The Type Tree Processor is designed to be read-only as the business logic of Finance defines a fixed number of categories for net worth items.

Usage:

Used by the adapter of the Expandable List to retrieve the sub group of net worth items in order to format the data stored in AssetsTypeTree so that they are compatible with the Expandable List widgets.

so that they are compatible with the Expandable List widgets. Used in the Breadth-First Search algorithm to retrieve the child nodes of a particular node.

Value Tree Processor

The Value Tree Processor is used to manipulate the data stored in the Value tree structure.

This processor contains methods to perform READ, EDIT, GROUP, DELETE on the data structure.

on the data structure. This data source of the processor also stores all the data including the values and the Type tree.

The data stored in the Assets Value Processor is illustrated by the table below:

The following table shows the actions that can be performed on the Value tree structure:

Leaf Node of Type Tree

Each leaf node contains the name of the leaf node, and the address of the node. A simple example below demonstrates the structure of a leaf node.

Node Container

A node container is essentially a data carrier that contains the essential data of a node as well as its level in the tree structure. It enables a more efficient access of the level as well as essential data when constructing the Multi-Expandable list.

The node container is mainly used in the following two ways:

Constructing the Expandable Lists: When the data of a certain level is needed, the Type Tree Processor will prepare the node container by putting each node of the particular level into a node container and recording its level. After the preparation is done, the group of node containers will be injected into the Expandable List Adapter. The mechanism in the adapter will assign the group to the corresponding level and retrieve the data in the node container and deliver them to the right widget on the UI.

When the data of a certain level is needed, the Type Tree Processor will prepare the node container by putting each node of the particular level into a node container and recording its level. After the preparation is done, the group of node containers will be injected into the Expandable List Adapter. The mechanism in the adapter will assign the group to the corresponding level and retrieve the data in the node container and deliver them to the right widget on the UI. Retrieve the data from the input box and inject into the Tree Processor: Each node container will be “paired” with a Input box (EditText), and a TextListener will be added to the Input Box. Once change is detected, the value will be injected into an AssetsValue object and stored in the data source (list of AssetsValue objects) Value Tree Processor. The id from the node container will also be injected and used as an identifier of the node.

The example below shows the structure of a node container and the group under Retirement Accounts that will be used to construct a nested expandable list:

DFS Algorithm

Another highlight in Finia is the algorithm to calculate net worth. A DFS (Depth-First Search) algorithm operates on the unbalanced tree at O(n) running time which gives users a speedy calculation. When the calculation starts, the algorithm will traverse the in-memory unbalanced tree and calculate the sum of leaf nodes and return a value to be assigned to their parent node. A value will be returned when the calculation is complete.

When calculating the net worth as well as the value of a parent node, the processor will call the methods to calculate the value of its child nodes. During this process, the processor actually searches for the group of leaf nodes and returns the sum of them as the value of their parent. Then, the values of the current level will be returned to the previous level.

The advantage DFS algorithm: