CodingNic

API, Persistence, and Hardening

Make the Data Dependable

API, Persistence, and Hardening 6 min read

Make the Data Dependable

The previous modules made the Ledger useful. This module makes the data underneath those features dependable.

We will work from the inside out. First we will decide exactly how money and dates are represented. Then we will move the important validation rules to the server, where they cannot be bypassed by a different client. After that we will put financial calculations in one place, strengthen the JSON persistence layer, and make API failures predictable for the browser.

You will work mainly in these areas:

text
client/src/lib/finance.js
server/src/domain/transactions.js
server/src/db.js
server/src/asyncHandler.js
server/src/app.js
client/src/lib/api.js

What you should be able to explain at the end

You should be able to answer four questions without guessing:

  1. Why does the app store 8450 instead of 84.50?
  2. Where does the app decide whether a transaction is valid?
  3. What happens if two writes reach the JSON database close together?
  4. How does a server error become a readable message in the UI?

Checkpoint

Before moving on, open the files listed above and note which layer each one belongs to: browser utility, server validation, persistence, or error handling. You do not need to change anything yet.