Tutorial: Hello CodeBot — a simple, secure, rich media, low code application

Matt Stephens and Doug Rosenberg, Parallel Agile, Inc.

What does “Hello World” look like when the code is a UML model?

Everyone’s familiar with introductory “Hello World” programs as a way to help you learn a new programming language. CodeBot generates and deploys web applications from UML models with virtually no programming (literally speaking, the model is the code). So what does “Hello World” look like when the code is a UML model?

Hello CodeBot is simple. There are only 3 webpages and 2 domain classes. But it illustrates many of the things you need to know to get started generating your own web apps.

Hello CodeBot is secure. It uses JSON web tokens (JWT) to provide secure access. Register and Login methods are automatically generated in the API and used by the generated React JS pages.

Hello CodeBot is rich media. It plays videos, uses image components and CSS stylesheets.

Hello Codebot is designed to be a starter model for your own web apps. You can use our pre-built Registration and Login pages, then build out your own web application by replacing our Home page. Figure 1 shows the application’s 3 pages; you can Register, Login and Play Videos (in this case, tutorials from our YouTube Channel).

Figure 1 — Hello CodeBot generates Register, Login and Home pages from wireframes

Hello CodeBot is free to download. Each of these pages was 100% code generated from wireframes within the (free to download) UML model. You read that right, virtually no code was written manually to generate this web application. The single solitary piece of code initializes the video list with data and is embedded within the UML model. You can download the UML model and the MERN Stack web app in a zipfile, including database (Mongo), API (Node), API documentation (Swagger) and React JS pages, from our online process guide at: https://parallelagile.github.io/CodeBot/codegen-process-guide/hello-codebot-project

Project Structure

Figure 2 shows the Enterprise Architect project browser window displaying the high level package structure for the project. There are 3 main packages — one for the Domain Model, one for the Use Cases, and one for the User Experience (UX).

CodeBot generates a database and an API from the Domain Model, and generates the React JS web application from the UX package. More specifically the React pages are generated from wireframes, and the navigation between pages is generated from the State Machine within the Navigation package.

Figure 2 — There are 3 top level packages, with sub-packages in the UX folder

The UX package also contains a nested package called Assets. This package contains image assets as well as Cascading Style Sheets which CodeBot applies to the generated pages to produce nicely styled and formatted web pages.

CodeBot doesn’t directly generate anything from the Use Case package, but it’s a good idea to include them in your model, especially if you plan on generating scenario test scripts later.

Navigation State Machine

CodeBot uses a state machine to determine the sequencing logic for how pages are displayed. Each state on the state machine matches the name of a wireframe. Since Hello CodeBot has three pages, our state machine has three states (see Figure 3).

Figure 3 — It’s easiest if you match your state names and wireframe names

When you start Hello CodeBot it takes you to the Login page. If you’re a new user, click the Register button to go to the Register page. Once you’ve registered successfully you’re automatically directed to Login. Once you’ve logged in, you’re directed to the Home page, where you can play videos.

When you build out your own web applications, you’ll add additional wireframes and additional states and transitions on the state machine to make your application as complex as you like.

Registration

The wireframe for the Registration page is shown in Figure 4. The diagram type is Webpage Wireframe, available from Enterprise Architect’s Wireframing toolbox. There are 4 “client areas” on the diagram — one to contain the entire webpage, with nested client areas for entering username and password, one for the image, and one for navigating to the Login page.

Figure 4 — Register is a “webpage wireframe” with three nested client areas

Each nested client area can be individually styled by setting UML Tagged values on the client area. Figure 5 shows that the blue client area uses the “primary” variant.

Figure 5 — Use tagged values to specify React/Bootstrap styling info

The wireframes can be linked to the domain model by dragging the appropriate domain class onto the wireframe diagram and connecting it to the client area using a UML Dependency arrow. CodeBot matches the text field names on the wireframe with attribute names on the domain class. In the case of text fields, we can use a “placeholder” tag to specify the text that appears on the generated React page (Figure 6).

Figure 6 — CodeBot matches field names to class attributes

Adding the image to the wireframe is accomplished by first importing the image into the EA model via drag-and-drop onto the diagram, moving the imported image into the Assets folder in the EA project browser, and then dragging the image asset onto the client area (see Figure 7). Image assets get exported in the XML file that CodeBot uses for input so the images show up on the generated React pages.

Figure 7 — Just drag the image asset onto the client area

Buttons on wireframes can have Actions assigned to them. Figure 8 shows that we’ve assigned an API call to register (on the User class) by adding a tagged value.

Figure 8 — Buttons can make API calls by using the action tag

JWT Authentication

CodeBot generates secure, server-side login for login and register for the Identity class that’s specified, if JWT Authentication is selected. So the register API endpoint is produced automatically and thus the “action register” tag has something to link to. Auto-generated REST endpoints for register and login are shown in Figure 9.

Figure 9 — CodeBot automatically generates REST endpoints for register and login

The identity class is currently specified in the CodeBot web console’s Project Details window when the Uses JWT Authentication checkbox is selected. CodeBot generates login and register endpoints for the identity class.

Figure 10 — CodeBot simplifies the process of developing with JWT

Automatic Deployment for Rapid Iteration Testing

Once your project setup is complete, export an XMI file from your UML model containing the packages you want to generate, and run CodeBot. You’ll be prompted to download a zipfile containing your web application, and if you’ve checked the Hosted box, CodeBot will automatically build your React JS web app and host it in the cloud, as shown in Figure 11.

Figure 11 — CodeBot does DevOps. Your application is immediately deployed for fast-iteration testing.

When your React build is ready, just click the Visit Website button and your application is live and available for immediate testing. The generated Register page is shown in Figure 12.

Figure 12 — Your fully styled, database-linked React web app is ready.

App in a Zipfile

If you decide to host your application yourself, you’ll use the contents of the downloaded zipfile. Hello CodeBot is a complete MERN stack application that includes Mongo DB, Express JS, React JS and Node.JS, along with Swagger API documentation, and some client-side API interface code (Figure 13).

Figure 13 — Here’s the Hello CodeBot MERN Stack App in a zipfile.

Login

The Login wireframe shown in Figure 14 follows a very similar pattern to the Register wireframe. To recap, it’s a webpage wireframe with 3 nested client areas inside the main client area. The top client area contains the banner image asset, the middle one uses the “primary” variant and displays in blue. This panel links to the User class from the domain model, and matches the names on the text fields to the names of the domain attributes (username and password). The Login button has an action to call the User login API endpoint.

Figure 14 — the Login wireframe is similar to the Register wireframe

CodeBot turns this wireframe into executable React JS in a big hurry. Much faster than anyone could code it by hand — giving a whole new meaning to the term “project velocity”

Figure 15 — CodeBot makes it very fast to develop MERN stack applications

Home Page

Hello CodeBot’s Home page, on the other hand, shows off some considerably more advanced capability. The Home page lets you play tutorial videos from the Parallel Agile YouTube channel and introduces a couple of more React JS components, specifically a media player and a combo box/dropdown list. These components can simply be dragged from EA’s toolbox onto the wireframe, as shown in Figure 16.

Figure 16 — CodeBot’s ability to bind components together and manage UI state yields surprising results

The real magic, though, comes in when you connect the components using Dependency arrows. The combo box is dependent on the Video class and the dependency is called “name”. This causes a query to be run on the Video collection and the names of the videos displayed in the dropdown list. All of that without a line of code. Next, the media player is dependent on the value selected on the dropdown list so the video plays on the generated page. Again, no coding required.

Figure 17 — CodeBot uses Redux state management to produce sophisticated UIs

There’s only one small piece of code required to make Hello CodeBot work, and that’s to initialize the Video collection with the names and URLs of a couple of videos. As shown in Figure 18, the code (for the moment at least) has been attached to the on register method on the User class, so the database will get initialized when a new user registers.

Figure 18 — We need a small snip of code to pre-load the database with videos

Fortunately, EA has a built-in code editor that makes it easy to attach code snippets to the UML model. CodeBot merges these snippets in with the auto-generated code so that it is invoked at the proper time. This code snip creates a JSON structure called data which holds a couple of name/URL pairs, and then calls the create method on the VideoDao class, which has been generated by CodeBot.

Learn More

You can get more detail on the parallelagile.com website, and we’ve added a section on Hello CodeBot to our online process guide at

https://parallelagile.github.io/CodeBot/codegen-process-guide/hello-codebot-project

To sum up, Hello CodeBot is a simple, secure, rich media MERN stack application that’s designed to help you get started doing development with CodeBot. We think you’ll find developing with CodeBot to be an order of magnitude faster than writing code by hand.

Please contact us at training@parallelagile.com if we can answer any questions for you.

--

--

--

We offer training, consultancy, and support for large-scale projects. If this sounds like just what your organization needs, give us a shout at training@parallelagile.com.

Recommended from Medium

Vetur Support for Onsen UI & Element UI

How To Make a Custom Responsivity Hook in React?

Zen of Functional Programming

Clickable Card Using React Hooks

JavaScript Concepts: Scope

Unsend Recall for Messenger — Recalling removed messages in Facebook Messenger

Sorting Algorithms

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Doug Rosenberg

Doug Rosenberg

More from Medium

Production deployment workflow for web client app

Analytics API are now in public beta!

Easy way to add animated github repository metrics into your website

Web spreadsheet, a use case in EMS