AI Central
18 supporters
ChatGPT The Game Changer in Software Arc ...

ChatGPT The Game Changer in Software Architecture Design

Aug 24, 2023


There has been a lot of interest in ChatGPT from OpenAI in recent weeks, with all sorts of interesting use cases emerging.

In many ways, this is the AI equivalent of the architects whiteboard but has numerous uses than just drawing lines and boxes. With this article, I want to use this innovative technology to demonstrate another use case for starting the software architecture process.

Just like drawing on a whiteboard, the process is a tad chaotic because of the typical interplay that causes constant revision to find the best answers. This article aims to demonstrate some questioning techniques I've used successfully with ChatGPT that have produced results of genuine value.

One caveat with ChatGPT is that it is still learning, so don't expect consistency. Asking the same question on another day may yield a different result.

Setting up a ChatGPT account is simplicity itself, which can be done by following the instructions at this address: https://openai.com/blog/chatgpt/

User Story

So let us start by asking ChatGPT to respond to a user story.

Prompt:

write a user story where a surveyor logins into a system and enters information about the geospatial coordinates, the building, it's type and it's characteristics of just one of the many surveys they will perform in a day


As you can see, this user story is specific to my industry. ChatGPT has a vast knowledge base, so experimentation is required to understand ChatGPT's depth of knowledge — what does it know?

The key here with the initial question is to be very explicit about crucial details to get the best results. This way, ChatGPT can respond with a decent set of results such as this:

If your results are anything like the above, then you know that ChatGPT has picked up the trail and will build on further questions you ask. The key to remember is that all the following results will be based on this initial context, hence why it is worth spending time defining the first interaction well.

So now we can do something rather remarkable. Build a database!

Let's Make a Database

Prompt:

generate the data model in detail, in tabular format in markdown


… and this is how ChatGPT responds:

But let's not stop there. Let's continue…

Prompt:

generate the SQL


ChatGPT answer:

… to which ChatGPT responds with perfectly acceptable SQL, which SQL database will have no problem creating. However, let's not stop there again…

Creating Diagrams

Prompt:

The diagram ChatGPT produces looks like this …

ChatGPT is full of surprises:

Generate a sequence diagram

ChatGPT will not display diagrams but generate the code in Mermaid script, which will create the diagrams. ChatGPT is fully conversant with Mermaid script, so it can produce diagrams that this scripting language will allow.

As we've established, ChatGPT has been taught to code, so you can continue to ask ChatGPT to write JavaScript, CSS, and HTML to put a working prototype together by simply asking for it. ChatGPT has been trained to generate code in many popular programming languages.

Given enough time, this is something a skilled person could do. Granted, but more slowly. But this is something other than production-ready code; much more work is required to get the code to that level of quality and usefulness. But there is no reason why ChatGPT shouldn't sit idly by whilst doing that.

So let us try to improve the quality of the code using ChatGPT:

generate a class design that adhere's to the solid principles in C# with error handling and a database access layer

This is how ChatGPT responded:


Here is the full code:

// Database access class
public class Database
{
    private string connectionString;
    public Database(string connectionString)
    {
        this.connectionString = connectionString;
    }

    public void SaveSurvey(Survey survey)
    {
        // Implement saving logic here
        // Handle database exceptions appropriately
    }
}

// Surveyor class
public class Surveyor
{
    public int UserId { get; private set; }
    public string Username { get; private set; }
    public string FirstName { get; private set; }
    public string LastName { get; private set; }

    public Surveyor(int userId, string username, string firstName, string lastName)
    {
        UserId = userId;
        Username = username;
        FirstName = firstName;
        LastName = lastName;
    }
}

// Building class
public class Building
{
    public int BuildingId { get; private set; }
    public string Name { get; private set; }
    public string Type { get; private set; }
    // Additional properties...

    public Building(int buildingId, string name, string type)
    {
        BuildingId = buildingId;
        Name = name;
        Type = type;
    }
}

// Survey class
public class Survey
{
    public int SurveyId { get; private set; }
    public Surveyor Surveyor { get; private set; }
    public Building Building { get; private set; }
    public DateTime SurveyDate { get; private set; }
    // Additional properties...

    public Survey(int surveyId, Surveyor surveyor, Building building, DateTime surveyDate)
    {
        SurveyId = surveyId;
        Surveyor = surveyor;
        Building = building;
        SurveyDate = surveyDate;
    }
}

// Interface for handling surveys
public interface ISurveyHandler
{
    void SaveSurvey(Survey survey);
}

// Implementation of the survey handler interface
public class SurveyHandler : ISurveyHandler
{
    private Database database;

    public SurveyHandler(Database database)
    {
        this.database = database;
    }

    public void SaveSurvey(Survey survey)
    {
        try
        {
            database.SaveSurvey(survey);
        }
        catch (Exception ex)
        {
            // Handle exception, perhaps log and rethrow or encapsulate into a custom exception
            throw new ApplicationException("There was a problem saving the survey.", ex);
        }
    }
}

… which as a set of classes to get things started is somewhat respectable.

The next task I got ChatGPT to do was to create the Swagger for a REST-based API.
Again ChatGPT returns a respectable effort that is enough to get development started.



The full response:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Surveyor API
paths:
  /users:
    post:
      summary: Create a new user (surveyor)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                password:
                  type: string
                firstName:
                  type: string
                lastName:
                  type: string
      responses:
        '201':
          description: User created
        '400':
          description: Invalid input
          
  /buildings:
    post:
      summary: Create a new building
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                type:
                  type: string
                characteristics:
                  type: object
      responses:
        '201':
          description: Building created
        '400':
          description: Invalid input
          
  /surveys:
    post:
      summary: Create a new survey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                userId:
                  type: integer
                buildingId:
                  type: integer
                surveyDate:
                  type: string
                  format: date
                geoCoordinates:
                  type: string
      responses:
        '201':
          description: Survey created
        '400':
          description: Invalid input


And the result:

Conclusion

ChatGPT can start development as it has the breadth of power but has yet to show the depth. At each turn, I've had to provoke ChatGPT to do the task; there is no initiative there, and I have initiated and driven the next steps.

However, developing a standard set of questions that you know will provoke ChatGPT into delivering a good result could be straightforward. This may be enough in sprint planning to start development in many ways.

This technology is now here, and we may fully embrace it and continue to experiment to understand further what value this advanced automation can provide.

Enjoy this post?

Buy AI Central a coffee

More from AI Central