Skip to content

Teolhyn/backtester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backtester

A full-stack trading strategy backtesting platform with subscription-based access to real market data and advanced features. Built with modern web technologies and designed for scalability.

Architecture Overview

Backtester follows a microservices architecture with four primary components:

  • Frontend (Astro + React) - User interface on port 4321
  • Auth Backend (Node.js + Better Auth) - Authentication and Stripe webhooks on port 3001
  • Main Backend (Rust + Axum) - Core business logic and API on port 3000
  • Database (PostgreSQL) - User data and application state

Tech Stack

  • Frontend: Astro, React, TypeScript, Tailwind CSS
  • Authentication: Better Auth with PostgreSQL
  • Payments: Stripe (Checkout, Billing Portal, Webhooks)
  • Backend: Rust (Axum framework)
  • Database: PostgreSQL
  • Development: Stripe CLI for webhook testing

Prerequisites

Before setting up the development environment, ensure you have the following installed:

  • Node.js (v18 or higher)
  • npm (v9 or higher)
  • Rust (latest stable version)
  • PostgreSQL (v14 or higher)
  • Stripe CLI (for webhook testing)
    brew install stripe/stripe-cli/stripe

Installation

1. Clone and Install Dependencies

git clone <repository-url>
cd atlas

# Install frontend dependencies
cd frontend
npm install

# Install auth backend dependencies
cd ../auth_backend
npm install

# Install stripe server dependencies (dev only)
cd ../stripe-server
npm install

# Build Rust backend
cd ../backend
cargo build

2. Database Setup

Create a PostgreSQL database and user:

psql postgres
CREATE DATABASE devdb;
CREATE USER user WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE devdb TO user;
\q

Run database migrations:

cd auth_backend
psql postgres://user:password@localhost/devdb -f better-auth_migrations/2026-01-13T08-22-12.000Z.sql

3. Environment Variables

Create a .env file in the project root:

# Database Configuration
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=devdb
DATABASE_URL=postgres://user:password@localhost/devdb

# Better Auth Configuration
BETTER_AUTH_SECRET=<generate-a-random-secret>
BETTER_AUTH_URL=http://localhost:3001

# Stripe Configuration
STRIPE_SECRET_KEY=<your-stripe-test-key>
STRIPE_WEBHOOK_SECRET=<from-stripe-cli-or-dashboard>

Getting Stripe Keys:

Generate Better Auth Secret:

node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"

Running the Development Environment

You need to run five services simultaneously. Open separate terminal windows for each:

Terminal 1: Auth Backend

cd auth_backend
npm run dev

Server starts on http://localhost:3001

Terminal 2: Main Backend

cd backend
cargo run

Server starts on http://localhost:3000

Terminal 3: Frontend

cd frontend
npm run dev

Application available at http://localhost:4321

Terminal 4: Stripe Webhook Forwarding (Required for subscriptions)

stripe login
stripe listen --forward-to localhost:3001/api/stripe/webhook

Copy the webhook signing secret (starts with whsec_) to your .env file as STRIPE_WEBHOOK_SECRET.

Terminal 5 (Optional): Stripe Test Server

cd stripe-server
npm start

Server starts on http://localhost:4242 (used for testing checkout flows)

Project Structure

atlas/
├── frontend/              # Astro + React frontend
│   ├── src/
│   │   ├── components/   # React components
│   │   ├── lib/          # Auth client and utilities
│   │   ├── middleware.ts # Route protection
│   │   └── pages/        # Astro pages
│   └── package.json
├── auth_backend/         # Better Auth + Stripe webhooks
│   ├── src/
│   │   ├── auth.ts       # Better Auth configuration
│   │   └── index.ts      # Express server + webhook handler
│   ├── better-auth_migrations/ # Database migrations
│   └── package.json
├── backend/              # Rust/Axum main backend
│   ├── src/
│   │   ├── api/          # API endpoints
│   │   └── main.rs
│   └── Cargo.toml
├── stripe-server/        # Test Stripe server (dev only)
│   └── server.js
└── .env                  # Environment variables (not committed)

Subscription Tiers

The application supports three subscription tiers:

  • Free - Limited features with sample data
  • Basic ($9/month) - Real market data and backtesting
  • Pro (future) - Advanced features and analytics

Testing Stripe Integration

1. Create a Test Product in Stripe

Go to Stripe Dashboard → Products and create a product with:

  • Name: "Backtester Basic Test License"
  • Price: $9.00/month (recurring)
  • Lookup Key: Backtester_Basic_Test_License-a40d0ed

2. Test Checkout Flow

  1. Sign up for an account at http://localhost:4321/signup
  2. Log in at http://localhost:4321/login
  3. Navigate to http://localhost:4321/subscription
  4. Click "Checkout"
  5. Use Stripe test card: 4242 4242 4242 4242, any future expiry, any CVC
  6. Complete checkout
  7. Verify webhook updates user's subscriptionTier to basic in database

3. Verify Database Updates

psql postgres://user:password@localhost/devdb
SELECT id, email, "subscriptionTier", stripe_customer_id, stripe_subscription_status FROM "user";

4. Test Billing Portal

  1. After subscribing, click your profile avatar
  2. Select "Manage Subscription"
  3. Stripe Billing Portal should open
  4. Test canceling/updating subscription

Common Issues

Webhooks Not Working

Symptom: Subscription tier not updating after checkout

Solution: Ensure stripe listen is running and STRIPE_WEBHOOK_SECRET in .env matches the output:

stripe listen --forward-to localhost:3001/api/stripe/webhook

Copy the whsec_... secret to your .env file and restart the auth backend.

CORS Errors

Symptom: Frontend requests blocked by CORS policy

Solution: Verify all servers are running on correct ports:

  • Frontend: 4321
  • Main Backend: 3000
  • Auth Backend: 3001
  • Stripe Server: 4242

Database Connection Failed

Symptom: FATAL: password authentication failed

Solution: Verify PostgreSQL is running and credentials in .env match your database:

psql postgres://user:password@localhost/devdb

TypeScript Errors in Frontend

Symptom: Build fails with type errors

Solution: Ensure all dependencies are installed:

cd frontend
rm -rf node_modules package-lock.json
npm install

Production Deployment

Services Required in Production:

  • Auth Backend (Better Auth + Stripe webhooks)
  • Main Backend (Rust/Axum)
  • Frontend (Astro SSR or static export)

Services NOT Needed:

  • Stripe server (port 4242) - dev/test only
  • Stripe CLI webhook forwarding - use Stripe Dashboard webhooks

Production Webhook Setup:

  1. Deploy auth backend to production URL
  2. In Stripe Dashboard → Webhooks, add endpoint: https://yourdomain.com/api/stripe/webhook
  3. Select events: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted
  4. Copy production webhook secret to production environment variables
  5. Update frontend URLs to use production endpoints

Contributing

  1. Create a feature branch
  2. Make changes
  3. Test locally with all services running
  4. Submit pull request

License

[Your License Here]

About

No-code trading strategy backtesting web app with robust and fast axum backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors