Data design

Shows the data this system handles as a logical data model, and which use case reads and writes which entity in the CRUD matrix.

Logical data model

Shows the data this system handles as a logical-level model: an ER diagram, the entity list and the entity definitions.

ER diagram

erDiagram
  "Book" {
    string isbn PK
  }
  "Supplier" {
    string supplier_id PK
  }
  "Delivery" {
    string delivery_id PK
    string supplier_id FK
  }
  "Delivery line" {
    string delivery_id PK, FK
    integer line_no PK
    string isbn FK
  }
  "Sale" {
    string sale_id PK
  }
  "Sale line" {
    string sale_id PK, FK
    integer line_no PK
    string isbn FK
  }
  "Stocktake" {
    string stocktake_id PK
  }
  "Stocktake line" {
    string stocktake_id PK, FK
    string isbn PK, FK
  }
    "Delivery" }o--|| "Supplier" : "supplier_id"
    "Delivery line" }o--|| "Delivery" : "delivery_id"
    "Delivery line" }o--|| "Book" : "isbn"
    "Sale line" }o--|| "Sale" : "sale_id"
    "Sale line" }o--|o "Book" : "isbn"
    "Stocktake line" }o--|| "Stocktake" : "stocktake_id"
    "Stocktake line" }o--|| "Book" : "isbn"

Entities

Entity Kind Term Implements Description
Book Resource book Book ledger, Stock ledger A product the system holds as stock. One record per publication with an ISBN, holding the current stock quantity as an attribute.
Supplier Resource supplier Supplier ledger A wholesaler or publisher that delivers books to the store. Chosen as the source of a delivery.
Delivery Event delivery Delivery records The record of taking in the books delivered by one supplier. Never altered or deleted once confirmed; the books and quantities delivered are held on its lines.
Delivery line Event Delivery records One line of a delivery, a book and its quantity. When the delivery is confirmed, this quantity is added to the stock quantity of the book.
Sale Event sale Sales records The record of one sales notification received from the payment service. The content of the notification is saved first; posting to stock follows.
Sale line Event Sales records One line of a sales notification, a book and its quantity. The notified ISBN is kept as received, and the match to a registered book is held separately.
Stocktake Event stocktake Stocktake records The record of one count of every book that reset stock quantities to the counted figures. From start to confirmation the system is in the stocktake-in-progress state.
Stocktake line Event Stocktake records The record of one book within one stocktake. Keeps the stock quantity at the start as the baseline, and records the difference from the counted quantity at confirmation.

A resource is a thing that persists as a subject of the business; an event is a record of something happening in the business. Resources come first, then events in order of creation. The Implements column names the data stores of the business model in the requirements specification that the entity implements: one ledger may be implemented by a parent and a line entity, and one entity may serve as two ledgers.

The entities without a corresponding term are the line entities (Delivery line, Sale line, Stocktake line), which the language of the business treats as part of their parent.

Sale and Sale line are never registered from a screen, because sales enter as notifications from the payment service. The only screen that refers to the two is the Pending sale review screen, used when a notification includes an unregistered book and becomes pending. The Book history screen, which shows the same two, defines no references for its items because it folds the three kinds of event, deliveries, sales and stocktakes, into one history table.

Entity definitions

For each entity, its attributes and the use cases and screens that use it. There are 8 entities, Book, Supplier, Delivery, Delivery line, Sale, Sale line, Stocktake, Stocktake line, in the same order as the entity list.

CRUD matrix

Shows which use case reads and writes which entity. Rows are the use cases (in the chronology of the business), columns the entities (in the same order as the entity list).

Use case Book Supplier Delivery Delivery line Sale Sale line Stocktake Stocktake line
UC01 Book registration CR
UC02 Supplier registration CR
UC03 Delivery registration RU R C C R
UC04 Sales posting RU C C R
UC07 Pending sale review RU RU RU R
UC05 Stocktake RU CU CU
UC06 Stock inquiry R R R R R R R

Every entity is created by some use case. Never updated after creation: Supplier, Delivery, Delivery line. No entity is deleted.

That the record of a Delivery is neither updated nor deleted after creation follows from design decision D02, which holds it as an append-only event. Two event entities are updated nevertheless: Stocktake by design decision D05, which holds the period from start to confirmation as the status of the stocktake, and Sale and Sale line by design decision D04, which matches pending sales to registered books through a clerk’s review.