Mastering Use Case Modeling: Library Architecture with UML and AI

Use Case Diagrams are the bridge between abstract business requirements and concrete system design. They provide a visual representation of how different users (actors) interact with a system to achieve specific goals. In this tutorial, we will deconstruct the architecture of a Library Management System, exploring the roles, behaviors, and the critical logic behind modeling relationships using PlantUML and UML standards.
1. Identifying the Actors
The foundation of any use case model is the actor. An actor represents a role that interacts with the system, not necessarily a specific person. In our Library Management System, we have identified four distinct actors:
- Member: The primary user who interacts with the library to borrow, reserve, and manage books.
- Librarian: An internal user responsible for managing the catalog and processing transactions.
- System Administrator: The technical role responsible for the health and configuration of the system itself.
- Email Service: An external system actor. This is crucial to remember: actors are not just humans. They can be other software systems, hardware devices, or legacy databases.
2. Defining Use Cases and Behaviors
Use cases are the specific goals an actor wants to achieve. We categorize them based on the actor’s perspective:
Member Use Cases
These represent the core value proposition for the library’s patrons. They include high-level actions like Search Catalog, Borrow Book, Return Book, Reserve Book, and Pay Fine.
Librarian Use Cases
These focus on operational efficiency. The librarian performs Add New Book, Process Loan, Process Return, and Manage Reservations.
System Administration
The System Administrator primarily interacts with the back-end infrastructure, represented here by Add New Book (catalog maintenance) and configuration tasks.
3. Modeling Relationships: The Core Logic
The power of a use case diagram lies in how these use cases interact. We utilize two primary relationship types: Include and Extend.
The «Include» Relationship (Mandatory)
An include relationship means that one use case must happen as part of another. It is a dependency.
- Authentication: Almost every action in the library system (Borrowing, Returning, Reserving) requires the user to be logged in. Therefore, we model Authenticate User as an included use case. The diagram shows that Borrow Book includes Authenticate User.
- Notifications: When a book is borrowed, returned, or reserved, the system must send a notification (or log the action). Thus, Send Notification is included in these flows.
The «Extend» Relationship (Optional)
An extend relationship represents optional behavior that occurs only under specific conditions. It adds functionality to a base use case.
- Renew Book: This is not a standard part of borrowing. It happens only if a member wants to extend the loan period. We model this as Renew Book extending Borrow Book.
- Report Lost Book: This is a special case of a return that occurs only when a book cannot be located. It is an extension of the standard Return Book process.
4. Implementation: The PlantUML Code
Below is the exact PlantUML code used to generate the architecture diagram shown above. This code demonstrates how to structure the system, define actors, and map the logical relationships using specific syntax.
@startuml
left to right direction
actor Member
actor Librarian
actor "System Administrator" as Admin
actor "Email Service" as Email
rectangle "Library Management System" {
usecase "Search Catalog" as UC1
usecase "Borrow Book" as UC2
usecase "Return Book" as UC3
usecase "Reserve Book" as UC4
usecase "Pay Fine" as UC5
usecase "Add New Book" as UC6
usecase "Process Loan" as UC7
usecase "Process Return" as UC8
usecase "Manage Reservations" as UC9
usecase "Authenticate User" as UC10
usecase "Send Notification" as UC11
usecase "Renew Book" as UC12
usecase "Report Lost Book" as UC13
}
Member --> UC1
Member --> UC2
Member --> UC3
Member --> UC4
Member --> UC5
Librarian --> UC6
Librarian --> UC7
Librarian --> UC8
Librarian --> UC9
Admin --> UC6
UC2 ..> UC10 : <>
UC3 ..> UC10 : <>
UC4 ..> UC10 : <>
UC7 ..> UC10 : <>
UC8 ..> UC10 : <>
UC2 ..> UC11 : <>
UC3 ..> UC11 : <>
UC4 ..> UC11 : <>
UC12 .> UC2 : <>
UC13 .> UC3 : <>
UC11 --> Email
@enduml
5. Best Practices for Effective Modeling
Creating a diagram is easy; creating a good diagram requires discipline. Here are the best practices to ensure your models remain valuable assets throughout the project lifecycle:
- Keep It Simple: Avoid “use case explosion.” Do not model every single button click or validation check. Focus on high-level goals. If a diagram becomes too crowded, consider splitting it into multiple diagrams (e.g., “Member Operations” vs. “Admin Operations”).
- Focus on Value: Every use case must deliver observable value to an actor. If a use case exists purely for internal data processing (like “Calculate Interest Rate”), it is likely a sub-process, not a top-level use case.
- Use Meaningful Names: Use the “Verb-Noun” format (e.g., “Process Loan” instead of “Loan”). This keeps the focus on the action and the object, making the diagram readable for stakeholders.
- Validate with Stakeholders: A diagram is a communication tool. Review it with the actual librarians and members to ensure it matches their mental model of the system.
6. Common Pitfalls to Avoid
Even experienced modelers make mistakes. Here are three common pitfalls in use case modeling:
- Confusing Include and Extend: Remember the “Always vs. Sometimes” rule. If it happens always, use Include. If it happens sometimes, use Extend.
- Over-Granular Use Cases: Don’t break down use cases too finely (e.g., “Click Login Button”). This creates maintenance overhead and confuses the high-level architecture.
- Ignoring External Systems: Don’t forget to model interactions with external APIs, services, or legacy systems. In our library example, the “Email Service” is a vital actor that drives the notification workflow.
By following these guidelines and understanding the logical structure of actors and relationships, you can create use case diagrams that serve as a robust blueprint for system development.