Preface
Goal: Starting from Requirement.
Basic class diagram and also ERD, has been asked to ChatGPT as below questions:
For quick and dirty solution, again, one question at a time, please.
Database
+--------+ +-------+ +--------------+
| User | | Role | | Permission |
+--------+ +-------+ +--------------+
| id | | id | | id |
| ... | | name | | name |
+--------+ +-------+ +--------------+
| | |
+----------------+ +----------------+ |
| | |
+---------------------+ +------------------+
| User_Role_Permission | | Role_Permission |
+---------------------+ +------------------+
| user_id | | role_id |
| role_id | | permission_id |
| permission_id | +------------------+
+---------------------+
Conceptual Diagram
Rewrite Diagram from Text to Image
All I can do is guess. And I guess I can interpret the ChatGPT response above to image below:
You can obtain both SVG sources here:
I know, I alter a few things.
- Agregation attribute.
- One-to-many instead of many-to-many.
I might be wrong though.
PlantUML
Again, ask using given textual UML.
@startuml
title User Management System ER Diagram
class User {
+id: int
...
}
class Role {
+id: int
+name: string
}
class Permission {
+id: int
+name: string
}
class User_Role_Permission {
+user_id: int
+role_id: int
+permission_id: int
}
User --> "*" User_Role_Permission
Role --> "*" User_Role_Permission
Permission --> "*" User_Role_Permission
@enduml
The generated diagram from draw.io can be shown as below
You can obtain the schematic source of PlantUML diagram here:
Not bad.
By comparation, my SVG and PlantUML seems similar.
Entity Relationship Diagram
Don not be confused with Engineering Requirement Document (ERD).
+-----------+
| User |
+-----------+
|PK: user_id|
+-----------+
|
|
+---------------------+-------------------+
| |
+-----------+ +-----------+
| Role | | Permission|
+-----------+ +-----------+
|PK: role_id| |PK: perm_id|
+-----------+ +-----------+
| |
| |
+-------------------+---------------------+ +------------+-------------+
| | | |
+------------------+ +----------------+----------------+ +--------------+
|UserRole | | RolePermission | | |RolePermission|
+------------------+ +----------------+ | +--------------+
|PK: user_role_id | |PK: role_perm_id| | |PK: rp_id |
|FK: user_id | |FK: role_id | | |FK: role_id |
|FK: role_id | |FK: perm_id | | |FK: perm_id |
+------------------+ +----------------+ +-----------------+
Conceptual Diagram
ERD is not part of UML standard. Before we go on.. I want to say…
Oh my cat… I don’t get it….
I simply do not understand the relationship between these boxes. I can’t interpret what I do not comprehend.
Allright. I might be wrong on this ERD. But I draw this anyway for practice purpose.
You can obtain both SVG sources here:
Again, I alter a few things.
Again. I might be completely wrong.
PlantUML
As usual, compare!
@startuml
class User {
+id: int
...
}
class Role {
+id: int
name: string
}
class Permission {
+id: int
name: string
}
User "1" --> "N" Role
Role "1" --> "N" Permission
class User_Role_Permission {
+user_id: int
+role_id: int
+permission_id: int
}
User_Role_Permission "N" --> "1" User
User_Role_Permission "N" --> "1" Role
User_Role_Permission "N" --> "1" Permission
class Role_Permission {
+role_id: int
+permission_id: int
}
Role_Permission "N" --> "1" Role
Role_Permission "N" --> "1" Permission
@enduml
The generated diagram from draw.io can be shown as below
You can obtain the schematic source of PlantUML diagram here:
Too bad.
By comparation, I can’t even analyze, whether it is similar or not.
Class Diagram
+----------------------------------------------------+
| User Management System |
+----------------------------------------------------+
| <<class diagram>> |
+----------------------------------------------------+
| User |
+----------------------------------------------------+
| - id: int |
| - username: string |
| - password: string |
| - email: string |
| - created_at: datetime |
| - updated_at: datetime |
+----------------------------------------------------+
| Role |
+----------------------------------------------------+
| - id: int |
| - name: string |
| - description: string |
| - created_at: datetime |
| - updated_at: datetime |
+----------------------------------------------------+
| Permission |
+----------------------------------------------------+
| - id: int |
| - name: string |
| - description: string |
| - created_at: datetime |
| - updated_at: datetime |
+----------------------------------------------------+
| UserRole |
+----------------------------------------------------+
| - user_id: int |
| - role_id: int |
+----------------------------------------------------+
| RolePermission |
+----------------------------------------------------+
| - role_id: int |
| - permission_id: int |
+----------------------------------------------------+
Specification Diagram
Since the diagram above contain the type, I must assume that, this is not a conceptual diagram, but rather a specification diagram.
I still don’t get it….
But I draw my interpretation anyway.
You can obtain the SVG source here:
I must admit. I’m not sure.
I should test the schema in database, so I can be sure, whether it is workable or not.
PlantUML
As usual, compare!
@startuml
title User Management System
skinparam class {
BackgroundColor<<class diagram>> Cornsilk
ArrowColor Black
BorderColor Black
}
class User {
- id: int
- username: string
- password: string
- email: string
- created_at: datetime
- updated_at: datetime
}
class Role {
- id: int
- name: string
- description: string
- created_at: datetime
- updated_at: datetime
}
class Permission {
- id: int
- name: string
- description: string
- created_at: datetime
- updated_at: datetime
}
class UserRole {
- user_id: int
- role_id: int
}
class RolePermission {
- role_id: int
- permission_id: int
}
User -- UserRole
Role -- UserRole
Role -- RolePermission
Permission -- RolePermission
@enduml
The generated diagram from draw.io can be shown as below
You can obtain the schematic source of PlantUML diagram here:
Too good to be true.
By comparation, I think it is very similar with mine. Now I got my confidence back.
What is Next 🤔?
We still have a lot of diagram. From sequence diagram, test diagram, and deployment.
Consider continue reading [ User - Sequence Diagram ].
Thank you for reading.