From 92cdadc6f2c76e1d427a8dd442f7d68f891eedd4 Mon Sep 17 00:00:00 2001 From: Harshil Date: Sun, 4 Oct 2026 18:35:57 +0530 Subject: [PATCH 01/11] feat: add repository guidelines and development instructions --- AGENTS.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..a9c2f63 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,45 @@ +# Repository Guidelines + +## Project Structure & Module Organization + +PaperDrill is a Bun/TypeScript monorepo without a root `package.json`. Each package owns its dependencies and `bun.lock`: + +- `backend/`: Express REST/WebSocket API and Prisma schema/migrations. +- `engine/`: in-memory order matching and snapshot persistence. +- `worker/`: Redis stream persistence, candles, and tickers. +- `bot/`: optional market-making clients. +- `frontend/`: React 19/Tailwind 4 SPA; static assets live in `frontend/public/`. +- `tests/integration/`: black-box cross-service tests. +- `benchmarks/`: HTTP, matching, and WebSocket performance scenarios. + +Keep unit tests in `backend/tests/` or `engine/tests/`. Public documentation belongs in `frontend/src/content/docs/`; root `docs/` is stale. + +## Build, Test, and Development Commands + +Run `bun install` inside an individual package after changing its dependencies. Common root commands are: + +- `make up`: start dependencies, migrate/seed the database, and launch backend, engine, and worker. +- `make build`: build the main development containers. +- `make logs SERVICE=backend`: follow service logs. +- `make test-unit`: run backend and engine Bun tests with `.env.test`. +- `make test-integration`: exercise the disposable test stack. +- `make bench`: run the benchmark suite. +- `make down`: stop the development stack. + +For frontend-only work, use `cd frontend && bun run dev` or `bun run build`. + +## Coding Style & Naming Conventions + +Follow existing TypeScript style: tabs, double quotes, semicolons, ESM imports, and trailing commas in multiline constructs. Use `camelCase` for variables/functions, `PascalCase` for components and types, and established kebab-case filenames (for example, `decimal-input.tsx`). No repository-wide formatter or linter is configured, so match adjacent code. + +## Testing Guidelines + +Tests use `bun:test` and `.test.ts` filenames. Add unit coverage for local logic and integration coverage for cross-service behavior. There is no stated coverage threshold; regressions should include a test that fails without the fix. Run both test commands before submitting service-wide changes. + +## Commit & Pull Request Guidelines + +Use Conventional Commit prefixes: `feat:`, `fix:`, `docs:`, `ci:`, or a scope such as `fix(bot):`. Keep commits focused. Pull requests should explain the change, identify affected services, link issues, list verification commands, and include screenshots for visible frontend work. Call out migrations, environment changes, or snapshot compatibility concerns. + +## Security & Configuration + +Never commit `.env.dev`, `.env.prod`, generated Prisma clients, engine snapshots, build output, or secrets. Do not add fallback production credentials. Preserve the established API error envelope and use `bigintReplacer` for BigInt values crossing JSON or Redis boundaries. From 3b9470b486e48bc4977fd6d986072d165daf08f9 Mon Sep 17 00:00:00 2001 From: Harshil Date: Sun, 4 Oct 2026 18:37:52 +0530 Subject: [PATCH 02/11] refactor: navigation structure, providers, improved components --- frontend/build.ts | 10 +- frontend/src/components/app-layout.tsx | 29 ++--- frontend/src/components/app-sidebar.tsx | 65 ++++++----- frontend/src/components/dashboard-layout.tsx | 13 +-- frontend/src/components/dashboard-page.tsx | 9 +- frontend/src/components/landing/navbar.tsx | 20 ++-- frontend/src/components/market/data-panel.tsx | 2 +- .../src/components/market/market-header.tsx | 2 +- frontend/src/components/market/orderbook.tsx | 16 +-- frontend/src/components/market/trade-form.tsx | 2 +- frontend/src/components/market/trades.tsx | 2 +- frontend/src/components/mobile-disclaimer.tsx | 21 ---- frontend/src/components/navbar.tsx | 21 ++-- frontend/src/components/root-layout.tsx | 6 +- frontend/src/components/ui/feedback-state.tsx | 54 +++++++++ frontend/src/components/ui/metric.tsx | 40 +++++++ frontend/src/components/ui/page.tsx | 30 ++++- frontend/src/components/ui/sidebar.tsx | 2 +- frontend/src/components/ui/skip-link.tsx | 10 ++ frontend/src/components/ui/surface.tsx | 38 +++++++ frontend/src/components/ui/tabs.tsx | 2 +- frontend/src/frontend.tsx | 10 +- frontend/src/lib/navigation.ts | 47 ++++++++ frontend/src/pages/dashboard/balances.tsx | 31 +---- frontend/src/pages/dashboard/overview.tsx | 30 +---- frontend/src/pages/leaderboard.tsx | 76 ++++++------- frontend/src/pages/markets.tsx | 23 ++-- frontend/src/pages/privacy.tsx | 7 +- frontend/src/pages/terms.tsx | 9 +- frontend/src/pages/trade.tsx | 106 ++++++++---------- frontend/styles/globals.css | 50 +++++++-- 31 files changed, 449 insertions(+), 334 deletions(-) delete mode 100644 frontend/src/components/mobile-disclaimer.tsx create mode 100644 frontend/src/components/ui/feedback-state.tsx create mode 100644 frontend/src/components/ui/metric.tsx create mode 100644 frontend/src/components/ui/skip-link.tsx create mode 100644 frontend/src/components/ui/surface.tsx create mode 100644 frontend/src/lib/navigation.ts diff --git a/frontend/build.ts b/frontend/build.ts index 11e1ed9..4e2203a 100644 --- a/frontend/build.ts +++ b/frontend/build.ts @@ -33,7 +33,7 @@ Example: process.exit(0); } -const toCamelCase = (str: string): string => str.replace(/-([a-z])/g, (g) => g[1].toUpperCase()); +const toCamelCase = (str: string): string => str.replace(/-([a-z])/g, (g) => g[1]!.toUpperCase()); const parseValue = (value: string): any => { if (value === "true") return true; @@ -48,7 +48,7 @@ const parseValue = (value: string): any => { }; function parseArgs(): Partial { - const config: Partial = {}; + const config: Record = {}; const args = process.argv.slice(2); for (let i = 0; i < args.length; i++) { @@ -81,7 +81,7 @@ function parseArgs(): Partial { key = toCamelCase(key); if (key.includes(".")) { - const [parentKey, childKey] = key.split("."); + const [parentKey, childKey] = key.split(".") as [string, string]; config[parentKey] = config[parentKey] || {}; config[parentKey][childKey] = parseValue(value); } else { @@ -89,7 +89,7 @@ function parseArgs(): Partial { } } - return config; + return config as Partial; } const formatFileSize = (bytes: number): string => { @@ -102,7 +102,7 @@ const formatFileSize = (bytes: number): string => { unitIndex++; } - return `${size.toFixed(2)} ${units[unitIndex]}`; + return `${size.toFixed(2)} ${units[unitIndex]!}`; }; console.log("\nπŸš€ Starting build process...\n"); diff --git a/frontend/src/components/app-layout.tsx b/frontend/src/components/app-layout.tsx index 7a02451..1dbd484 100644 --- a/frontend/src/components/app-layout.tsx +++ b/frontend/src/components/app-layout.tsx @@ -1,32 +1,27 @@ import { Outlet, useLocation } from "react-router-dom"; import { Navbar } from "./navbar"; -import { MobileDisclaimer } from "./mobile-disclaimer"; import { SeoHead } from "@/components/seo-head"; -import { AuthProvider } from "@/context/AuthContext"; -import { MarketProvider } from "@/context/MarketContext"; +import { SkipLink } from "@/components/ui/skip-link"; export function AppLayout() { - return ( - - - - - - ); -} - -function AppShell() { const { pathname } = useLocation(); const isDashboard = pathname.startsWith("/dashboard"); return ( -
+
+ {!isDashboard && } -
- {!isDashboard && } + {isDashboard ? ( -
+ ) : ( +
+ +
+ )}
); } diff --git a/frontend/src/components/app-sidebar.tsx b/frontend/src/components/app-sidebar.tsx index eb881f4..2aab681 100644 --- a/frontend/src/components/app-sidebar.tsx +++ b/frontend/src/components/app-sidebar.tsx @@ -6,6 +6,7 @@ import { LayoutDashboard, Trophy, WalletCards, + type LucideIcon, } from "lucide-react"; import type { ComponentProps } from "react"; import { Link } from "react-router-dom"; @@ -22,13 +23,28 @@ import { SidebarMenuItem, SidebarRail, } from "@/components/ui/sidebar"; +import { dashboardNavigation, dashboardUtilityNavigation } from "@/lib/navigation"; -const navigation: DashboardNavItem[] = [ - { title: "Overview", url: "/dashboard", icon: LayoutDashboard, end: true }, - { title: "API keys", url: "/dashboard/api-keys", icon: KeyRound }, - { title: "Balances", url: "/dashboard/balances", icon: WalletCards }, - { title: "Account data", url: "/dashboard/data", icon: Database }, -]; +type SidebarNavigationId = + | (typeof dashboardNavigation)[number]["id"] + | (typeof dashboardUtilityNavigation)[number]["id"]; + +const icons: Record = { + overview: LayoutDashboard, + "api-keys": KeyRound, + balances: WalletCards, + "account-data": Database, + leaderboard: Trophy, + trading: ArrowUpRight, + docs: BookOpen, +}; + +const navigation: DashboardNavItem[] = dashboardNavigation.map((item) => ({ + title: item.label, + url: item.href, + icon: icons[item.id], + end: item.end, +})); export function AppSidebar(props: ComponentProps) { return ( @@ -44,30 +60,19 @@ export function AppSidebar(props: ComponentProps) {
- - - - - Leaderboard - - - - - - - - Open trading - - - - - - - - Documentation - - - + {dashboardUtilityNavigation.map((item) => { + const Icon = icons[item.id]; + return ( + + + + + {item.label} + + + + ); + })}
diff --git a/frontend/src/components/dashboard-layout.tsx b/frontend/src/components/dashboard-layout.tsx index a4ea828..eb07951 100644 --- a/frontend/src/components/dashboard-layout.tsx +++ b/frontend/src/components/dashboard-layout.tsx @@ -12,24 +12,17 @@ import { Separator } from "@/components/ui/separator"; import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"; import { Button } from "@/components/ui/button"; import { useTheme } from "@/lib/theme-provider"; - -const pageNames: Record = { - "/dashboard": "Overview", - "/dashboard/api-keys": "API keys", - "/dashboard/balances": "Balances", - "/dashboard/data": "Account data", - "/dashboard/profile": "Profile", -}; +import { dashboardPageNames } from "@/lib/navigation"; export function DashboardLayout() { const { pathname } = useLocation(); const { theme, toggleTheme } = useTheme(); - const pageName = pageNames[pathname] ?? "Dashboard"; + const pageName = dashboardPageNames[pathname] ?? "Dashboard"; return ( - +
diff --git a/frontend/src/components/dashboard-page.tsx b/frontend/src/components/dashboard-page.tsx index 2ff284c..bdfebe0 100644 --- a/frontend/src/components/dashboard-page.tsx +++ b/frontend/src/components/dashboard-page.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from "react"; import { cn } from "@/lib/utils"; +import { PageHeading } from "@/components/ui/page"; export function DashboardPage({ title, @@ -16,13 +17,7 @@ export function DashboardPage({ }) { return (
-
-
-

{title}

-

{description}

-
- {action &&
{action}
} -
+ {children}
); diff --git a/frontend/src/components/landing/navbar.tsx b/frontend/src/components/landing/navbar.tsx index 74e3421..6dae252 100644 --- a/frontend/src/components/landing/navbar.tsx +++ b/frontend/src/components/landing/navbar.tsx @@ -4,13 +4,7 @@ import { Menu, X, Sun, Moon } from "lucide-react"; import { useTheme } from "@/lib/theme-provider"; import { BrandLogo } from "@/components/brand-logo"; import { Sheet, SheetClose, SheetContent, SheetTitle, SheetTrigger } from "../ui/sheet"; - -const LINKS = [ - { label: "Markets", to: "/markets" }, - { label: "Trading", to: "/trade/BTC_USD" }, - { label: "Leaderboard", to: "/leaderboard" }, - { label: "Docs", to: "/docs" }, -]; +import { primaryNavigation } from "@/lib/navigation"; export function Navbar() { const { theme, toggleTheme } = useTheme(); @@ -21,10 +15,10 @@ export function Navbar() {