Case Study // SaaS / Full-Stack Engineering

ClearPeak Trading

Trading Analytics SaaS Platform

Role / OwnershipFull-Stack Engineer (Personal Project)
Timeline2024
StatusLive Production SaaS
Architecture ScopeSaaS
ClearPeak Trading

01 // System Overview

What The System Does

ClearPeak Trading is a subscription-based financial analytics SaaS offering proprietary performance indicators, automated trade journaling, and paid access to analytical tools. Built for scalability, data isolation, and smooth monetization, ClearPeak provides traders with actionable metrics while ensuring secure subscriber authentication.

A high-performance SaaS web application built with Next.js, Auth.js, Prisma ORM, PostgreSQL, Stripe Subscriptions with idempotent webhook processing, and Brevo transactional emails.

02 // Architecture & Data Flow

End-to-End System Design

Trader Browser / Client
          │
          ▼ HTTPS
┌───────────────────────────────────────────────┐
│     Next.js Application (App Router)          │
│     ├── Auth.js (Protected Routes & Sessions) │
│     └── Server Actions & Analytics APIs       │
└───────┬───────────────────────────┬───────────┘
        │                           │
        ▼ Prisma Client             ▼ REST API
┌──────────────────────────┐ ┌───────────────────────────┐
│   PostgreSQL Database    │ │   Stripe Billing Engine   │
│   (Neon Serverless)      │ │   (Checkout & Subscriptions)
│   • Users & Sessions     │ └─────────────┬─────────────┘
│   • Subscriptions & Logs │               │ Webhooks
│   • Trade Journals       │               ▼ (HMAC Verified)
└──────────────────────────┘ ┌───────────────────────────┐
                             │ Next.js Webhook Handler   │
                             │ (State Sync & Entitlement)│
                             └─────────────┬─────────────┘
                                           │
                                           ▼ REST
                             ┌───────────────────────────┐
                             │ Brevo Email API           │
                             └───────────────────────────┘

03 // Engineering Ownership

What I Personally Built

Built the entire SaaS application from scratch using Next.js (App Router) and TypeScript.
Implemented authentication and access control workflows using Auth.js (OAuth and credentials sessions).
Modeled relational database schemas, migrations, and transactional queries using Prisma and PostgreSQL (Neon).
Integrated Stripe billing, supporting recurring plans, monthly/annual toggles, and customer portal session redirection.
Engineered idempotent Stripe webhook handling to maintain subscriber entitlement state across billing events.
Implemented comprehensive lifecycle event listeners for subscription creation, trials, invoice payment, and cancellations.
Integrated Brevo API to trigger transactional welcome emails, billing receipts, and plan change notifications.

04 // Technical Problems Solved

Engineering Challenges & Solutions

Challenge 01

Guaranteeing idempotent webhook processing when Stripe retries deliveries during transient network delays.

Engineering Solution

Created an EventLog table in PostgreSQL to record each incoming Stripe event ID inside a database transaction, rejecting already-processed events before modifying user entitlement records.

Challenge 02

Protecting proprietary trading indicator calculations from unauthorized client extraction.

Engineering Solution

Kept all core mathematical calculations on the server inside isolated serverless API endpoints protected by session and subscription guard middleware.

Challenge 03

Database connection limits under serverless Next.js edge and lambda function scaling.

Engineering Solution

Configured Prisma with Neon serverless connection pooling (pgBouncer), preventing connection pool exhaustion under sudden traffic bursts.

05 // Trade-offs

Key Architectural Decisions

  • Selected PostgreSQL with Prisma for type-safe database schemas and predictable schema migrations.
  • Chose Stripe Customer Portal to offload credit card updates, invoicing, and tax handling directly to Stripe's secure infrastructure.
  • Utilized Brevo API for transactional email delivery decoupled from web server execution.

Technologies Used

Next.jsTypeScriptAuth.jsPrismaPostgreSQLStripeBrevoTailwind CSSVercel

Explore Other Work

Next Case Study

Instasew

Fashion Marketplace Platform & Backend Architecture

Read Next