# CubisFIN

## Purpose

CubisFIN is a desktop investment portfolio application built with Python and PySide6.

The app currently provides:

- a local SQLite-backed portfolio database
- dashboard, transaction, allocation, exposure, positions, settings, and AI insights views
- market-data-backed portfolio calculations and charts
- first-run example data when no existing database is present

## Project Structure

```text
cubisfin/
  main.py
  requirements.txt
  requirements-packaging.txt
  CubisFIN.spec
  README.md
  .gitignore
  installer/
    CubisFIN.iss
  scripts/
    build_windows.ps1
    build_installer.ps1
  app/
    __init__.py
    config.py
    ui/
      __init__.py
      main_window.py
      views/
        __init__.py
        dashboard_view.py
        transactions_view.py
        positions_view.py
        allocation_view.py
        settings_view.py
    services/
      __init__.py
    providers/
      __init__.py
    domain/
      __init__.py
    db/
      __init__.py
    utils/
      __init__.py
```

## Setup

Create a virtual environment:

```powershell
python -m venv .venv
```

Activate it on Windows PowerShell:

```powershell
.venv\Scripts\Activate.ps1
```

Install requirements:

```powershell
python -m pip install --upgrade pip
pip install -r requirements.txt
```

## Run The App

```powershell
python main.py
```

## Local Data Storage

CubisFIN stores writable runtime data outside the install directory so packaged builds can run safely under normal Windows installs.

On Windows, the default app home is:

```text
%LOCALAPPDATA%\CUBIS SOFT SRL\CubisFIN\
```

That location contains:

- `data\portfolio_app.db`
- `cache\matplotlib\`
- `cache\yfinance\`
- `logs\cubisfin.log`

For local testing or CI, you can override the storage paths:

```powershell
$env:CUBISFIN_HOME = "C:\temp\cubisfin-test"
$env:CUBISFIN_DB_PATH = "C:\temp\cubisfin-test\data\custom.db"
```

## Packaging For Windows

Install packaging requirements into the same virtual environment used for the app:

```powershell
.\.venv\Scripts\python.exe -m pip install -r requirements-packaging.txt
```

Build a bundled Windows app folder:

```powershell
.\scripts\build_windows.ps1 -Clean
```

That produces:

```text
dist\CubisFIN\
```

Build a portable zip that can be shared directly with users:

```powershell
.\scripts\build_windows.ps1 -Clean -CreatePortableZip
```

That produces:

```text
release\CubisFIN-<version>-portable.zip
```

Build the Windows installer after the bundled app exists and Inno Setup 6 is installed:

```powershell
.\scripts\build_installer.ps1 -BuildAppFirst -Clean
```

That produces:

```text
release\CubisFIN-Setup-<version>.exe
```

Notes about packaging:

- Users do not need Python installed when running the packaged app.
- The installer defaults to a per-user install under `%LOCALAPPDATA%\Programs\CubisFIN` so admin rights are not required.
- Runtime data is still stored separately under `%LOCALAPPDATA%\CUBIS SOFT SRL\CubisFIN\`.
- `APP_VERSION` in `app/config.py` is the current app version used by the packaging scripts.

## Notes

- Existing databases are left untouched during startup.
- A new database is seeded with example portfolio data only when no database file exists yet.
- OpenAI API keys are currently stored in plaintext application settings and should be hardened before external distribution.
