Review of UML class Diagram of a ASP.NET Core Web API
I've set up a UML class diagram of my ASP.NET Core Web API that uses Entity Framework, with Models and Controllers
I would appreciate any feedback
Things i'm concerned about:
- Multiplicity
- Relations
Here's an example of the Bookmark.cs (model):
public class Bookmark
{
public int Id { get; set; }
public int PostID { get; set; }
public int UserID { get; set; }
public virtual Post Post { get; set; }
public virtual User User { get; set; }
}
And it's controller (BookmarksController.cs):
[Route("api/[controller]")]
[ApiController]
public class BookmarksController : ControllerBase
{
private readonly WebContext _context;
public BookmarksController(WebContext context)
{
_context = context;
}
// GET: api/Bookmarks
[HttpGet]
public async Task<ActionResult<IEnumerable<Bookmark>>> GetBookmarks()
{
return await _context.Bookmarks.ToListAsync();
}
// GET: api/Bookmarks/5
[HttpGet("{id}")]
public async Task<ActionResult<Bookmark>> GetBookmark(int id)
{
var bookmark = await _context.Bookmarks.FindAsync(id);
if (bookmark == null)
{
return NotFound();
}
return bookmark;
}
// POST: api/Bookmarks
[HttpPost]
public async Task<ActionResult<Bookmark>> PostBookmark([FromForm]Bookmark bookmark)
{
_context.Bookmarks.Add(bookmark);
await _context.SaveChangesAsync();
return CreatedAtAction("GetBookmark", new { id = bookmark.Id }, bookmark);
}
// DELETE: api/Bookmarks/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteBookmark(int id)
{
var bookmark = await _context.Bookmarks.FindAsync(id);
if (bookmark == null)
{
return NotFound();
}
_context.Bookmarks.Remove(bookmark);
await _context.SaveChangesAsync();
return NoContent();
}
}
I don't know the domain, so IMO just some feedbacks about UML syntax:
-
Aggregation arrow should have diamond on container (not on contained class).
-
Higher abstractions should be on higher part of the diagram so inheritance arrows should be from bottom to top. It helps to understand the most important part of the diagram.
-
If you can, avoid crossing arrows. You should try to divide your domain not to intertwine.
-
Out of diagram scope classes should be grayed or diagram should indicate that they come from a different package (see
ControllerBase
andDbContext
). It's usefull to understand dependencies. -
Class diagram should state extension points of the architecture. For instance, in the source code of
Bookmark
class, I saw two virtual properties. If your intent is to extend this class, you should indicate it in the diagram. At least with a dummy concrete class example. Usually I use color for it (even if it's out of the standard UML).