How mnsrulz/mytradingview works
Project Type and Purpose
• Type: Full-stack serverless web application built on Next.js (App Router)
• Purpose: Provide in-depth stock options analytics (profit views, Greeks, hedging, screener) with real-time and historical data via external APIs and a PostgreSQL database.
Main Components
A. Client (Browser/UI)
– Next.js frontend (src/app pages + React components)
– SSR/SSG/Client-side navigation, CSS (globals.css), theming (theme.ts)
– Interactive charts, dialogs, data tables (components/*)
B. Next.js Server/API Layer
– API Routes (src/app/api/*) implemented as serverless functions
• auth: NextAuth handlers for login/ session
• contact, schedules (cron-style endpoints), symbols, trades, watchlist, timesales
– Middleware (src/middleware.ts) for auth, request logging
– Socket service (src/lib/socket.ts) for real-time updates
C. Business Logic & Services (src/lib)
– prisma.ts: Prisma Client for PostgreSQL
– dataService, mzDataService: DB abstractions
– tradierService, cboeService, stockService: External market data APIs
– optionPriceHelper, dgHedgingHelper: domain calculations
– logger, utils, formatters, hooks
D. Database
– PostgreSQL (managed via Prisma ORM, schema.prisma + migrations)
E. External Services
– Tradier Brokerage API
– CBOE delayed quotes (scraping or REST)
– (Potential) WebSocket or SSE providers for live tick data
F. Infrastructure & CI/CD
– Devcontainer for local dev
– GitHub Actions (sync-branch, dependabot)
– Netlify for staging/production deployment
– Environment variables (.env.local_SAMPLE)
Relationships & Data Flows
• Browser → Next.js Frontend → SSR (page.tsx) or Client API calls (/app/api/…)
• API Route Handler →
– Prisma Client → PostgreSQL
– External Service Clients (Tradier/CBOE) → fetch market data
– Business-logic helpers → compute Greeks, exposures, returns
• API Response → Frontend → Render visualizations
• NextAuth Middleware → Protect routes, manage sessions
• Socket Service → Push live updates from server to client
• Scheduler Endpoint → Triggered by external cron (Netlify functions) to update open trades’ last contract price
Architectural Patterns & Principles
• Monolithic serverless functions (Next.js API routes)
• Separation of concerns:
– UI components vs. page routes vs. API handlers vs. business logic libs
• Domain-driven modules: Each feature (symbols, trades, watchlist) has its own route folder
• Infrastructure as code: Prisma migrations, devcontainer, CI pipelines
• Responsive design + progressive enhancement (SSR + CSR)
Final Checklist
– Each component labeled (UI, API route, lib service, DB, external API)
– Notes on update frequencies for scheduled jobs
– Authentication boundary via NextAuth