- Ruby 81.9%
- HTML 9.6%
- Dart 4.8%
- JavaScript 2.9%
- Rust 0.3%
- Other 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Replaces #4496, closed so the stack can be a native GitHub stack (heads in this repo). Its review history, including jjmata's threads and their answers, stays there. Part of #4449. **Slice 2 (U2)** of the per-lot cost basis series that #4449 proposes. Slice 1 (#4495) is merged. **This is the bottom of a GitHub stack** of the remaining slices: each one targets the branch below it, and the stack map in the merge box shows the order. Merge bottom-up. **In short.** Lots now persist: a `holding_lots` table holds each account's lots per security, written by the materializer from the calculators' lot books, and remap/reset re-key them. **Look first:** `Holding::Materializer`, `HoldingLot.store!`, `Holding::ReverseCalculator#open_lots`. **Check:** `bin/rails test test/models/holding_lot_test.rb test/models/holding/lot_book_test.rb`. **Fork pre-flight:** jaysbeekay/sure#600 (https://github.com/jaysbeekay/sure/pull/600), which holds this slice's CI and review history. Same commits: the pre-flight runs on the fork's copy of this branch. It ports the merged fork PR jaysbeekay/sure#579, whose review history is there too. ## Problem Slice 1 keeps lots in memory during a sync and throws them away. Every later step in #4449 (FIFO disposals, a user's cost on one lot, remap moving lots) needs lots that persist between syncs and follow their trades. ## What this changes A new `holding_lots` table holds each account's lots per security. The holdings materializer writes them from the calculators' lot books on every sync. - **Derived lots.** One per acquiring trade (a buy or a transfer-in), keyed by its source entry. A closed lot stays at qty 0. - **Opening lots.** One per position, for units no imported trade accounts for. On the reverse path this is the baseline the walk already computes: the units held before the first trade, or the whole provider quantity when there are no trades. It is seeded as an unknown-cost lot, so sales relieve it pro rata like any other, and it stays out of the average. - **Clamp.** Where the provider reports fewer units than the trades add up to, the opening lot is stored at qty 0 with `clamped: true`. Nothing else changes. - **Forward keeps opening lots.** Only the reverse walk produces opening lots, so a forward materialization (for example, the first sync after a provider is unlinked) leaves them in place and keeps only derived lots in step. - **Remap and reset.** `remap_security!` and `reset_security_to_provider!` move lots with their trades in the same transaction. An opening lot keeps `origin_security_id`, so a reset returns it. Two book rules land with storage: - **Shortfall.** A sale beyond the open lots becomes a shortfall. The next acquisitions fill it before they open a lot, so open lots equal the position. A split restates the shortfall. - **Rounding.** Pro-rata relief rounds each lot to the stored scale (18), and the residual goes to the last open lot. **Every stored figure is unchanged.** Nothing reads lots yet, and the pool the figure comes from is untouched. Slice 1's characterisation pins and byte-identity dumps pass unedited. No UI, no params, `average` only. ## Blast radius **Who else hits these lines, and what do they pass?** Only `Balance::Materializer` calls `Holding::Materializer#materialize_holdings`, from account sync, remap/reset and trade edits. It passes `account`, `strategy` and an optional `security_ids`. The same account and security scope now also writes `holding_lots`, and lots for out-of-scope securities are left alone. **Siblings:** | Code | Status | |---|---| | Both calculators | Changed: they expose `lots_by_security`; reverse seeds opening lots and records clamps | | `CostBasisTracker < LotBook` | Unchanged interface; its pool and `average_cost` are line-for-line unchanged | | Transfer gates, `Holding#calculate_avg_cost`, `FlowClassifier` | Unchanged: they read trades, not lots | | `Trade#basis_holding` | Unchanged: it reads holdings rows, which do not change | | `Holding#remap_security!`, `#reset_security_to_provider!` | Changed: lots move with the trades | | Snaptrade split repair, Trade Republic rematch, `securities.rake`, `data_migration.rake` | Unchanged. They move trades without lots, and the next materialization's upsert re-keys each derived lot to its trade's security. The `security_id` FK cascades, so destroying a duplicate security is not blocked by its lots | | `import_holding` and the provider processors | Unchanged: they write provider holdings rows, from which the opening lot is derived | ## Migration notes `db/migrate/20261023090000_create_holding_lots.rb`: schema only, reversible (`change`), **no data backfill**. Lots appear at each account's next materialization. - **Columns:** `account_id`, `security_id` (FKs, cascade); `source_entry_id` (FK to `entries`, cascade, so deleting a trade deletes its lot; nil marks the opening lot); `origin_security_id` (FK, nullify); `acquired_on`; `qty` decimal(34,18) as `holdings.qty`; `unit_cost` decimal(25,10), the same 15 integer digits as `holdings.cost_basis`; `currency`; `clamped`; timestamps. - **Indexes and constraints:** unique `(account_id, source_entry_id)`; partial unique `(account_id, security_id) WHERE source_entry_id IS NULL`, one opening lot per position; `source_entry_id`, `security_id`, `origin_security_id`; check `qty >= 0`. - **Verified:** migrate, rollback and migrate again in a throwaway test container. `db/schema.rb` takes only this table's hunks. ## Tests `test/models/holding_lot_test.rb`, 21 tests. - **Book rules, failing before:** the shortfall after a sale with nothing held, then a transfer-in; a split restating the shortfall; the rounding residual on the last open lot. - **Storage:** a buy adds one lot and leaves earlier ones untouched (ids, `created_at`); open lots equal the snapshot quantity on every forward date across a buy, sale, 3:1 split and transfer-in, and equal the provider snapshot on reverse, opening lot included; a provider-only position keeps its provider basis; the opening lot does not move the figure; a clamp is stored and recorded, and flips both ways on re-materialization; an opening lot goes once the trades explain the position; a forward sync after unlinking keeps opening lots. - **Lifecycle:** deleting a trade deletes its lot; a buy edited into a sale loses its lot; a trade moved to another security without its lot takes the lot along; remap and reset move lots, keeping ids; remap onto a position with its own opening lot leaves one there. - **Mutations (22, all caught):** each book rule, each storage rule, the remap and reset moves, the upsert keys, and the forward/reverse opening-lot handling. Two survived the first round, and the tests that catch them were added. ## Validation - **Full suite** at `d9290e2ec`: `13477 runs, 62070 assertions, 0 failures, 0 errors, 36 skips`. - `bin/rubocop`: no offenses. `bin/brakeman`: 0 warnings. No ERB. ## Known limit **Opening-lot collision on remap.** With one opening lot per position, an opening lot cannot move onto a security that already has one. This slice drops the moved opening lot there, and the re-materialization the controller runs straight after a remap restates the target's opening lot over the merged provider quantity. Derived lots always move intact, and opening lots carry nothing user-set yet. Slice 4 (U4) merges them instead. ## AGENTS.md - **Code placement:** model logic, a current-version migration with notes above, and Minitest with no new fixtures. - **Comments:** they describe current behaviour. - **Commits:** subjects are ≤72 characters, with no fork references. - **UI, API, providers:** none. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Holdings now retain acquisition-level lot details, including quantities, costs, and dates, alongside position records. * Opening positions can include provider-reported cost basis, and lot details remain aligned when securities are remapped or reset. * Lot details update alongside calculated holdings and reflect trades, transfers, and security splits. * **Bug Fixes** * Improved lot and position reconciliation for shortfalls, splits, rounding, and provider-reported quantities and costs. Acquisitions cover outstanding shortfalls before contributing to open lots, and positions that close to zero can reopen with known average cost. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jays Beekay <beekay@users.noreply.github.com> |
||
| .cursor/rules | ||
| .devcontainer | ||
| .gemini | ||
| .github | ||
| .junie | ||
| app | ||
| bin | ||
| charts/sure | ||
| config | ||
| db | ||
| design/tokens | ||
| desktop | ||
| docs | ||
| lib | ||
| log | ||
| mobile | ||
| public | ||
| spec | ||
| storage | ||
| test | ||
| tmp | ||
| vendor | ||
| .coderabbit.yaml | ||
| .dockerignore | ||
| .editorconfig | ||
| .env.example | ||
| .env.local.example | ||
| .env.test.example | ||
| .erb_lint.yml | ||
| .gitattributes | ||
| .gitignore | ||
| .rspec | ||
| .rubocop.yml | ||
| .ruby-version | ||
| AGENTS.md | ||
| biome.json | ||
| CLAUDE.md | ||
| compose.example.ai.yml | ||
| compose.example.yml | ||
| config.ru | ||
| CONTRIBUTING.md | ||
| Dockerfile | ||
| Gemfile | ||
| Gemfile.lock | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| perf.rake | ||
| pipelock.example.yaml | ||
| Procfile.dev | ||
| Rakefile | ||
| README.md | ||
| SECURITY.md | ||
Deutsch | Español | Français | 日本語 | 한국어 | Português | Русский | 中文
Sure: The personal finance app for everyone
Get involved: Discord • Website • Issues
Important
This repository is a community fork of the now-abandoned Maybe Finance project.
Learn more in their final release doc.
Backstory
The Maybe Finance (archived/abandoned repo) team spent most of 2021–2022 building a full-featured personal finance and wealth management app. It even included an “Ask an Advisor” feature that connected users with a real CFP/CFA — all included with your subscription.
The business end of things didn't work out, and so they stopped developing the app in mid-2023.
After spending nearly $1 million on development (employees, contractors, data providers, infra, etc.), the team open-sourced the app. Their goal was to let users self-host it for free — and eventually launch a hosted version for a small fee.
They actually did launch that hosted version … briefly.
That also didn’t work out — at least not as a sustainable B2C business — so now here we are: hosting a community-maintained fork to keep the codebase alive and see where this can go next.
Join us!
Hosting Sure
Sure is a fully working personal finance app that can be self hosted with Docker. Sure can be accessed from a browser, the macOS desktop app, the mobile app, API clients, and LLM agents. See Sure Clients for an overview.
Forking and Attribution
This repo is a community fork of the archived Maybe Finance repo. You’re free to fork it under the AGPLv3 license — but we’d love it if you stuck around and contributed here instead.
To stay compliant and avoid trademark issues:
- Be sure to include the original AGPLv3 license and clearly state in your README that your fork is based on Maybe Finance but is not affiliated with or endorsed by Maybe Finance Inc.
- "Maybe" is a trademark of Maybe Finance Inc. and therefore, use of it is NOT allowed in forked repositories (or the logo)
Performance Issues
With data-heavy apps, inevitably, there are performance issues. We've set up a public dashboard showing the problematic requests seen on the demo site, along with the stacktraces to help debug them.
https://www.skylight.io/app/applications/s6PEZSKwcklL/recent/6h/endpoints
Any contributions that help improve performance are very much welcome.
Local Development Setup
If you are trying to self-host the app, read this guide to get started.
The instructions below are for developers to get started with contributing to the app.
Requirements
- See
.ruby-versionfile for required Ruby version - PostgreSQL >9.3 (latest stable version recommended)
- Redis > 5.4 (latest stable version recommended)
Getting Started
cd sure
cp .env.local.example .env.local
bin/setup
bin/dev
# Optionally, load demo data
rake demo_data:default
Visit http://localhost:3000 to view the app.
If you loaded the optional demo data, log in with these credentials:
- Email:
user@example.com - Password:
Password1!
For further instructions, see guides below.
Setup Guides
- Mac dev setup
- Linux dev setup
- Windows dev setup
- Dev containers - visit this guide
One-click Install
Render expects each button target branch to have a render.yaml at the repository root. The branch-ready Blueprint files live in branches/<branch-name>/render.yaml in a separate repo and can be copied to each corresponding branch root.
License and Trademarks
Maybe and Sure are both distributed under an AGPLv3 license.
- "Maybe" is a trademark of Maybe Finance, Inc.
- "Sure" is not, and refers to this community fork.