How I architected my project with NextSketch 2 (Tutorial)
Tags: beginners, tutorial, productivity, architecture
Published: 2023-01-16 11:54:00

Hello!

In this blog post I'll show you how to architect/explain a project using NextSketch 2, which is an IntelliJ-Platform Plugin. I'm going to be using IntelliJ IDEA and the project I'll be designing is Editor4J, a lightweight code editor I've worked on before.

Let's get started!

After starting IntelliJ IDEA, I'll grab my Editor4J sources from VCS using the link www.github.com/skyloft7/Editor4J-new. 


After it's opened and been indexed, I'll open the Sketch Designer Tool Window. The first time this Tool Window is opened, it will display a "Verifying License..." message. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1o87b6gee9lrifcxncy1.png)
> This shouldn't take longer than 6 or 7 seconds


Once your license is verified, I'll create a new Sketch right inside my working repo called overview by right clicking on the project folder, selecting New > New Sketch. 

Once, that's done, my Sketch Designer should automatically open it up. 

Great, let's take a moment to think about Editor4J. Editor4J has a Main class that is the entry point of the app. It has an Application class that builds the GUI and shows the app on the window.

Let's create a new Node called 'Main Class' in the center of our canvas by pressing 'T' or by dragging a Node from the Multibar. You can inspect the Node by selecting it and pressing 'I'. Change the text to 'Main Class'. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jcpqopfii9i1bd62m1a.png)



Neat. Let's create another Node right next to it called Application. Again, create it with 'T' and then set it's text by inspecting it. 

Now, let's define the relationship between them. Right click the 'Main Class' node and drag out the Link to the 'Application' node and right click to attach it. We know that the Main Class starts the Application so a good name for this Link would be 'Creates and Starts".

Let's set the text by moving our mouse over the Link (until it turns red), then hitting 'I' to inspect it. Also, enable "Arrowed" to give more context about what the Link's text is referring to.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mkw3pzjawafthp668hw.png)



> Tip: The direction the arrow faces is based on which order the Nodes were linked in

Our Main Class also does the work of loading in a settings file (if it currently exists) or just using the default settings. In hindsight, something like this should have probably been in the Application class itself!

Anyway, let's create a Node called "Settings Storage" and connect the 'Main Class' node to it. Set the text of the Link to 'loads settings from" and set it to arrowed.

> Tip: Data Storage Nodes should use the 'Data Store/Server' shape by convention. You can also change this in the Inspector.

Now, once Main is done reading the settings, it passes them onto the Settings Manager so define a Node "SettingsManager" and connect 'Settings Storage' to it with the Link text 'Sets settings in'. You should also make this arrowed for clarity.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvpsouapedy0nit0pijj.png)

Editor4J uses a ComponentRegistry. It let's different parts of the app (for example the CodeEditor) communicate with other Components and makes Editor4J extensible. 

Let's define the ComponentRegistry node and have the Application node connect to it with a Link. The link should probably say something like "Creates a/Lays out" and be arrowed to emphasize that it creates and lays out a ComponentRegistry and all it's registered Components.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1phtm2l1m1gobyllmrdm.png)



Since the only Component Editor4J ever had was the CodeEditorComponent, we'll define a Node for that to and connect the ComponentRegistry to it. 

Finally, we know that the CodeEditorComponent interfaces with FileManager to read the source code of projects off the disk so we can define a FileManager node and connect CodeEditorComponent to that. 

And that's it! Your final diagram should look something like this:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b49nhova4zag51ywf5z6.png)

This diagram can now be used for future reference and to bring other people up to speed on the project. If we were designing Editor4J from scratch again, NextSketch 2 would also be useful in that ideation process.

Thanks for reading! Check out NextSketch 2 at [JetBrains Marketplace](https://plugins.jetbrains.com/plugin/20805-nextsketch2) or visit the [Website](https://www.nextsketch.ca).