Inspiration

In Pakistan most small shops, the kiryana store, the dairy, the pharmacy around the corner, still run on a paper khata. It is a simple notebook where the shopkeeper writes who took what on credit and who paid back. It has worked for generations. But a page gets wet, a number gets smudged, a notebook gets lost, and sooner or later a customer says "I already paid". Shopkeepers do not want an app that makes them type every sale. They want to keep writing the way they always have.

So the question I asked was: what if the dead paper page could come back to life by itself? That is the Resurrection idea behind Revenant Ledger. The old technology is the handwritten ledger, and the new life is a digital ledger that keeps every line tied to the paper it came from.

What it does

The shopkeeper takes one photo of today's page. The ghost_reader reads it with Gemini and every line rises off the paper as an entry: date, customer, item, amount, and whether it is credit given (udhaar) or payment received (jama). It reads Urdu, Roman Urdu and English, including Urdu digits.

The most important rule is that it never invents a number. Anything it is not sure about, a smudged amount, a crossed out line, a name it cannot match, glows like a lantern. The shopkeeper sees the exact crop from the original photo, fixes it in one tap, and only then is the line saved. Nothing goes into the ledger without approval.

After that every customer has a live balance, oldest debt first, and every rupee traces back to a line on paper. Money is stored in whole paisa so there are no rounding mistakes.

Overdue customers appear in Reminders. Revenant Ledger drafts a polite reminder in Urdu or English and attaches the photo of the original line as proof, which ends the "I already paid" argument. The shopkeeper approves every message and shares it on WhatsApp; the app never sends anything on its own.

The shopkeeper can also just ask, in their own language, for example "Hamza ka kitna udhaar hai?", and get the answer with the balance and the oldest unpaid date.

The interface has a haunted theme that helps instead of hiding things: ink lifting off the page while it reads, a lantern glow on unclear values, and full Urdu right to left support.

How I built it

The backend is Python with FastAPI, SQLAlchemy and SQLite. The frontend is Vite, React and TypeScript. The reader is a separate package, ghost_reader, that calls Gemini with a schema for a ledger page and returns rows with a confidence for every field. The same package runs as an MCP server, so it is also a Kiro Power.

Everything was built in Kiro, spec-first. How I used Kiro is explained in detail at the end of this story.

Testing on a real page

I wrote a real khata page by hand with eight lines, including a smudged amount, a crossed out number, an Urdu name and a misspelled name. On that page the reader got 32 of 32 date, customer, item and amount fields right. It left the credit or payment type as unclear on seven lines where the page has no marker, which is exactly what it should do. This is one page and one run, so I treat it as proof that it works on real handwriting, not as an accuracy benchmark. The photo, the raw result and the ground truth are all in the repo under test_data.

Challenges I ran into

Handwriting is messy, and the easy path for an AI model is to guess. Guessing is dangerous in a ledger, because one wrong number becomes a wrong debt. Designing the whole flow around "unclear means ask the shopkeeper" took several rounds of spec changes.

Urdu was the second challenge: right to left text, Urdu digits, Urdu month names, and the same customer written once in Urdu script and once in English. The review step lets the shopkeeper choose or correct the customer for each line, so a name written once in Urdu and once in English ends up on one account.

The third challenge was the Gemini model being busy during testing. I added retries with backoff and a clear message in the app, and the demo mode on the live site uses a recorded real read so judges can always try it.

Accomplishments that I'm proud of

The never invent a value rule holds everywhere: in the reader, in the review screen, in balances and in reminders.

Corrections make the reader stricter over time. Every fix I make becomes a regression test automatically through a Kiro hook.

Over three thousand automated tests run on every push, including property based tests tied to the spec requirements.

What I learned

Writing the requirements first changed how I build. When Kiro had a clear spec, the code it produced matched what I wanted, and when something was wrong I fixed the spec instead of patching code. Steering files were the other big lesson: putting the product rules in one place meant every session respected them without me repeating them.

What's next for Revenant Ledger

Testing with real shopkeepers in my area on many more pages, offline capture on Android with sync later, monthly reports for the shopkeeper, and reading old notebooks in bulk so a shop can bring years of history back to life at once.

How I used Kiro

Kiro IDE was where the whole project was built, from the first spec to the final deploy fixes. The .kiro directory is at the root of the repository with all specs, steering and hooks.

Spec-driven development

I built the project as six specs: ghost-reader (the handwriting reader and MCP server), ledger-core (customers, entries and balances), page-review (the review screen, old register import, audit reports and the corrections log), reminders-and-voice (reminders and questions), haunted-ui (the whole frontend), and demo-fixture-year-fix (a bugfix spec). Each feature spec went from requirements to design to tasks, and Kiro ran the tasks one by one. Every task names the requirement it satisfies and the test that proves it, so I always knew why a piece of code existed.

Compared with vibe coding, the spec approach is slower to start but keeps a large project consistent. With the spec, rules like "a balance is always the sum of its entries" were written down once and turned into tests. I still used direct prompts for small things that did not need a spec, such as the product rename, the logo and icons, and a few deploy fixes. KIRO_PROMPTS.md in the repo records the prompts I used to create the specs.

The bugfix spec was useful in a different way. When the demo data showed the wrong year, Kiro's bugfix flow made me first write tests that showed the bug, then fix it, then rerun the same tests plus preservation tests to prove nothing else changed.

Steering docs

Three steering files shaped every Kiro session. product.md is always included and holds the non negotiable rules: never invent a value, store money as integer paisa, a balance is the sum of its entries, customer data stays private, the UI is in Urdu and English. tech.md is always included and holds the stack and conventions, such as ISO dates and getting today's date in the shop's time zone. urdu-and-numbers.md is included only for the reader, parsing, query and regression files and holds Urdu digits, entry type words in three languages, Urdu month names and correction rules.

The strategy that made the biggest difference was putting the rule "never invent a value, mark it unclear and ask the user" in an always included steering file. Because it is always included, the same rule carries through the reader, the review screen, the question answering and the reminder drafts.

Agent hooks

promote-correction runs when a new reviewer correction is saved in backend/corrections. It copies the crop of the line and writes a regression test that feeds that crop to the reader and expects the corrected value. When the same digit mistake appears three or more times, it also appends a rule to the Urdu steering file. So every correction I make teaches the project something permanent.

ghost-reader-tests runs when a file in the reader package is saved. It runs the reader tests without live Gemini calls and summarises any failures, so I caught breakages immediately instead of at the end.

MCP and Kiro Power

The reader is packaged as a Kiro Power in ghost_reader/POWER, with POWER.md and mcp.json, and registered for the workspace in .kiro/settings/mcp.json with the API key passed from the environment and never stored in the repo. Its tools are read_page, list_schemas and validate_schema. Because it is an MCP server, Kiro's agent can call read_page directly on a real page image and see the actual structured output, which keeps the review screen and the regression tests matched to what the reader really returns. Because it is a Power, the same reader can be reused by anyone who needs to read handwritten registers, not only khata pages.

Property based testing

I enabled property based tests for the rules that must hold for every input, not just a few examples. They use Hypothesis in Python and fast-check in TypeScript, and each property names the spec property it checks. The ghost-reader spec alone has 27 properties. Examples are: money columns reject every float, money text converts to exact integer paisa, unparseable or out of range money is marked unclear and never guessed, the digit normaliser converts Urdu digits one by one and leaves everything else alone, dates round trip whatever digit set they are written in, a page read only ever produces proposed rows, and errors never contain the API key. Property tests generate inputs I would never write by hand, such as mixed Urdu and English digits, Urdu month names and random bounding boxes, so they cover far more cases than my example tests.

Testing and CI

GitHub Actions runs more than three thousand tests on every push: about 1,939 backend tests, 739 frontend tests and 482 ghost_reader tests.

Built With

Share this project:

Updates

Submission history