openapi: 3.1.0 info: title: Api version: 0.1.0 description: Receipt-to-Wallet API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: accounts description: Bank account management - name: transactions description: Bank transaction operations - name: receipts description: Scanned receipt operations - name: matches description: Receipt-transaction reconciliation - name: categories description: User-created categories and per-category color overrides - name: dashboard description: Summary and analytics - name: events description: >- TrackStack Universal Event Contract adapter (see workspace-notes/EVENT_CONTRACT_SPEC.md and EVENT_CONTRACT_OPENAPI.yaml) -- an additional, uniform layer alongside the transaction-specific routes above, not a replacement for them. paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" # ── ACCOUNTS ──────────────────────────────────────────────────────────────── /accounts: get: operationId: listAccounts tags: [accounts] summary: List all linked bank accounts responses: "200": description: List of accounts content: application/json: schema: type: array items: $ref: "#/components/schemas/Account" post: operationId: createAccount tags: [accounts] summary: Link a new bank account (via Plaid token exchange) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AccountInput" responses: "201": description: Account linked content: application/json: schema: $ref: "#/components/schemas/Account" /accounts/{accountId}: get: operationId: getAccount tags: [accounts] summary: Get a single account parameters: - name: accountId in: path required: true schema: type: string responses: "200": description: Account content: application/json: schema: $ref: "#/components/schemas/Account" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" delete: operationId: deleteAccount tags: [accounts] summary: Unlink a bank account parameters: - name: accountId in: path required: true schema: type: string responses: "204": description: Account unlinked # ── TRANSACTIONS ───────────────────────────────────────────────────────────── /transactions: get: operationId: listTransactions tags: [transactions] summary: List bank transactions parameters: - name: accountId in: query schema: type: ["string", "null"] - name: pending in: query schema: type: ["boolean", "null"] - name: from in: query schema: type: ["string", "null"] description: ISO date (YYYY-MM-DD) - name: to in: query schema: type: ["string", "null"] description: ISO date (YYYY-MM-DD) - name: search in: query schema: type: ["string", "null"] responses: "200": description: List of transactions content: application/json: schema: type: array items: $ref: "#/components/schemas/Transaction" /transactions/sync: post: operationId: syncTransactions tags: [transactions] summary: Pull latest transactions from Plaid for all linked accounts responses: "200": description: Sync result content: application/json: schema: $ref: "#/components/schemas/SyncResult" /transactions/unmatched: get: operationId: listUnmatchedTransactions tags: [transactions] summary: Transactions that have no linked receipt responses: "200": description: Unmatched transactions content: application/json: schema: type: array items: $ref: "#/components/schemas/Transaction" /transactions/{transactionId}: get: operationId: getTransaction tags: [transactions] summary: Get a single bank transaction parameters: - name: transactionId in: path required: true schema: type: string responses: "200": description: Transaction content: application/json: schema: $ref: "#/components/schemas/Transaction" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" # ── RECEIPTS ──────────────────────────────────────────────────────────────── /receipts/categories: get: operationId: listReceiptCategories tags: [receipts] summary: List valid categories for receipt items (same list transactions use — defaults + user-created) responses: "200": description: Category names content: application/json: schema: type: array items: type: string /categories: get: operationId: listUserCategories tags: [categories] summary: List the current user's category rows -- user-created categories, and any color/icon override set on a default category's name responses: "200": description: The user's category rows content: application/json: schema: type: array items: $ref: "#/components/schemas/UserCategory" post: operationId: createUserCategory tags: [categories] summary: Create a new custom category requestBody: required: true content: application/json: schema: type: object required: [name] properties: name: type: string color: type: ["string", "null"] icon: type: ["string", "null"] responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/UserCategory" "400": description: Missing/invalid name content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" "409": description: A category with this name already exists for this user content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /categories/color: put: operationId: setCategoryColor tags: [categories] summary: Set (or clear) the display color for a category name, default or user-created alike requestBody: required: true content: application/json: schema: type: object required: [name, color] properties: name: type: string color: type: ["string", "null"] description: "#rrggbb hex string, or null to clear the override and fall back to the app's built-in default color" responses: "200": description: The upserted category row content: application/json: schema: $ref: "#/components/schemas/UserCategory" "400": description: Missing name, invalid color, or unknown category name content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /categories/{id}: delete: operationId: deleteUserCategory tags: [categories] summary: Delete a user-created category parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted /receipts: get: operationId: listReceipts tags: [receipts] summary: List all scanned receipts parameters: - name: status in: query schema: type: ["string", "null"] description: "Filter by processing_status: pending | ocr_complete | matched | unmatched | error" - name: search in: query schema: type: ["string", "null"] - name: from in: query schema: type: ["string", "null"] - name: to in: query schema: type: ["string", "null"] responses: "200": description: List of receipts content: application/json: schema: type: array items: $ref: "#/components/schemas/Receipt" post: operationId: createReceipt tags: [receipts] summary: Submit a new receipt for OCR processing requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ReceiptInput" responses: "201": description: Receipt created and queued for OCR content: application/json: schema: $ref: "#/components/schemas/Receipt" /receipts/expiring: get: operationId: listExpiringReceipts tags: [receipts] summary: Receipts whose return window expires within the next N days parameters: - name: days in: query schema: type: ["integer", "null"] description: Look-ahead window in days (default 14) responses: "200": description: Expiring receipts content: application/json: schema: type: array items: $ref: "#/components/schemas/Receipt" /receipts/unmatched: get: operationId: listUnmatchedReceipts tags: [receipts] summary: Receipts that have no linked bank transaction responses: "200": description: Unmatched receipts content: application/json: schema: type: array items: $ref: "#/components/schemas/Receipt" /receipts/{receiptId}: get: operationId: getReceipt tags: [receipts] summary: Get a single receipt with its items parameters: - name: receiptId in: path required: true schema: type: integer responses: "200": description: Receipt content: application/json: schema: $ref: "#/components/schemas/ReceiptDetail" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" patch: operationId: updateReceipt tags: [receipts] summary: Update receipt metadata parameters: - name: receiptId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ReceiptUpdate" responses: "200": description: Updated receipt content: application/json: schema: $ref: "#/components/schemas/Receipt" delete: operationId: deleteReceipt tags: [receipts] summary: Delete a receipt and its items parameters: - name: receiptId in: path required: true schema: type: integer responses: "204": description: Deleted /receipts/{receiptId}/suggestions: get: operationId: getReceiptSuggestions tags: [receipts] summary: Re-run the matcher for an already-saved, unmatched receipt (read-only) parameters: - name: receiptId in: path required: true schema: type: integer responses: "200": description: Match suggestions content: application/json: schema: $ref: "#/components/schemas/ReceiptSuggestions" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /receipts/{receiptId}/items: get: operationId: listReceiptItems tags: [receipts] summary: List line items for a receipt parameters: - name: receiptId in: path required: true schema: type: integer responses: "200": description: Receipt items content: application/json: schema: type: array items: $ref: "#/components/schemas/ReceiptItem" post: operationId: createReceiptItem tags: [receipts] summary: Add a line item to a receipt parameters: - name: receiptId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ReceiptItemInput" responses: "201": description: Item added content: application/json: schema: $ref: "#/components/schemas/ReceiptItem" /receipts/{receiptId}/items/{itemId}: patch: operationId: updateReceiptItem tags: [receipts] summary: Update a line item (e.g. re-assign its category) after the receipt has been saved parameters: - name: receiptId in: path required: true schema: type: integer - name: itemId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ReceiptItemUpdate" responses: "200": description: Updated item content: application/json: schema: $ref: "#/components/schemas/ReceiptItem" "404": description: Item not found # ── RECONCILIATION / MATCHES ───────────────────────────────────────────────── /reconcile: post: operationId: runReconciliation tags: [matches] summary: Auto-match unmatched receipts against unmatched transactions responses: "200": description: Reconciliation results content: application/json: schema: $ref: "#/components/schemas/ReconcileResult" /matches: get: operationId: listMatches tags: [matches] summary: List all receipt-transaction matches parameters: - name: confirmed in: query schema: type: ["boolean", "null"] - name: method in: query schema: type: ["string", "null"] description: "auto | manual" responses: "200": description: List of matches content: application/json: schema: type: array items: $ref: "#/components/schemas/Match" post: operationId: createMatch tags: [matches] summary: Manually link a receipt to a transaction requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MatchInput" responses: "201": description: Match created content: application/json: schema: $ref: "#/components/schemas/Match" /matches/{matchId}: patch: operationId: updateMatch tags: [matches] summary: Confirm or update a match parameters: - name: matchId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MatchUpdate" responses: "200": description: Updated match content: application/json: schema: $ref: "#/components/schemas/Match" delete: operationId: deleteMatch tags: [matches] summary: Remove a match link parameters: - name: matchId in: path required: true schema: type: integer responses: "204": description: Deleted # ── DASHBOARD ──────────────────────────────────────────────────────────────── /dashboard/summary: get: operationId: getDashboardSummary tags: [dashboard] summary: Aggregated stats for the home dashboard responses: "200": description: Dashboard summary content: application/json: schema: $ref: "#/components/schemas/DashboardSummary" /dashboard/spending-by-category: get: operationId: getSpendingByCategory tags: [dashboard] summary: Spending totals grouped by merchant category parameters: - name: from in: query schema: type: ["string", "null"] - name: to in: query schema: type: ["string", "null"] responses: "200": description: Category spending content: application/json: schema: type: array items: $ref: "#/components/schemas/CategorySpend" /events/log: post: operationId: logEvent tags: [events] summary: Log one event (Universal Event Contract) description: >- Only event_type "transaction" is supported. Writes a normal bank_transactions row against a lazily-created synthetic "Manual Entries" account, so a manually-logged event shows up in the regular transaction list/aggregations like any other transaction. requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/EventLogRequest" responses: "200": description: Logged content: application/json: schema: $ref: "#/components/schemas/LogEventResult" "400": description: Unknown event_type content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /events: get: operationId: getEvents tags: [events] summary: Query events (Universal Event Contract) parameters: - name: start in: query required: true description: Inclusive start date, YYYY-MM-DD schema: type: string - name: end in: query required: true description: Inclusive end date, YYYY-MM-DD schema: type: string - name: event_type in: query required: false description: 'Only "transaction" is valid for this tracker; omit for all (same result).' schema: type: ["string", "null"] - name: source in: query required: false description: Filter to one source (e.g. "plaid" or "manual"); omit for all. schema: type: ["string", "null"] responses: "200": description: Matching events content: application/json: schema: $ref: "#/components/schemas/EventsQueryResult" /aggregations/{aggType}: get: operationId: getEventAggregations tags: [events] summary: Sum event amounts grouped by one dimension (Universal Event Contract) description: >- Deliberately simple, uniform semantics matching every other tracker's adapter -- a flat sum of `amount` per group, not finance's richer per-receipt-item category-splitting (see GET /dashboard/spending-by-category for that). `unit` is always "usd": every bank_transactions row already defaults to USD, and true multi-currency aggregation is a real gap this endpoint doesn't attempt to solve. parameters: - name: aggType in: path required: true schema: type: string enum: [by_category, by_source, by_event_type] - name: start in: query required: true description: Inclusive start date, YYYY-MM-DD schema: type: string - name: end in: query required: true description: Inclusive end date, YYYY-MM-DD schema: type: string responses: "200": description: Aggregated totals content: application/json: schema: $ref: "#/components/schemas/AggregationsResponse" components: schemas: HealthStatus: type: object required: [status] properties: status: type: string ErrorResponse: type: object required: [error] properties: error: type: string # ── CATEGORY ───────────────────────────────────────────────────────────── UserCategory: type: object required: [id, name, color, icon, createdAt] properties: id: type: integer name: type: string color: type: ["string", "null"] icon: type: ["string", "null"] createdAt: type: string # ── ACCOUNT ────────────────────────────────────────────────────────────── Account: type: object required: [id, institutionId, institutionName, name, type, mask, currency, createdAt] properties: id: type: string institutionId: type: string institutionName: type: string name: type: string type: type: string subtype: type: ["string", "null"] mask: type: ["string", "null"] currency: type: string createdAt: type: string AccountInput: type: object required: [publicToken, institutionId, institutionName] properties: publicToken: type: string institutionId: type: string institutionName: type: string # ── TRANSACTION ────────────────────────────────────────────────────────── Transaction: type: object required: [id, accountId, amount, currency, date, pending, createdAt] properties: id: type: string accountId: type: string amount: type: number currency: type: string merchantName: type: ["string", "null"] merchantNameRaw: type: ["string", "null"] categoryPrimary: type: ["string", "null"] categoryDetail: type: ["string", "null"] date: type: string pending: type: boolean matchId: type: ["integer", "null"] createdAt: type: string SyncResult: type: object required: [added, removed, updated, accounts] properties: added: type: integer removed: type: integer updated: type: integer accounts: type: integer # ── RECEIPT ────────────────────────────────────────────────────────────── Receipt: type: object required: [id, sourceFilePath, ocrEngine, processingStatus, createdAt, updatedAt] properties: id: type: integer sourceFilePath: type: string ocrEngine: type: string storeName: type: ["string", "null"] storeAddress: type: ["string", "null"] purchaseDate: type: ["string", "null"] subtotal: type: ["number", "null"] tax: type: ["number", "null"] total: type: ["number", "null"] paymentMethod: type: ["string", "null"] returnWindowDays: type: ["integer", "null"] returnDeadline: type: ["string", "null"] processingStatus: type: string ocrConfidence: type: ["number", "null"] notes: type: ["string", "null"] matchId: type: ["integer", "null"] createdAt: type: string updatedAt: type: string ReceiptDetail: type: object required: [id, sourceFilePath, ocrEngine, processingStatus, items, createdAt, updatedAt] properties: id: type: integer sourceFilePath: type: string ocrEngine: type: string storeName: type: ["string", "null"] storeAddress: type: ["string", "null"] purchaseDate: type: ["string", "null"] subtotal: type: ["number", "null"] tax: type: ["number", "null"] total: type: ["number", "null"] paymentMethod: type: ["string", "null"] returnWindowDays: type: ["integer", "null"] returnDeadline: type: ["string", "null"] processingStatus: type: string ocrConfidence: type: ["number", "null"] notes: type: ["string", "null"] matchId: type: ["integer", "null"] items: type: array items: $ref: "#/components/schemas/ReceiptItem" match: oneOf: - $ref: "#/components/schemas/ReceiptMatchSummary" - type: "null" createdAt: type: string updatedAt: type: string ReceiptMatchSummary: type: object description: The transaction this receipt is reconciled against, if any. required: [matchId, matchMethod, confirmed, transaction] properties: matchId: type: integer matchMethod: type: string confirmed: type: boolean transaction: type: object required: [id, merchantName, amount, date] properties: id: type: string merchantName: type: ["string", "null"] amount: type: number date: type: string ReceiptSuggestions: type: object description: Candidate transactions for an unmatched receipt, from the fuzzy-matching engine. Never implies a match has been created — the frontend must call POST /matches to actually link one. required: [status, suggestions] properties: status: type: string description: "auto_matched | needs_review | unmatched" suggestions: type: array items: type: object required: [bankTransactionId, merchantName, amount, date, confidenceScore] properties: bankTransactionId: type: string merchantName: type: ["string", "null"] amount: type: number date: type: string confidenceScore: type: number ReceiptInput: type: object required: [sourceFilePath, ocrEngine] properties: sourceFilePath: type: string ocrEngine: type: string sourceFileHash: type: ["string", "null"] storeName: type: ["string", "null"] purchaseDate: type: ["string", "null"] total: type: ["number", "null"] returnWindowDays: type: ["integer", "null"] notes: type: ["string", "null"] ReceiptUpdate: type: object properties: storeName: type: ["string", "null"] storeAddress: type: ["string", "null"] purchaseDate: type: ["string", "null"] subtotal: type: ["number", "null"] tax: type: ["number", "null"] total: type: ["number", "null"] paymentMethod: type: ["string", "null"] returnWindowDays: type: ["integer", "null"] notes: type: ["string", "null"] ReceiptItem: type: object required: [id, receiptId, description, quantity, unitPrice, lineTotal] properties: id: type: integer receiptId: type: integer description: type: string quantity: type: number unitPrice: type: number lineTotal: type: number category: type: ["string", "null"] sku: type: ["string", "null"] isTaxable: type: boolean sortOrder: type: integer ReceiptItemInput: type: object required: [description, quantity, unitPrice, lineTotal] properties: description: type: string quantity: type: number unitPrice: type: number lineTotal: type: number category: type: ["string", "null"] sku: type: ["string", "null"] ReceiptItemUpdate: type: object description: All fields optional — only fields present are updated. properties: description: type: string quantity: type: number unitPrice: type: number lineTotal: type: number category: type: ["string", "null"] sku: type: ["string", "null"] isTaxable: type: boolean # ── MATCH ───────────────────────────────────────────────────────────────── Match: type: object required: [id, receiptId, bankTransactionId, matchMethod, confirmed, createdAt] properties: id: type: integer receiptId: type: integer bankTransactionId: type: string matchMethod: type: string confidenceScore: type: ["number", "null"] scoreBreakdown: type: ["object", "null"] additionalProperties: type: number confirmed: type: boolean confirmedAt: type: ["string", "null"] createdAt: type: string MatchInput: type: object required: [receiptId, bankTransactionId] properties: receiptId: type: integer bankTransactionId: type: string MatchUpdate: type: object properties: confirmed: type: boolean ReconcileResult: type: object required: [autoMatched, needsReview, unmatched] properties: autoMatched: type: integer needsReview: type: integer unmatched: type: integer matches: type: array items: $ref: "#/components/schemas/Match" # ── DASHBOARD ───────────────────────────────────────────────────────────── DashboardSummary: type: object required: - totalReceipts - matchedReceipts - unmatchedReceipts - totalTransactions - unmatchedTransactions - expiringReturns - totalSpendThisMonth - pendingReconciliation properties: totalReceipts: type: integer matchedReceipts: type: integer unmatchedReceipts: type: integer totalTransactions: type: integer unmatchedTransactions: type: integer expiringReturns: type: integer totalSpendThisMonth: type: number pendingReconciliation: type: integer CategorySpend: type: object required: [category, total, count] properties: category: type: string total: type: number count: type: integer EventLogRequest: type: object description: >- Core Event Shape, as a request body. `event_type` must be "transaction" -- the only event type this tracker has. See EVENT_CONTRACT_OPENAPI.yaml for the tracker-agnostic version of this shape. required: [event_type, occurred_at] properties: event_type: type: string enum: [transaction] occurred_at: type: string description: Maps to bank_transactions.date, YYYY-MM-DD. amount: type: number default: 0 description: The transaction's dollar amount (signed -- positive spending, negative income). source: type: ["string", "null"] description: Defaults to "manual" for events logged through this endpoint. source_id: type: ["string", "null"] category: type: ["string", "null"] description: >- Maps to bank_transactions.userCategory. Valid values come from GET /transactions/categories (defaults + user-created) -- not a fixed enum in this schema since that list is dynamic. hidden: type: boolean default: false description: Maps directly to bank_transactions.ignored. status: type: ["string", "null"] description: >- Not persisted. Finance's real lifecycle field is `pending` (a boolean, surfaced in `metadata.pending` on read) -- deliberately not generalized into a string enum, per EVENT_CONTRACT_SPEC.md's Resolved Decision #3. metadata: type: object additionalProperties: true default: {} description: >- merchantName, merchantNameRaw, currency (all optional). Not a fixed schema -- see EventLogRequest's description. Event: type: object description: Core Event Shape, as returned by GET /events. required: [id, user_id, event_type, occurred_at, created_at, amount] properties: id: type: string user_id: type: integer event_type: type: string enum: [transaction] category: type: ["string", "null"] occurred_at: type: string created_at: type: string amount: type: number source: type: ["string", "null"] source_id: type: ["string", "null"] hidden: type: boolean default: false status: type: ["string", "null"] metadata: type: object additionalProperties: true default: {} LogEventResult: type: object required: [status, id] properties: status: type: string id: type: string EventsQueryResult: type: object required: [events, total] properties: events: type: array items: $ref: "#/components/schemas/Event" total: type: integer AggregationsResponse: type: object required: [data] properties: data: type: array items: type: object additionalProperties: oneOf: - type: string - type: number description: >- A dynamic group-dimension key ("category", "source", or "event_type", whichever aggType was requested) plus fixed total_amount (number) and unit (string, always "usd") fields.