Introduction to using Model First Design: Creating an Invoice Microservice

This post is the first in a series on creating an Invoice Microservice using Model First Design. Firstly let us look at the outline the goals for the Microservice. Secondly I will dive into the benefits of using Model First Design. Thirdy I will examine more deeply how to design the Invoice Microservice using Model First Design.

My goal with this series is to teach you new skills to boost your development productivity from 10x to 100x! My current record is 100,000 lines of code after four hours of work. I want to pass these skills on to you.

Goals of the Invoice Microservice:

  • To create a fully functional Invoice Microservice that can be used by other projects
  • To teach you how to use Model First Design to design the Invoice Microservice
  • To teach you how to automate the creation of the code for the Invoice Microservice from the Model.

The features of the Invoice Microservice:

  • It can use a Relational database via EFCore or use Azure Tables/Cosmos
  • Website – Angular/HTML
  • Mobile Apps – iOS and Android
  • CRUD access via REST, Web and Mobile
  • REST API – for more complex operations
  • Documentation Web Site

The Model and Code for the Invoice Microservice are on Github.

The CRUD interface that was generated from the Model is up and running for the REST, Web and Mobile clients. The Model has automated the creation of 12000+ lines of code. The Model only took one hour to create, so productivity wise we are off to a great start.

Impressive Benefits of Model First Design and Code Automation 

So why Model First Design? Simply its all about “Productivity”. By using Model First Design and Automating your code creation, you can reduce your development time from years to weeks. You can create massive amounts of code from your models and slash your development times. Most projects have large amounts of code that can be automatically generated. So when you generate this code automatically, it frees you up to spend time on the code that adds the real business value.

Lets explore some more benefits of using Model First Design. Here is a list of the areas I am going to explore

  1. What is the most productive programming language
  2. Models are clearer and faster understand
  3. Why code automation is better than code generation.
  4. Cross Platform, language independent
  5. Creating 1000’s of lines of code per hour.
  6. Fix once, Fix everywhere else too.

1. What is the most productive programming language

What is the world’s most productive programming language? Is it Machine code, C, Rust or Python? Something else? I believe its Model First Design and I will explain why.

The reason I started using Model First Design is because I saw an opportunity to create the next generation of development tools. Tools that would give the same leap in productively as going from Machine Code to Java.

The Invoicing MicroService Model has around 60 elements. These 60 elements are creating 12,000+ lines of code for a full stack of application code. e.g REST API, Web App and Mobile Apps.

So after an hour of design, Model First Design can create code that would weeks to months to develop!!

Model First Design allows me to create an Invoicing Microservice with the least effort in the fastest time.

2. Models are clearer and faster understand

A picture is worth a thousand words. The same applies to models. For example, here is the model for the Invoice MicroService. 

From looking at this Model you will now have a understanding of what Classes are in the model. What attributes are in each Class and what the relationships are between the Classes. This picture is worth a thousands words.

Now let’s compare this to how it would look in code.

using System;
using System.Collections.Generic;
using System.Linq;

namespace SilverdawnSoftware.Invoice.Database
{
    public class Entity
    {
        public int EntityId { get; set; }
        public string Name { get; set; }
        public string EntityExternalRef { get; set; }
        public int AddressAddressId { get; set; }
        public string LogoURL { get; set; }
        public virtual List<Customer> Customers { get; set; }

    }
}

From looking at this code may have an understanding of the Entity class but not the rest of the application. You would have to work your way, painstakingly through the code to build up your understanding of how it fits together. You may even need to map it on a piece of paper. The process becomes slow and laborious. It’s so much faster and more efficient just viewing the code in the above pictorial Model!  

For more complex designs with 100’s of classes Models give a much quicker understanding of the application and how the information flows within it. It is also a lot easier to make updates to the Models as you can see the big picture on your screen instead of a small portion of code. 

3. Why Code Automation is better than Code Generation.

It’s all about the mindset. When I develop applications, I am always on the lookout for code that can be automated in the form of a Model. My goal is to reduce development time, spending  less time on the ‘easy’ code, freeing up time to spend on the more interesting developmental challenges which I enjoy. As time goes on, the more I have automated the quicker I become at writing applications! 

Although you may have to write a new code generator from time to time,  once the generator is working for one object (e.g Mobile screen) all the rest of your objects can instantly get the same ability. It is the write once- reuse 10’s to 1000’s of times that is extremely beneficial. This is where your productivity gets boosted sky high.

4. Cross Platform, Language Independent

The wonderful thing about Model First Design is that models are independent of any code your generate. You can reuse the same Model to create code for lots of different platforms and computer languages.

Some examples of different platforms and languages you could target from the same model.

  • HTML
  • Java
  • Javascript
  • C#
  • JSON
  • XML
  • Go
  • etc etc

There are no limitations of what you can target the code generation for. If mid project you suddenly had the need to create a mobile app in iOS and Swift, you could use your existing model to generate code for the new platform.

My Invoice Microservice requires lots of different platforms (e.g. Web,iOS,Database etc). Model First Design is the easiest way to create all the code for each platform, and importantly,  keep them all in sync. 

5. Creating 1000’s of lines of code per hour

Once you have your code generators created then you easily create 1000’s of lines of code per hour.

I have a legacy application which wanted to add a modern web application and mobile clients to. I imported the Model into SilverModel , choose the targets(e.g. Database, Mobile, Web) and it created over 100,000 lines of code for me. Not bad for one hours work.

Why spend hours manually developing the Invoice Microservice when I don’t need to. The Model First Design enables me to create the service in record time.

6. Fix once, Fix everywhere else too

One of the major benefits of Model First Design is that it is fast and easy to add new features or fix mistakes throughout your code base quickly.

For example, you have completed your REST API which has 100’s of entry points. Your boss walks in and now wants every api call to be logged to a new internal system. Normally this would take you weeks of effort to update all the code and test it.

With Model First Design you can make the change just once to a code generator and test the change. Then you can use the Model and code generator to update the entire REST API with the new updates. Your work is now completed in a day instead of weeks of effort.

When I need to add a new feature to the Invoice Microservice, I will only need to write it once and then all of my code will be simultaneously updated to use the new feature. Why takes weeks to do something manually that can be done automatically in hours?

Next Steps

Hopefully you can now see some of the incredible benefits of Model First Design and Code Automation. 

If you want to learn more here are some of the posts I will be writing on the design and creation of the invoicing microservice.

  • Designing the Database Model
  • Creating the CRUD access Layer(Web, Mobile)
  • Creating a Rest API e.g. Creating Invoice, Paying invoice etc
  • Creating Mobile and Web forms for access the API
  • Mapping Data between layers e.g. REST API to the database
  • Using Data Mapping and Abstraction

Getting Started

Look at the microservice code on github https://github.com/SilverdawnSoftware/Invoice-MicroService

Download SilverModel to explore the model. https://www.silverdawnsoftware.com/Download-silvermodel/

Any questions about the microservice, the model or code just post a question on GitHub or the support forums and I will get back to you.