CodingNic

Architecture and Data

Understand the Ledger Data Model

Architecture and Data 15 min read

Understand the Ledger Data Model

Open these two files:

text
server/data/db.json
server/src/routes/transactions.js

The JSON file contains the records the server keeps. The transaction route describes the shape the API accepts and returns.

A starter transaction has these fields:

javascript
{
  id: "…",
  date: "2026-09-01",
  description: "Salary",
  category: "Income",
  amount: 3200,
  type: "income"
}

Here is what each property means:

  • id uniquely identifies the record. The server creates it with randomUUID(), so the form does not need to invent an id.
  • date is the calendar day the transaction belongs to, stored as YYYY-MM-DD.
  • description is the text the user enters, such as Salary or Groceries – Mwenge market.
  • category identifies the expense category in the starter data. Income is currently represented by the special text Income; we will improve that model later.
  • amount is the numeric value in the starter project. Later, we will replace this representation with integer cents so money calculations are safer.
  • type is either income or expense. This tells the application how the amount should affect totals.

Now open server/src/routes/categories.js and find the object created when a category is added:

javascript
const category = { name, color };

A category therefore has two values:

  • name is the value stored on an expense transaction.
  • color is the visual color used by the client when it displays that category.

Why there are two collections

transactions are the financial events. categories are the reusable labels that organize expense events.

That separation matters because one category can describe many transactions. For example, the Food category can be used by several grocery transactions without copying the category’s color or other metadata into every transaction.

Test it

Find Salary in server/data/db.json and locate the same record in the running Ledger. Identify its date, description, amount, and type values.

Then find the Housing category and identify the property that controls its visual color.

Checkpoint

You can explain every field in a starter transaction and every field in a starter category, including which value is generated by the server.