Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
# Can also be set on the Settings page (stored encrypted).
# ANTHROPIC_API_KEY=
# OPENAI_API_KEY=
# OpenAI-compatible endpoint (DeepSeek, OpenRouter, Ollama, and similar).
# Set the provider to Custom in Settings, or provide both of these.
# CUSTOM_AI_API_KEY=
# CUSTOM_AI_BASE_URL=https://api.example.com/v1
# If only OPENAI_API_KEY is set, OpenAI is selected automatically.
# If both keys are set, Anthropic stays the default until you choose a provider in Settings.
# Provider and model choices are saved in Settings; environment keys take precedence over saved keys.
# If both official keys are set, Anthropic stays the default until you choose a provider in Settings.
# Provider, model, and custom base URL are saved in Settings; environment keys and CUSTOM_AI_BASE_URL take precedence.

# Optional market data: no provider is configured or enabled by this template.
# Choose a connection or upload candle CSVs in Settings > Market data.
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@ docker compose up -d

### Configuration (all optional)

| Env var | Effect |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| `JOURNAL_PASSWORD` | Require a password; recommended when accessible beyond localhost |
| `JOURNAL_SECRET` | Encryption key source for credentials at rest (default: generated key file in the data dir) |
| `JOURNAL_DATA_DIR` | Database, attachments, and local encryption key directory (default `./data` relative to the app process) |
| `ANTHROPIC_API_KEY` | Anthropic AI key via env instead of the Settings page |
| `OPENAI_API_KEY` | OpenAI AI key via env instead of the Settings page |
| Env var | Effect |
| -------------------- | -------------------------------------------------------------------------------------------------------- |
| `JOURNAL_PASSWORD` | Require a password; recommended when accessible beyond localhost |
| `JOURNAL_SECRET` | Encryption key source for credentials at rest (default: generated key file in the data dir) |
| `JOURNAL_DATA_DIR` | Database, attachments, and local encryption key directory (default `./data` relative to the app process) |
| `ANTHROPIC_API_KEY` | Anthropic AI key via env instead of the Settings page |
| `OPENAI_API_KEY` | OpenAI AI key via env instead of the Settings page |
| `CUSTOM_AI_API_KEY` | API key for an OpenAI-compatible endpoint chosen as Custom in Settings |
| `CUSTOM_AI_BASE_URL` | Base URL for that endpoint, such as `https://api.example.com/v1`. Overrides a URL saved in Settings |

Set these in the process environment or in `apps/web/.env.local` for local Next.js runs; the root [`.env.example`](.env.example) documents the optional values. For Docker, configure the service environment in [`docker-compose.yml`](docker-compose.yml).

For AI, open **Settings → AI**, select **Anthropic** or **OpenAI**, enter your API key, and choose **Save AI settings**. OpenAI defaults to `gpt-4.1-mini`; you can enter another text model ID available to your account. Each provider keeps its own encrypted key and model choice. Existing Anthropic settings continue to work. An OpenAI-only environment setup selects OpenAI automatically; with both keys present, Anthropic remains the default until you save a provider choice. Environment keys override saved keys and must be changed on the server. Saving settings does not make a model request or verify account access.
For AI, open **Settings → AI**, select **Anthropic**, **OpenAI**, or **Custom endpoint**, enter your API key, and choose **Save AI settings**. A custom endpoint also needs an OpenAI-compatible base URL and the model ID that endpoint expects. OpenAI defaults to `gpt-4.1-mini`; you can enter another text model ID available to your account. Each provider keeps its own encrypted key and model choice. Existing Anthropic settings continue to work. An OpenAI-only environment setup selects OpenAI automatically; with both official keys present, Anthropic remains the default until you save a provider choice. Environment keys override saved keys and must be changed on the server. Saving settings does not make a model request or verify account access.

Deploy anywhere a Node process and a persistent disk exist: Docker, Railway, Fly.io, a small VPS. Serverless platforms without a disk need an external database, which this release does not support. SQLite on disk is the point.

Expand Down Expand Up @@ -136,7 +138,7 @@ flowchart LR
| **Trade pages** | Charted on [Vela](https://www.npmjs.com/package/@luxalgo/vela) with entry/exit markers and P&L labels: fill paths from recorded executions, optional user-selected market candles, and trade replay. Estimated MAE/MFE, running P&L, executions, ratings, stops/targets, tags, mistakes. |
| **Daily journal** | Day stats, intraday P&L curve, autosaving Markdown notes with templates and attachments (images, PDFs). Type them or **dictate** them with browser speech recognition (no journal API key required; browser support and speech processing vary). |
| **Notebook & playbooks** | Folders, search, tags, trade links; named setups with rule checklists scored per trade, with adherence and followed-vs-broken performance in Reports. |
| **AI reflection** | Bring your own Anthropic or OpenAI API key: session recaps, per-trade critiques, "ask your journal" over your own aggregates. Key encrypted at rest; requests go from your server to the model, nowhere else. |
| **AI reflection** | Bring your own Anthropic, OpenAI, or OpenAI-compatible endpoint: session recaps, per-trade critiques, "ask your journal" over your own aggregates. Key encrypted at rest; requests go from your server to the model, nowhere else. |
| **Routines & misses** | Pre-, during- and post-session routines with weekday schedules and a 13-week history; a missed-opportunity log kept out of your trading metrics. |
| **Journal defaults** | Configure breakeven tolerance, plus fee and stop/target rules per account and symbol; set timezone and contract multipliers for consistent calculations. |
| **Prop firms** | Evaluation and reset expenses, refunds, payout requests, partial receipts, reversals, cash ROI, account phases, renewal reminders, attachments, and generic cash CSV import/export. Separate from trade P&L. |
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/app/accounts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Suspense, useState } from "react";
import { Archive, ArchiveRestore, Plus, RefreshCw, Trash2 } from "lucide-react";
import { AccountCreateForm } from "@/components/account-create-form";
import { FilterBar } from "@/components/filter-bar";
import { useI18n } from "@/components/locale";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
Expand Down Expand Up @@ -50,6 +51,7 @@ export default function AccountsPage() {
}

function Accounts() {
const { text } = useI18n();
const { data, refresh } = useApi<{ accounts: AccountRow[] }>("/api/accounts");
const [syncing, setSyncing] = useState<string | null>(null);
const [creating, setCreating] = useState(false);
Expand Down Expand Up @@ -80,7 +82,7 @@ function Accounts() {
return (
<div>
<FilterBar
title="Accounts"
title={text.pages.accounts}
actions={
<Button size="sm" onClick={() => setCreating(true)}>
<Plus />
Expand Down
30 changes: 28 additions & 2 deletions apps/web/src/app/api/settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import {
getImportTimeZone,
aiKeyEnvironment,
aiModelSetting,
customBaseUrlLocked,
getAiProvider,
getAiSettings,
setAiKey,
setSetting,
deleteSetting,
} from "@/server/settings";
import { AI_PROVIDERS, AI_PROVIDER_NAMES, isAiProvider, type AiProvider } from "@/lib/ai-settings";
import {
AI_PROVIDERS,
AI_PROVIDER_NAMES,
isAiProvider,
parseCustomBaseUrl,
type AiProvider,
} from "@/lib/ai-settings";
import { isTimeZone } from "@/lib/timezone";
import { parseCurrencyConversion, type CurrencyConversion } from "@/lib/currencies";

Expand All @@ -34,6 +42,8 @@ interface SettingsBody {
/** Set to a key string to store (encrypted), or null to clear. Absent = unchanged. */
anthropicKey?: string | null;
openaiKey?: string | null;
customKey?: string | null;
customBaseUrl?: string | null;
aiProvider?: AiProvider;
aiModel?: string;
currencyConversion?: CurrencyConversion;
Expand Down Expand Up @@ -68,7 +78,21 @@ export const PATCH = handler(async (request: Request) => {
}
}
if (body.aiProvider !== undefined)
requireValue(isAiProvider(body.aiProvider), "Choose Anthropic or OpenAI.");
requireValue(isAiProvider(body.aiProvider), "Choose Anthropic, OpenAI, or a custom endpoint.");
let normalizedBaseUrl: string | null | undefined;
if (body.customBaseUrl !== undefined) {
requireValue(
!customBaseUrlLocked(),
"Custom AI uses CUSTOM_AI_BASE_URL from the server environment. Update or remove it on the server.",
);
if (body.customBaseUrl === null) normalizedBaseUrl = null;
else {
requireValue(typeof body.customBaseUrl === "string", "Enter a valid API base URL.");
const parsed = parseCustomBaseUrl(body.customBaseUrl);
requireValue(parsed.ok, parsed.ok ? "" : parsed.error);
if (parsed.ok) normalizedBaseUrl = parsed.url;
}
}
const provider = body.aiProvider ?? getAiProvider();
if (body.aiModel !== undefined)
requireValue(
Expand Down Expand Up @@ -127,6 +151,8 @@ export const PATCH = handler(async (request: Request) => {
}
if (body.aiProvider !== undefined) setSetting("aiProvider", body.aiProvider);
if (body.aiModel !== undefined) setSetting(aiModelSetting(provider), body.aiModel.trim());
if (normalizedBaseUrl === null) deleteSetting("customBaseUrl");
else if (normalizedBaseUrl !== undefined) setSetting("customBaseUrl", normalizedBaseUrl);
});
return ok({ saved: true });
});
11 changes: 7 additions & 4 deletions apps/web/src/app/calendar/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { dayKeyOf } from "@luxalgo/journal-core";
import { CurrencyNotice } from "@/components/currency-notice";
import { CalendarPnl } from "@/components/calendar-pnl";
import { FilterBar, useFilters } from "@/components/filter-bar";
import { useI18n } from "@/components/locale";
import { localeTag } from "@/lib/locale";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
Expand All @@ -23,6 +25,7 @@ export default function CalendarPage() {
}

function CalendarView() {
const { text, locale } = useI18n();
const { query, timeZone } = useFilters();
const [selection, setMonth] = useState<{ year: number; month: number } | null>(null);
const { data, error, refresh } = useApi<CalendarResponse>(
Expand All @@ -40,20 +43,20 @@ function CalendarView() {
return (
<div>
<FilterBar
title="Calendar"
title={text.pages.calendar}
actions={
<div className="flex items-center gap-1">
<Button
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => shift(-1)}
aria-label="Previous month"
aria-label={text.pages.previousMonth}
>
<ChevronLeft />
</Button>
<span className="w-36 text-center text-sm font-medium">
{new Date(Date.UTC(month.year, month.month - 1)).toLocaleString("en-US", {
{new Date(Date.UTC(month.year, month.month - 1)).toLocaleString(localeTag(locale), {
month: "long",
year: "numeric",
timeZone: "UTC",
Expand All @@ -64,7 +67,7 @@ function CalendarView() {
size="icon"
className="h-8 w-8"
onClick={() => shift(1)}
aria-label="Next month"
aria-label={text.pages.nextMonth}
>
<ChevronRight />
</Button>
Expand Down
24 changes: 17 additions & 7 deletions apps/web/src/app/import/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ImportReconciliation } from "@/components/import-reconciliation";
import type { ImportReview, ImportReviewOptions } from "@/lib/import-review";
import { TimeZonePicker } from "@/components/timezone-picker";
import { AiImportOptions } from "@/components/ai-import-options";
import { useI18n } from "@/components/locale";
import { AI_DEFAULT_MODELS, type AiSettingsPayload } from "@/lib/ai-settings";
import {
AI_IMPORT_MAX_BYTES,
Expand Down Expand Up @@ -83,10 +84,11 @@ export default function ImportPage() {
}

function ImportView() {
const { text } = useI18n();
const router = useRouter();
return (
<div>
<FilterBar title="Import trades" />
<FilterBar title={text.pages.import} />
<div className="mx-auto max-w-3xl p-4">
<Tabs defaultValue="file">
<TabsList>
Expand Down Expand Up @@ -126,6 +128,7 @@ function ImportView() {
}

function FileImport() {
const { text } = useI18n();
const router = useRouter();
const [accountId, setAccountId] = useState("");
const [reviewOptions, setReviewOptions] = useState<ImportReviewOptions>({});
Expand Down Expand Up @@ -169,9 +172,16 @@ function FileImport() {
const timeZone = statementTimeZone ?? settingsData?.importTimeZone ?? "";
const validTimeZone = isTimeZone(timeZone);
const displayTimeZone = settingsData?.timeZone ?? "UTC";
const connection = settingsData?.aiConnections[aiOptions.provider];
const aiReady = Boolean(
aiOptions.model.trim() &&
(aiOptions.apiKey?.trim() || settingsData?.aiConnections[aiOptions.provider].configured),
(aiOptions.apiKey?.trim() ||
connection?.configured ||
(aiOptions.provider === "custom" && connection?.source)) &&
(aiOptions.provider !== "custom" ||
aiOptions.baseUrl?.trim() ||
connection?.baseUrl ||
connection?.baseUrlSource === "environment"),
);
const invalidateAiPreview = () => {
setPreview(null);
Expand Down Expand Up @@ -449,11 +459,11 @@ function FileImport() {
>
{busy
? aiEnabled
? "AI is reading your statement…"
: "Reading…"
? text.ai.readingAi
: text.ai.reading
: aiEnabled
? "Preview with AI"
: "Preview file"}
? text.ai.preview
: text.ai.previewFile}
</Button>
)}

Expand Down Expand Up @@ -687,7 +697,7 @@ function FileImport() {
(preview.detected === "ninjatrader" && !preview.reconciliation?.token)
}
>
{busy ? "Importing…" : "Import"}
{busy ? text.ai.importing : text.ai.import}
</Button>
{preview.aiPreviewToken && (
<label className="flex items-start gap-2 text-xs text-muted-foreground">
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/app/journal/[date]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Suspense, use, useRef, useState } from "react";
import type { IntradayPoint, TradeMetrics } from "@luxalgo/journal-core";
import { EquityArea } from "@/components/charts/equity-area";
import { FilterBar, useFilters } from "@/components/filter-bar";
import { useI18n } from "@/components/locale";
import { fill } from "@/lib/messages";
import { Pnl } from "@/components/pnl";
import { MonetaryValue } from "@/components/privacy";
import { VoiceNote } from "@/components/voice-note";
Expand Down Expand Up @@ -50,6 +52,7 @@ export default function JournalDayPage({ params }: { params: Promise<{ date: str
}

function JournalDay({ date }: { date: string }) {
const { text } = useI18n();
const { query, values: filters, timeZone } = useFilters();
const { data, error } = useApi<DayPayload>(`/api/journal/${date}?${query}`);
const [note, setNote] = useState<string | null>(null);
Expand All @@ -67,7 +70,7 @@ function JournalDay({ date }: { date: string }) {
const m = data?.metrics;
return (
<div>
<FilterBar title={`Journal · ${date}`} />
<FilterBar title={fill(text.pages.journalDay, { date })} />
<div className="grid gap-3 p-4 xl:grid-cols-3">
<div className="min-w-0 space-y-3 xl:col-span-2">
{m && m.closedTrades > 0 ? (
Expand Down
Loading