Full-stack self-hosted finance app with FastAPI backend and React frontend. Features: - Accounts, transactions, budgets, investments with GBP base currency - CSV import with auto-detection for 10 UK bank formats - ML predictions: spending forecast, net worth projection, Monte Carlo - 7 selectable themes (Obsidian, Arctic, Midnight, Vault, Terminal, Synthwave, Ledger) - Receipt/document attachments on transactions (JPEG, PNG, WebP, PDF) - AES-256-GCM field encryption, RS256 JWT, TOTP 2FA, RLS, audit log - Encrypted nightly backups + key rotation script - Mobile-responsive layout with bottom nav Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
2.3 KiB
Python
36 lines
2.3 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, LargeBinary, Numeric, String, Text
|
|
from sqlalchemy.dialects.postgresql import JSONB, UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Account(Base):
|
|
__tablename__ = "accounts"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
name_enc: Mapped[bytes] = mapped_column("name", LargeBinary, nullable=False)
|
|
institution_enc: Mapped[bytes | None] = mapped_column("institution", LargeBinary, nullable=True)
|
|
type: Mapped[str] = mapped_column(String(30), nullable=False)
|
|
currency: Mapped[str] = mapped_column(String(10), nullable=False)
|
|
current_balance: Mapped[Decimal] = mapped_column(Numeric(20, 8), default=0, nullable=False)
|
|
credit_limit: Mapped[Decimal | None] = mapped_column(Numeric(20, 8), nullable=True)
|
|
interest_rate: Mapped[Decimal | None] = mapped_column(Numeric(8, 4), nullable=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
include_in_net_worth: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
color: Mapped[str] = mapped_column(String(7), default="#6366f1", nullable=False)
|
|
icon: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
notes_enc: Mapped[bytes | None] = mapped_column("notes", LargeBinary, nullable=True)
|
|
meta: Mapped[dict] = mapped_column(JSONB, default=dict, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
user: Mapped["User"] = relationship(back_populates="accounts", lazy="noload") # type: ignore[name-defined]
|
|
transactions: Mapped[list["Transaction"]] = relationship(foreign_keys="Transaction.account_id", back_populates="account", lazy="noload") # type: ignore[name-defined]
|
|
holdings: Mapped[list["InvestmentHolding"]] = relationship(back_populates="account", lazy="noload") # type: ignore[name-defined]
|