Building a SaaS Product? Start Early On With Your Database ER Diagram & API Sequence Diagram
I have participated on several software projects where we developed a back end API and database. In retrospect, I wish I would have started designing my first projects with an ER diagram and an API sequence diagram.
During 5 or so years of my web development career I have developed several websites and seen them through to completion. Some of my favorite websites to work on where membership websites where we needed to track user account data and other user input data in a database. As a developer there is a temptation to just start coding however I have gained an appreciated for designing and architecting software first. As you design your software or database with diagrams, you will quickly discover questions you have not asked yet. These questions help you find potential problems with your software and database ahead of time.
The E-R diagram stands for "Entity Relationship Diagram". Lets say you are making a database for a University. The entities you will need to track will likely include professors, students, courses, semester, room numbers, and departments. Each of these entities have some relation to each other. For example, a student can enroll in a course, the course is assigned to a semester, a professor is assigned to a course, a professor is assigned to a department, and a course is assigned a room number. These are relationships. Entities also have attributes. For example, a professor has a name, a degree, faculty id etc.
In general you can then translate this diagram to tables in a database. Entities are often represented as tables, attributes are represented as columns in tables, and the relationships are id keys that tie relationships together. By starting with an E-R diagram you can match your database model with the audience you are designing for whether it is a university, hospital, or online community.
Below is an example of a E-R Diagram of a Hospital Management System. Not to be confused with "Emergency Room". :) Once you understand the entities and relationships you can then turn the diagram into database tables. I have designed diagrams using the website draw.io which offers free templates for building software diagrams.
The other diagram which helps you think about your software development prior to coding is a sequence diagram. A sequence diagram helps you think about the front end code, back end code, and the database. It can reveal potential security issues where you are not tokenizing, potential performance bottlenecks, and can help you write better code. Each of the API calls can be represented in a sequence diagram.
The sequence of each call may also be tied back to a user action such as the "login", "signup", or "edit profile" buttons. Below is a basic example of an API sequence diagram I designed using a free website called draw.io. Professional tools such as Microsoft Visio can also be used, but for learning, and an inexpensive way of producing software diagrams, you can use draw.io.
Most of the APIs I have designed have been developed using NodeJS. You can design each POST and GET request. Each request should also have security in mind as well. For example, you will want to limit the number of login attempts to prevent brute-force and you will want to encrypt your API with HTTPS. Be sure to make sure to use tokens as well and always encrypt passwords in the database with the latest algorithms.
I hope you find these diagrams as useful as I have when building SaaS products. It helps to see a visual of what is going to be developed so you can identify problems ahead of time and have those problem solving questions before developing code.