I wanted a local tool for writing invoices: a client list, line items, tax, a status, and a PDF I could download. It also needed real accounts, because a single shared database of invoices is not something I wanted to leave open on my machine. The result is a FastAPI app with server-rendered pages, SQLite, and email verification through Resend.
What it does
You sign up with an email and a password. The app does not log you in yet. It sends a confirmation link, and login stays blocked until you open it. After that, each account has its own business details, clients, and invoice numbers. INV-0001 for me is not INV-0001 for someone else. Asking for another person's invoice, client, or PDF returns a not-found page, so the response does not reveal that the record exists.
Invoices are created from a normal HTML form. You can add and remove line items in the browser, and the page shows a live subtotal, tax, and total. The server recalculates those numbers on save. The preview is only a preview.
The stack
I kept the stack small on purpose:
- FastAPI and Jinja2 templates, so the browser is just forms and a little JavaScript
- SQLModel on SQLite
-
pwdlibwith argon2 for passwords - A signed session cookie from Starlette
-
fpdf2for PDFs - Resend for verification and password-reset email
I chose fpdf2 because it is pure Python. WeasyPrint needs GTK on Windows, and I did not want the first setup step to be installing a native library.
Accounts, without a token table full of secrets
Passwords are hashed with argon2id. I used the OWASP profile (19 MiB of memory, 2 iterations) instead of the library default, which asks for 64 MiB and makes signup feel stuck on a laptop.
Email links do not store the raw token. The app generates a random value, emails that value once, and saves only its SHA-256 hash. The link works once. Verification links last 24 hours. Reset links last 1 hour. A second email to the same address is skipped for 60 seconds, so a double click does not burn Resend quota, and the page still says the same thing either way.
The forgot-password page always says a link was sent if an account exists. A wrong email and a wrong password on login share one message: "Invalid email or password." An unverified account gets a different message, because that person already typed the right password.
The session cookie holds a user id and a session_version. Resetting the password increments that number, so older cookies stop working. There is no separate CSRF token. The cookie is SameSite=Lax, and every change is a POST.
Money is text, not a float
SQLite will happily store a number as a float. That is a bad place to put a price. Quantity, unit price, and tax rate go through a SQLAlchemy type that writes the decimal as text and reads it back as a Decimal.
Totals are not stored. A line is quantity * unit_price, rounded to cents with half-up rounding. Tax is a percentage: 10 means 10 percent, not "multiply by 10." The tax is rounded, then added to the subtotal. The form, the invoice page, and the PDF all call the same function, so they cannot drift apart.
Testing the email without sending any
send_email is the only function that talks to Resend. Tests replace it with a recorder that keeps the recipient, subject, and HTML. The auth tests pull the token out of the recorded link and follow it with FastAPI's TestClient. That covers signup, an unverified login, an expired link, a reused link, the 60-second cooldown, and a password reset that logs the old session out. The database for those tests is an in-memory SQLite database. No test needs an API key.
What I left out
Email verification and password reset are in. Social login, two-factor authentication, and a full login rate limiter are not. The app also does not email the finished invoice to a client, and it does not do recurring invoices or more than one tax rate. Those are the next pieces, not the first version.
The interesting part was not the invoice table. It was deciding where a number of cents is allowed to be rounded, and making sure a reset link cannot be replayed or used to learn who has an account.
Here is the project repository: https://github.com/Collins331/invoice-gen-engine

