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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .next/trace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"generate-buildid","duration":299,"timestamp":1496679668566,"id":4,"parentId":1,"tags":{},"startTime":1770437349361,"traceId":"07b981920be75e4a"},{"name":"load-custom-routes","duration":475,"timestamp":1496679669380,"id":5,"parentId":1,"tags":{},"startTime":1770437349362,"traceId":"07b981920be75e4a"},{"name":"create-dist-dir","duration":547,"timestamp":1496679669915,"id":6,"parentId":1,"tags":{},"startTime":1770437349363,"traceId":"07b981920be75e4a"},{"name":"clean","duration":547,"timestamp":1496679671999,"id":7,"parentId":1,"tags":{},"startTime":1770437349365,"traceId":"07b981920be75e4a"},{"name":"next-build","duration":2684150,"timestamp":1496676993412,"id":1,"tags":{"buildMode":"default","version":"16.1.6","bundler":"turbopack"},"startTime":1770437346686,"traceId":"07b981920be75e4a"}]
1 change: 1 addition & 0 deletions .next/trace-build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"next-build","duration":2684150,"timestamp":1496676993412,"id":1,"tags":{"buildMode":"default","version":"16.1.6","bundler":"turbopack"},"startTime":1770437346686,"traceId":"07b981920be75e4a"}]
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.terminal.useEnvFile": true
}
1 change: 1 addition & 0 deletions backend/models/ComplianceRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ComplianceRunSchema = new mongoose.Schema(
datasetId: { type: mongoose.Schema.Types.ObjectId, ref: "ComplianceDataset" },
entities: { type: [Object], default: [] },
transactions: { type: [Object], default: [] },
selectedRules: { type: [String], default: ["AML", "KYC", "OFAC", "SOX", "RegW", "Patterns"] },
alerts: { type: [Object], default: [] },
regulatoryScores: { type: [Object], default: [] },
summary: { type: String, default: "" },
Expand Down
25 changes: 17 additions & 8 deletions backend/routes/compliance.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,33 @@ router.get("/runs", async (_req, res) => {
// POST /api/compliance/scan
router.post("/scan", async (req, res) => {
try {
const { entities, transactions } = req.body;
const { entities, transactions, selectedRules } = req.body;
const rules = selectedRules || ["AML", "KYC", "OFAC", "SOX", "RegW", "Patterns"];

if (!process.env.DEDALUS_API_KEY && !process.env.OPENAI_API_KEY) {
return res.status(500).json({ error: "DEDALUS_API_KEY or OPENAI_API_KEY not set" });
}

const rulesText = rules.map(rule => {
const ruleMap = {
"AML": "- AML (Anti-Money Laundering) red flags",
"KYC": "- KYC (Know Your Customer) issues",
"OFAC": "- OFAC sanctions screening concerns",
"SOX": "- SOX (Sarbanes-Oxley) control violations",
"RegW": "- Regulation W affiliate transaction limits",
"Patterns": "- Unusual transaction patterns"
};
return ruleMap[rule] || "";
}).filter(Boolean).join("\n");

const response = await openai.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [
{
role: "system",
content: `You are a financial compliance AI. Analyze the provided entities and transactions for regulatory compliance issues.
Check for:
- AML (Anti-Money Laundering) red flags
- KYC (Know Your Customer) issues
- OFAC sanctions screening concerns
- SOX (Sarbanes-Oxley) control violations
- Regulation W affiliate transaction limits
- Unusual transaction patterns
${rulesText}

Return a JSON object with:
- "alerts": array of objects with "id" (generate CMP-xxx), "rule", "entity", "severity" (high/medium/low), "detail", "recommended_action"
Expand All @@ -82,13 +90,14 @@ Return ONLY valid JSON, no markdown.`,
datasetId: dataset._id,
entities: entities || [],
transactions: transactions || [],
selectedRules: rules,
alerts: parsed.alerts || [],
regulatoryScores: parsed.regulatory_scores || [],
summary: parsed.summary || "",
status: "success",
});

res.json({ ...parsed, runId: run._id });
res.json({ ...parsed, runId: run._id, selectedRules: rules });
} catch (error) {
console.error("Compliance scan error:", error);
await ComplianceRun.create({
Expand Down
207 changes: 164 additions & 43 deletions frontend/app/dashboard/compliance/page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { useEffect, useState, useMemo } from "react";

const API = process.env.NEXT_PUBLIC_API_URL || "http://localhost:5001";

Expand All @@ -21,6 +21,26 @@ export default function CompliancePage() {
const [transactionsInput, setTransactionsInput] = useState("[]");
const [inputError, setInputError] = useState("");
const [runs, setRuns] = useState([]);
const [alertRuleFilters, setAlertRuleFilters] = useState([
"AML",
"KYC",
"OFAC",
"SOX",
"RegW",
"Patterns",
]);
const [alertSeverityFilters, setAlertSeverityFilters] = useState(["high", "medium", "low"]);
const [alertSearchQuery, setAlertSearchQuery] = useState("");
const [selectedRules, setSelectedRules] = useState(["AML", "KYC", "OFAC", "SOX", "RegW", "Patterns"]);

const complianceRules = [
{ id: "AML", label: "AML - Anti-Money Laundering" },
{ id: "KYC", label: "KYC - Know Your Customer" },
{ id: "OFAC", label: "OFAC - Sanctions Screening" },
{ id: "SOX", label: "SOX - Sarbanes-Oxley" },
{ id: "RegW", label: "Regulation W - Affiliate Limits" },
{ id: "Patterns", label: "Transaction Patterns" },
];

useEffect(() => {
reloadDataset();
Expand All @@ -36,7 +56,7 @@ export default function CompliancePage() {
const res = await fetch(`${API}/api/compliance/scan`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ entities, transactions }),
body: JSON.stringify({ entities, transactions, selectedRules }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error);
Expand Down Expand Up @@ -134,6 +154,32 @@ export default function CompliancePage() {
</button>
</div>

<div className="rounded border p-5 space-y-3" style={{ background: "var(--card)", borderColor: "var(--border)" }}>
<div>
<p className="text-[11px] font-semibold uppercase tracking-wider" style={{ color: "var(--muted)" }}>Compliance Rules to Check</p>
<p className="text-xs mt-1" style={{ color: "var(--muted)" }}>Select which compliance rules to scan for.</p>
</div>
<div className="grid grid-cols-2 gap-3">
{complianceRules.map((rule) => (
<label key={rule.id} className="flex items-center gap-2 cursor-pointer">
<input
type="checkbox"
checked={selectedRules.includes(rule.id)}
onChange={(e) => {
if (e.target.checked) {
setSelectedRules([...selectedRules, rule.id]);
} else {
setSelectedRules(selectedRules.filter((r) => r !== rule.id));
}
}}
className="w-4 h-4"
/>
<span className="text-xs" style={{ color: "var(--foreground)" }}>{rule.label}</span>
</label>
))}
</div>
</div>

<div className="rounded border p-5 space-y-3" style={{ background: "var(--card)", borderColor: "var(--border)" }}>
<div className="flex items-center justify-between gap-4">
<div>
Expand All @@ -143,14 +189,14 @@ export default function CompliancePage() {
<div className="flex items-center gap-2">
<button
onClick={loadInputs}
className="rounded-sm px-3 py-1.5 text-xs font-medium"
className="rounded-sm px-3 py-1.5 text-xs font-medium btn-click"
style={{ background: "var(--background)", color: "var(--accent)", border: "1px solid var(--border)" }}
>
Load Local
</button>
<button
onClick={saveDataset}
className="rounded-sm px-3 py-1.5 text-xs font-medium"
className="rounded-sm px-3 py-1.5 text-xs font-medium btn-click"
style={{ background: "var(--background)", color: "var(--accent)", border: "1px solid var(--border)" }}
>
Save to DB
Expand All @@ -165,22 +211,28 @@ export default function CompliancePage() {
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<textarea
value={entitiesInput}
onChange={(e) => setEntitiesInput(e.target.value)}
rows={6}
className="w-full rounded border p-3 text-xs font-mono"
style={{ background: "var(--background)", borderColor: "var(--border)", color: "var(--foreground)" }}
placeholder='[{"name":"Counterparty A","type":"Counterparty","kyc_expiry":"2026-03-01","jurisdiction":"US"}]'
/>
<textarea
value={transactionsInput}
onChange={(e) => setTransactionsInput(e.target.value)}
rows={6}
className="w-full rounded border p-3 text-xs font-mono"
style={{ background: "var(--background)", borderColor: "var(--border)", color: "var(--foreground)" }}
placeholder='[{"id":"TXN-001","entity":"Counterparty A","amount":"1000","type":"Wire","date":"2026-02-07"}]'
/>
<div>
<p className="text-[11px] font-semibold mb-2" style={{ color: "var(--muted)" }}>Entities</p>
<textarea
value={entitiesInput}
onChange={(e) => setEntitiesInput(e.target.value)}
rows={6}
className="w-full rounded border p-3 text-xs font-mono"
style={{ background: "var(--background)", borderColor: "var(--border)", color: "var(--foreground)" }}
placeholder='[{"name":"Counterparty A","type":"Counterparty","kyc_expiry":"2026-03-01","jurisdiction":"US"}]'
/>
</div>
<div>
<p className="text-[11px] font-semibold mb-2" style={{ color: "var(--muted)" }}>Transactions</p>
<textarea
value={transactionsInput}
onChange={(e) => setTransactionsInput(e.target.value)}
rows={6}
className="w-full rounded border p-3 text-xs font-mono"
style={{ background: "var(--background)", borderColor: "var(--border)", color: "var(--foreground)" }}
placeholder='[{"id":"TXN-001","entity":"Counterparty A","amount":"1000","type":"Wire","date":"2026-02-07"}]'
/>
</div>
</div>
{inputError && <p className="text-xs" style={{ color: "#b54a4a" }}>{inputError}</p>}
<p className="text-xs" style={{ color: "var(--muted)" }}>
Expand Down Expand Up @@ -230,40 +282,109 @@ export default function CompliancePage() {
<div className="col-span-2">
<div className="rounded border" style={{ background: "var(--card)", borderColor: "var(--border)" }}>
<div className="border-b px-5 py-4" style={{ borderColor: "var(--border)" }}>
<h2 className="text-sm font-semibold" style={{ color: "var(--foreground)" }}>
{alerts.length > 0 ? `Active Alerts (${alerts.length})` : "Active Alerts"}
</h2>
<div className="flex items-center justify-between">
<h2 className="text-sm font-semibold" style={{ color: "var(--foreground)" }}>
{alerts.length > 0 ? `Active Alerts (${alerts.length})` : "Active Alerts"}
</h2>
<div className="flex items-center gap-2">
<input
type="text"
placeholder="Search alerts"
value={alertSearchQuery}
onChange={(e) => setAlertSearchQuery(e.target.value)}
className="text-xs rounded-sm px-2 py-1"
style={{ border: "1px solid var(--border)", background: "var(--background)", color: "var(--foreground)" }}
/>
</div>
</div>
</div>
<div className="px-5 py-3 flex items-center gap-4" style={{ borderBottom: "1px solid var(--border)" }}>
<div className="flex items-center gap-3">
<p className="text-xs font-semibold" style={{ color: "var(--muted)" }}>Rules:</p>
{complianceRules.map((r) => (
<label key={r.id} className="flex items-center gap-1 text-xs" style={{ color: "var(--foreground)" }}>
<input
type="checkbox"
checked={alertRuleFilters.includes(r.id)}
onChange={(e) => {
if (e.target.checked) setAlertRuleFilters([...alertRuleFilters, r.id]);
else setAlertRuleFilters(alertRuleFilters.filter((x) => x !== r.id));
}}
className="w-3 h-3"
/>
<span>{r.id}</span>
</label>
))}
</div>
<div className="flex items-center gap-3">
<p className="text-xs font-semibold" style={{ color: "var(--muted)" }}>Severity:</p>
{["high", "medium", "low"].map((s) => (
<label key={s} className="flex items-center gap-1 text-xs" style={{ color: "var(--foreground)" }}>
<input
type="checkbox"
checked={alertSeverityFilters.includes(s)}
onChange={(e) => {
if (e.target.checked) setAlertSeverityFilters([...alertSeverityFilters, s]);
else setAlertSeverityFilters(alertSeverityFilters.filter((x) => x !== s));
}}
className="w-3 h-3"
/>
<span className="capitalize">{s}</span>
</label>
))}
</div>
</div>
{alerts.length === 0 ? (
<div className="px-5 py-8 text-center">
<p className="text-sm" style={{ color: "var(--muted)" }}>{scanning ? "Scanning..." : "Run a compliance scan to detect issues."}</p>
</div>
) : (
<div className="divide-y" style={{ borderColor: "var(--border)" }}>
{alerts.map((alert, i) => (
<div key={alert.id || i} className="px-5 py-4">
<div className="flex items-start justify-between">
<div className="flex items-center gap-2.5">
<div className="h-2 w-2 rounded-sm" style={{ background: severityStyles[alert.severity]?.color || "var(--muted)" }} />
<div>
<div className="flex items-center gap-2">
<span className="text-[13px] font-medium" style={{ color: "var(--foreground)" }}>{alert.rule}</span>
<span className="rounded-sm px-2 py-0.5 text-[10px] font-medium capitalize"
style={{ background: severityStyles[alert.severity]?.bg, color: severityStyles[alert.severity]?.color }}>
{alert.severity}
</span>
(() => {
const filtered = alerts.filter((alert) => {
if (!alert) return false;
if (alert.rule && !alertRuleFilters.includes(alert.rule)) return false;
if (alert.severity && !alertSeverityFilters.includes(alert.severity)) return false;
if (alertSearchQuery) {
const q = alertSearchQuery.toLowerCase();
const hay = `${alert.rule || ""} ${alert.entity || ""} ${alert.detail || ""} ${alert.id || ""}`.toLowerCase();
if (!hay.includes(q)) return false;
}
return true;
});

return (
<div className="divide-y" style={{ borderColor: "var(--border)" }}>
{filtered.map((alert, i) => (
<div key={alert.id || i} className="px-5 py-4">
<div className="flex items-start justify-between">
<div className="flex items-center gap-2.5">
<div className="h-2 w-2 rounded-sm" style={{ background: severityStyles[alert.severity]?.color || "var(--muted)" }} />
<div>
<div className="flex items-center gap-2">
<span className="text-[13px] font-medium" style={{ color: "var(--foreground)" }}>{alert.rule}</span>
<span className="rounded-sm px-2 py-0.5 text-[10px] font-medium capitalize"
style={{ background: severityStyles[alert.severity]?.bg, color: severityStyles[alert.severity]?.color }}>
{alert.severity}
</span>
</div>
<p className="text-xs" style={{ color: "var(--muted)" }}>{alert.entity}</p>
</div>
</div>
<p className="text-xs" style={{ color: "var(--muted)" }}>{alert.entity}</p>
</div>
<p className="mt-2 pl-[18px] text-xs leading-relaxed" style={{ color: "var(--muted)" }}>{alert.detail}</p>
{alert.recommended_action && (
<p className="mt-1 pl-[18px] text-xs" style={{ color: "var(--accent)" }}>Action: {alert.recommended_action}</p>
)}
</div>
))}
{filtered.length === 0 && (
<div className="px-5 py-6 text-center">
<p className="text-sm" style={{ color: "var(--muted)" }}>No alerts match the current filters.</p>
</div>
</div>
<p className="mt-2 pl-[18px] text-xs leading-relaxed" style={{ color: "var(--muted)" }}>{alert.detail}</p>
{alert.recommended_action && (
<p className="mt-1 pl-[18px] text-xs" style={{ color: "var(--accent)" }}>Action: {alert.recommended_action}</p>
)}
</div>
))}
</div>
);
})()
)}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/dashboard/reconciliation/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ export default function ReconciliationPage() {
<div className="flex items-center gap-2">
<button
onClick={loadTransactions}
className="rounded-sm px-3 py-1.5 text-xs font-medium"
className="rounded-sm px-3 py-1.5 text-xs font-medium btn-click"
style={{ background: "var(--background)", color: "var(--accent)", border: "1px solid var(--border)" }}
>
Load Local
</button>
<button
onClick={saveDataset}
className="rounded-sm px-3 py-1.5 text-xs font-medium"
className="rounded-sm px-3 py-1.5 text-xs font-medium btn-click"
style={{ background: "var(--background)", color: "var(--accent)", border: "1px solid var(--border)" }}
>
Save to DB
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/dashboard/reports/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ReportsPage() {
</div>
</div>
<button
className="ml-4 rounded-sm px-3 py-1.5 text-xs font-medium transition-colors"
className="ml-4 rounded-sm px-3 py-1.5 text-xs font-medium transition-colors btn-click"
style={{ background: "var(--background)", color: "var(--accent)", border: "1px solid var(--border)" }}
>
Generate
Expand Down
Loading