Portfolio

PAYDAY BANK

Web banking on top of a compiled COBOL program that owns every balance, customer and business rule. Flask only handles presentation: it passes each operation to the core on the command line and reads back a single line, with no database in between. GnuCOBOL with indexed files, Python/Flask and Docker, with a live demo.

In development Solo developer
COBOL Python Flask Jinja HTML CSS JavaScript Docker Gunicorn systemd

Leer en español

PAYDAY BANK

PAYDAY BANK: a COBOL banking core behind a modern web app

A good share of real-world banking still runs on COBOL, and it is rarely rewritten: it gets wrapped. PAYDAY BANK is my small-scale take on that idea. A compiled COBOL program owns every balance, customer and business rule, and a Flask app puts a modern web interface on top of it, with no database in between.

It is a personal, educational project, not a real bank. It is live at payday-bank.astronautmarkus.dev and the code is public on GitHub.

PAYDAY BANK dashboard: total balance, the customer's accounts and the notice carrying the COBOL core's reply after a deposit

Overview
RoleAuthor (personal project)
PeriodAugust 2026
TypeEducational prototype: web banking on top of a COBOL core
StatusLive demo
CodePublic on GitHub

Stack

LayerTechnologies
CoreGnuCOBOL 3, indexed files, packed-decimal arithmetic (COMP-3)
WebPython, Flask 3 (application factory + blueprints), Flask-WTF, Jinja, hand-written CSS and JS with no framework
SecurityPassword hashing with werkzeug (scrypt), CSRF protection on every form, HttpOnly + SameSite cookies
DeploymentGunicorn as a systemd service behind a reverse proxy; multi-stage Docker as an alternative

Architecture

 Browser
     |   POST /deposit  (form with a CSRF token)
     v
 +--------------------------------+
 |  Flask 3 + Gunicorn            |   checks input shape, renders pages
 |  call_cobol()  -> subprocess   |
 +--------------------------------+
     |   argv:    bank_api DEPOSIT 772384 423285 1250
     |   stdout:  OK|6160
     v
 +--------------------------------+
 |  bank_api  (GnuCOBOL)          |   dispatcher + 21 operations
 |  OP-*  ->  *-REPOSITORY        |   business rules and account ownership
 +--------------------------------+
     |
     v
 accounts.dat · customer_profiles.dat · transactions.dat · cards.dat

There is one design rule: Flask makes no banking decisions. It checks that an amount looks like an amount and renders results, but who owns which account, whether the balance covers a withdrawal and whether an account is frozen are always decided by COBOL.

Features

AreaWhat it doesTechnical detail
Sign-upA 4-step wizard (personal, contact, employment, security) that creates the customer and their first checking accountBrowser-side validation mirrors the server's; email and ID document are unique thanks to the indexed file's alternate keys
Sign-inEmail and password in a modalThe hash is computed in Python and stored as an opaque field of the COBOL record
AccountsOpen checking or savings accounts6-digit numbers with a 42 prefix and a Luhn check digit, generated with secrets
Money movementDeposits, withdrawals and transfers between the customer's own accountsThe core checks ownership and status of every account and records each movement in a ledger
DashboardTotal balance, account list and a notice with the outcome of each operationAmounts formatted by a custom Jinja filter
Ready in the core, no screen yetPer-account statements, transfers to other customers, freezing and closing accounts, debit cards with CVV, expiry and a per-purchase limitThe operations already exist in COBOL; the interface is next

PAYDAY BANK public landing page

Deep dive

1. From a click to COBOL

This is how a deposit travels end to end:

Infographic: a deposit goes through the browser, the Flask route, the subprocess call, the COBOL dispatcher, the OP-DEPOSIT operation and the indexed files

The bridge is simple on purpose: Flask runs the binary with the operation and its arguments on the command line, and COBOL answers with a single line on stdout. There is no COBOL server listening on a port and no native library linked into Python. Each call is a short-lived process that opens the files, does its work and exits. State lives only in the .dat files.

def call_cobol(*args: str) -> list[str]:
    result = subprocess.run(
        [str(config["MAINFRAME_BIN"]), *args],
        cwd=config["MAINFRAME_DATA_DIR"],   # COBOL assigns its files by relative name
        capture_output=True, text=True,
        timeout=config["MAINFRAME_TIMEOUT"], check=False,
    )
    return result.stdout.splitlines()

Because the contract is plain text (OK|…, ERR|…, ROW|…, END), the core can be tested from a terminal without starting the web app. This is a real session against the demo data:

$ bank_api BALANCE 423285
OK|Jordan Avery|6160
$ bank_api DEPOSIT 770005 423285 100
ERR|This account does not belong to the customer
$ bank_api WITHDRAW 772384 423285 999999
ERR|Insufficient funds
$ bank_api TRANSFER 772384 423996 423285 500
OK|14000|6660
$ bank_api STATEMENT 772384 423285
ROW|0000000001|OPEN|0|0|000000||20261105143234
…
ROW|0000000009|DEPOSIT|1250|6160|000000||20261105143411
ROW|0000000011|TRANSFER-IN|500|6660|423996||20261105143837
END

Bringing a new COBOL operation to the web always follows the same recipe:

  1. If it needs a new file, its record layout goes in a copybook (src/copybooks/*.cpy) and its repository in src/repository/.
  2. The logic goes in an OP-* subprogram in src/ops/, which prints its result using the OK|/ERR| contract.
  3. A WHEN is added to the dispatcher's EVALUATE (bank_api.cbl).
  4. The Makefile picks up src/ops/*.cbl with a wildcard, so a rebuild is enough.
  5. In Flask, the route calls call_cobol("VERB", ...) and shows the result.

2. Modular COBOL: dispatcher, operations and repositories

bank_api.cbl only opens the files and dispatches. Each operation is its own subprogram, and all of them compile into a single binary: when several sources go into one cobc -x, the first file's PROGRAM-ID becomes the entry point and the rest are linked in as subprograms.

In COBOL, all I/O on a file must happen inside the program that declares it. So each file has a repository (ACCOUNT-REPOSITORY, CUSTOMER-REPOSITORY, and so on) that exposes its operations through a function code (OPEN, READ, WRITE, REWRITE, START, READNEXT), since COBOL has no overloading. Each record layout lives in a copybook that is reused with REPLACING to give it a different prefix in every program that needs it:

COPY "account-record.cpy"
    REPLACING ==ACCOUNT-RECORD==    BY ==WS-FROM-RECORD==
              ==FD-BALANCE==        BY ==WS-FROM-BALANCE==
              ...

3. Money in packed decimal

Balances are stored as PIC 9(12) COMP-3: integers of up to 12 digits in packed decimal, with no floating point and no rounding errors. To keep things simple, the bank works in whole dollars, without cents. Flask's validation is matched to that field, so an amount COBOL could not store never reaches the core:

AMOUNT_RE = re.compile(r"^[1-9]\d{0,11}$")   # positive integer, fits PIC 9(12)

When replying, each operation passes the balance through an edited PIC Z(11)9 field, which drops leading zeros, and Flask only adds the thousands separator.

4. The rules live in the core

  • Account ownership. Every operation that moves money receives the caller's customer-id, and COBOL checks that the account belongs to them. Flask runs the same check first, but the account number comes from the browser and can't be trusted.
  • Transfers never lose money silently. Both accounts are read and verified before anything is written. If crediting the destination fails after the source was debited, a compensating rewrite restores the balance and the operation reports that it was reversed.
  • Transfers to other customers without leaking data. The P2P version only replies with the source account's balance, never the recipient's.
  • A ledger with its own IDs. Every movement appends a row to transactions.dat. IDs come from a persisted counter instead of the clock, because a transfer writes two rows within the same second.
  • Account lifecycle. Each account is ACTIVE, FROZEN or CLOSED, and every money operation respects it.

5. Identity without a database

COBOL has no cryptographic primitives, so the password is hashed in Python (werkzeug, scrypt) and the hash is stored as one more field of the customer's COBOL record, which keeps it without interpreting it. The session cookie holds only the customer ID. On every request, Flask asks the core for the profile with PROFILE, so the web layer stores nothing persistently.

Sign-in modal over the landing page

Customer IDs (77 prefix) and account numbers (42 prefix) are generated with secrets plus a Luhn digit, and checked against the COBOL index before use.

Four-step sign-up wizard

6. Deployment

In production, Gunicorn runs as a systemd service behind a reverse proxy. I also added a multi-stage Dockerfile: the first stage installs gnucobol3 and compiles the core; the final image carries only Python, the binary and libcob4, the GnuCOBOL runtime. The .dat files are not baked into the image but kept on a mounted volume, so updating the core and rebuilding the image doesn't wipe the data.

Transfer between the customer's own accounts

Challenges that taught me something

  • Adding a field is a migration. COBOL records have a fixed width. When I added the account status (ACTIVE/FROZEN/CLOSED), the existing accounts.dat no longer matched the new layout and I had to migrate it after taking a backup. Since then every copybook warns against reordering or resizing fields without a migration plan.
  • Indexed files aren't portable. A .dat created with Homebrew's GnuCOBOL on macOS isn't guaranteed to be readable by Debian's libcob4 inside the container. The fix was to document it and start each new environment with empty data.
  • Design the disk before the code. Without an ORM or automatic migrations, every decision about a field (size, type, whether it's an alternate key) has to be made before writing the first line of logic.

By the numbers

MetricValue
COBOL programs26: dispatcher, 4 repositories and 21 operations
Copybooks5
Lines of COBOL~2,900, copybooks included
Web client~520 lines of Python, ~750 of Jinja templates, ~1,500 of CSS and JS
Indexed files5: accounts, customers, transactions, cards and the ledger counter
Commits26, between August 19 and 22, 2026

Takeaways

PAYDAY BANK made me think the way software used to be built: fixed data layouts, exact decimal arithmetic and a single owner for each file. It also showed me why modernizing legacy systems usually means wrapping rather than rewriting. As long as the contract between layers stays small and explicit, the interface can change as much as it wants without touching the code that moves the money.

Screenshots are from a local instance with a fictitious customer.

Project screenshots

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4 Screenshot 5 Screenshot 6 Screenshot 7 Screenshot 8 Screenshot 9 Screenshot 10 Screenshot 11 Screenshot 12 Screenshot 13
← All projects