Skip to content

thepranaygupta/khaata

Repository files navigation

खाता Khaata

Trading journal and P&L analytics for Indian retail traders. Import .xlsx transaction exports from INDmoney, Groww, Zerodha, or Motilal Oswal, auto-match trades using FIFO, and get deep performance analytics.

Tech Stack

  • Framework: Next.js 15 (App Router, Turbopack)
  • Language: TypeScript (strict)
  • Styling: Tailwind CSS + shadcn/ui (dark mode first)
  • Fonts: Geist Sans (body), Geist Mono (numbers), IM Fell Great Primer (display headings)
  • Auth: Clerk email OTP (@clerk/nextjs)
  • Database: Neon Postgres + Prisma ORM
  • Charts: Recharts
  • File Parsing: xlsx
  • URL State: nuqs
  • Toasts: sonner
  • Dates: date-fns
  • Package Manager: pnpm
  • Deployment: Vercel

Getting Started

Prerequisites

  • Node.js 18+
  • pnpm
  • Neon Postgres database (free tier works)
  • Clerk account (free tier works)

Setup

# Install dependencies
pnpm install

# Copy env file and fill in your credentials
cp .env.example .env.local
cp .env.example .env

# Generate Prisma client
pnpm prisma generate

# Push schema to database
pnpm prisma db push

# Seed demo data (optional)
pnpm prisma db seed

# Start dev server
pnpm dev

Environment Variables

Create .env and .env.local with:

DATABASE_URL=              # Neon pooled connection string
DIRECT_URL=                # Neon direct connection string
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
NEXT_PUBLIC_APP_URL=http://localhost:3000

Prisma CLI reads from .env, Next.js reads from .env.local. Both need the DB URLs.

Scripts

pnpm dev              # Start dev server (Turbopack)
pnpm build            # Production build
pnpm lint             # Run linter
pnpm prisma generate  # Generate Prisma client
pnpm prisma db push   # Push schema to database
pnpm prisma db seed   # Seed demo data
pnpm prisma studio    # Open Prisma Studio

Pages

Route Description
/ Landing page
/login Email OTP login (password fallback in dev)
/dashboard KPI cards, cumulative/monthly P&L charts, stats
/insights Risk models, Kelly criterion, risk of ruin, day-of-week analysis
/path-to-profitability Goal setting, position sizing, scenario simulator
/calendar Monthly heatmap of daily P&L
/journal Trade table with sorting, filtering, inline editing, CSV export
/import Drag-drop .xlsx upload, FIFO matching preview, import history
/demo/* Read-only demo mode with seeded data (no auth required)

Import Pipeline

  1. Upload .xlsx export from INDmoney, Groww, Zerodha, or Motilal Oswal
  2. Parse both Equity and FNO sheets (skip metadata rows 0–5, header at row 6)
  3. Filter Order Status === "Executed" rows
  4. Group by symbol → FIFO match BUY/SELL (partial fills supported)
  5. Unmatched BUYs become OPEN trades
  6. Preview matched trades → confirm → save to DB
  7. Duplicate detection by fileName + userId

Conventions

  • All monetary values: Indian number system (₹1,23,456.78)
  • All dates: DD MMM YYYY
  • Financial Year: Apr 1 → Mar 31 (e.g. FY 2025-26)
  • Currency: INR only
  • Supports Equity and F&O, Long and Short trades

Project Structure

src/
├── actions/          # Server actions (analytics, trades, import, etc.)
├── app/
│   ├── (auth)/login/ # Login page
│   ├── (app)/        # Authenticated routes (dashboard, journal, etc.)
│   └── demo/         # Demo mode (no auth)
├── components/
│   ├── ui/           # shadcn/ui components
│   ├── layout/       # Sidebar, demo banner
│   ├── landing/      # Landing page sections (hero, features, etc.)
│   ├── dashboard/    # KPI cards, charts, filters
│   ├── journal/      # Trade table, inline editors
│   ├── import/       # File upload, preview, history
│   ├── insights/     # Advanced analytics
│   ├── calendar/     # Heatmap grid
│   └── path-to-profitability/
├── lib/
│   ├── prisma.ts     # Prisma singleton
│   ├── fifo.ts       # FIFO trade matching
│   ├── format.ts     # INR formatting, dates
│   ├── fy-utils.ts   # Financial year utilities
│   └── parsers/      # Broker-specific .xlsx parsers
├── prisma/
│   ├── schema.prisma # Database schema
│   └── seed.ts       # Demo data seeder
├── types/index.ts    # Shared TypeScript types
└── middleware.ts      # Clerk auth + route protection

About

Trading journal and analytics for Indian retail traders. Parses transaction exports, matches trades using FIFO, and provides performance analytics, insights, and journaling tools.

Resources

Stars

Watchers

Forks

Contributors