Last updated: over 1 year ago
iOS apps are no longer as small as they were a few years ago. They are increasingly large projects with growing complexity and architecture. Yet there are no tools available to analyze and visualize the architecture and dependencies of a Swift project like there are for other languages. In this talk I will give a short overview of my master thesis in which I created such a tool.
The first step is to analyze the source code and extract connections and dependencies between code entities. To do this, we will explore SwiftSyntax, Apples framework for parsing Swift code. It provides an abstract syntax tree which we can traverse over to handle various components of the Swift language such as ClassDeclSyntax, FunctionDeclSyntax and AsExprSyntax.
Building on the previous analysis we can start to visualize the code entities and their dependencies as a node-link diagram. To provide a clear and understandable picture, these nodes will be arranged in levels that follow the direction of their dependencies. Additionally, nodes representing modules or groups can be expanded and collapsed to show or hide their inner nodes, e.g. subgroups and classes. This allows a user to easily drill down into one specific part of an app and to inspect only relevant dependencies between code entities.
The developed tool can help developers and software architects to understand and improve their apps in various new ways. By inspecting the visualization, it is possible to compare the actual structure of an app with a previously planned architecture and thus find and remove unintended connections between different parts of an app. When changes need to be made, the impact of refactoring one part of the app on the rest of the project is visible, allowing a better estimation of consequences.
Thank you for your proposal!
Could you expend a little bit on that last part? What specifically can developers and architects take away from a visualisation of code dependency?
Is there graph theory involved?
Hey, thanks for your feedback! I added a little bit more information about the benefits of visualizing dependencies between code entities. Yes, graph theory plays an important role, e.g. when arranging the nodes in groups and levels.
Hi there, very interesting topic. With a friend, we also built a tool like this in 2018: https://bismuthlabs.io/ I'm not in the project anymore but do not hesitate if you want feedback (I did tons of pres about why visualization is important) or contact. Few questions: Did you look at DSM visualisation ? Do you know other tools that are proposing that ? What are the features available in your visualisation ?
Cool, thanks for the tip, I didn't know your project yet. I like your approach of a dependency graph, which looks a little bit like a mindmap. My visualization is more related to structure101 studio (https://structure101.com) where you have nested nodes representing the groups and source files that can be expanded to show their inner nodes (e.g. other groups and source files or code entities) or collapsed. Yes, I thought about adding a Dependency Structure Matrix, but currently I am working on the dependency graph. That is because I think a DSM can give you a good high level overview of the health of you project, but with a dependency graph it is easier to understand and follow the relations between elements. In my research I didn’t find any other tools to visualize the architecture of a swift project, which are currently available.
Wo this topic is really nice. I myself studies visualization and thus find your topic really interesting. Would vote for it 👍
Considering other products, Lattix can analyze clang and swiftc AST and enable visualisation and analysis of the structure of your code (at least I think it can). Just in case :-) (they have good use cases and are applying their tools in big projects configurations) I think they also have some tools for CI integration (and breach detection).
Hey, thanks for the tip! But I don't know whether Lattix can analyze Swift code, they explicitly list C/C++/Objective-C as their supported technologies but not Swift. Also it looks like they create a Dependency Structure Matrix and not a hierarchical Dependency Graph, which is the type of visualization I use.Log in to comment