• TypeScript 95.1%
  • SCSS 4.5%
  • CSS 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
chris-kreidl 80ed09bd77
Merge pull request #64 from chris-kreidl/chore/dependency-upgrades
Upgrade dependencies: Vitest 5, kysely 0.29, Sentry 11, recharts 3, TanStack Table 9 and more
2026-10-24 23:18:37 -04:00
.githooks fix: adds missing test:run script as noop 2026-01-24 13:14:26 -05:00
.github/instructions Remove unused nitro-v2 plugin and happy-dom, upgrade oxfmt 2026-10-24 22:06:33 -04:00
.idea webstorm settings 2025-07-19 01:30:45 -04:00
.vscode Reapply "chore: update prisma to v7." 2026-01-17 19:48:33 -05:00
apps Upgrade remaining web app majors 2026-10-24 23:09:47 -04:00
docs Validate guildId as numeric string before BigInt conversion 2026-03-11 03:05:11 +00:00
packages Upgrade kysely to 0.29 and kysely-codegen to 0.20 2026-10-24 22:53:22 -04:00
.dockerignore fix docker issues 2026-01-24 23:29:16 -05:00
.env.example Replace hardcoded optimizer authorization IDs with env-driven config 2026-08-08 09:21:58 -04:00
.gitignore feat(obs): add postgres and pgbouncer monitoring 2026-01-27 09:02:14 -05:00
.gitlab-ci.yml chore: scaffold monorepo with Bun workspaces 2026-01-24 00:33:47 -05:00
.oxfmtrc.json fix: block scss parser from looking at anything -- throws a fit on tailwind's @imports 2026-01-24 12:54:14 -05:00
.oxlintrc.json feat(armory): enable armory module config 2026-01-27 22:15:30 -05:00
.prettierignore fix deploy issues 2026-01-18 15:46:04 -05:00
bun.lock Upgrade remaining web app majors 2026-10-24 23:09:47 -04:00
CLAUDE.md Remove unused nitro-v2 plugin and happy-dom, upgrade oxfmt 2026-10-24 22:06:33 -04:00
package.json Upgrade inngest to 4.x and override zod to 4.6.7 2026-10-24 22:11:56 -04:00
README.md feat(armory): add inventory monitoring and configuration features 2026-01-27 21:36:56 -05:00
renovate.json chore: format 2025-12-27 22:46:25 -05:00
tsconfig.base.json feat: extract services to packages/torn-services (Phase 3) 2026-01-24 09:08:07 -05:00

TanStack Torn

A modern web application for Torn City utilities and tools, built with TanStack Start.

Features

  • Gym Tracker - Track training progress and optimize gym efficiency
  • Chain Watch Scheduler - Coordinate faction chain watching with time slot reservations
  • Company Optimizer - Optimize company job efficiency
  • Ranked War Dashboard - View and analyze ranked war statistics
  • Booster Calculator - Calculate booster effectiveness
  • Shopping Tools - Item shopping and price tracking

Tech Stack

Prerequisites

  • Bun 1.0+ (includes Node.js runtime)
  • PostgreSQL database
  • Torn City API Key (for testing/development)

Background Services

This repo also includes two long-running services used in production:

  • Worker (apps/worker): data ingestion + background polling, writes to the outbox table.
  • Bot (apps/bot): Discord delivery + slash commands, consumes the outbox.

See docs/DEPLOY_WORKER.md for deployment details.

Getting Started

1. Clone and Install

git clone <repository-url>
cd tanstack-torn
bun install

2. Configure Environment

Copy the example environment file and fill in your values:

cp .env.example .env

Edit .env with your credentials:

# PostgreSQL connection string (Neon or other provider)
DATABASE_URL=postgres://user:password@host:5432/dbname

# Generate a secure random string for session encryption
SESSION_PASSWORD=your-secure-random-password

# Comma-separated Torn user IDs with admin access
ADMIN_USER_IDS=123456

# Comma-separated faction IDs allowed to use the app
ALLOWABLE_FACTION_IDS=12345

# Vercel Blob read/write token for wiki uploads
BLOB_READ_WRITE_TOKEN=your-vercel-blob-read-write-token

3. Setup Database

# Run Kysely migrations
bun run db:migrate

# Generate Kysely types from the database
bun run db:generate-types

4. Run Development Server

bun dev

Open http://localhost:4000 in your browser.

Development

Project Structure

src/
├── routes/              # File-based routes
│   ├── __root.tsx       # Root layout (sidebar, header, auth)
│   ├── _authed.tsx      # Protected route wrapper
│   ├── _authed/         # Protected feature routes
│   │   ├── gym/         # Gym tracking
│   │   ├── chain/       # Chain watch
│   │   ├── company/     # Company optimizer
│   │   ├── rankedwar/   # Ranked war stats
│   │   └── schedule/    # Chain watch scheduler
│   ├── (auth)/          # Login/logout
│   └── api/             # API endpoints
├── components/
│   ├── ui/              # shadcn/ui components
│   └── *.tsx            # Custom components
├── lib/
│   ├── torn/            # Torn API integration
│   ├── security/        # Security utilities
│   ├── validation/      # Valibot schemas
│   ├── session.ts       # Session management
│   └── db/              # Kysely client + types
├── hooks/               # React hooks
└── styles/              # Global CSS

See CLAUDE.md for detailed architecture documentation.

Key Commands

# Development
bun dev                 # Start dev server (port 4000)

# Build
bun run build           # Build for production
bun start               # Start production server

# Testing
bun test                # Run tests in watch mode
bun test:run            # Run tests once
bun test:coverage       # Run tests with coverage

# Database
bun run db:migrate      # Run Kysely migrations
bun run db:generate-types # Generate Kysely types

# Code Quality
bun lint                # Run oxlint with type-aware checking
bun format              # Format code with oxfmt
bun format:check        # Check code formatting
bun typecheck           # Run TypeScript type checking

Authentication

Users authenticate with their Torn City API key:

  1. Navigate to login page
  2. Enter Torn API key (limited access or higher)
  3. Key is validated against Torn API
  4. User data (ID, faction, company) stored in encrypted session
  5. API key stored in session for subsequent Torn API calls

Access is restricted by:

  • Faction membership: User's faction must be in ALLOWABLE_FACTION_IDS
  • Admin access: Admin features require user ID in ADMIN_USER_IDS

Creating New Routes

TanStack Router uses file-based routing:

// src/routes/_authed/myfeature/index.tsx
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/_authed/myfeature/")({
  component: MyFeature,
});

function MyFeature() {
  const { user } = Route.useRouteContext();
  return <div>Hello {user.userId}!</div>;
}

Protected routes under _authed/ automatically require authentication.

Creating API Endpoints

// src/routes/api/myendpoint.ts
import { createFileRoute } from "@tanstack/react-router";
import { json } from "@tanstack/react-start";

export const Route = createFileRoute("/api/myendpoint")({
  server: {
    handlers: {
      POST: async ({ request }) => {
        const body = await request.json();
        // Process request
        return Response.json({ success: true });
      },
    },
  },
});

Working with the Database

import { db } from "@/lib/db";

// Query data
const slots = await db
  .selectFrom("time_slots")
  .selectAll()
  .where("is_available", "=", true)
  .execute();

// Create data
const reservation = await db
  .insertInto("reservations")
  .values({
    user_id: user.id,
    time_slot_id: slotId,
    notes: "Available for chain",
  })
  .returningAll()
  .executeTakeFirstOrThrow();

Calling Torn API

import { tornFetch } from "@nuxx/torn-fetch";

// In server functions or API routes
const profile = await tornFetch(apiKey, "/user/basic");
const faction = await tornFetch(apiKey, "/faction/basic");

Deployment

Environment Variables

Ensure these are set in your production environment:

  • DATABASE_URL - PostgreSQL connection string (Neon or other provider)
  • SESSION_PASSWORD - Secure random string for session encryption
  • ADMIN_USER_IDS - Admin user IDs
  • ALLOWABLE_FACTION_IDS - Allowed faction IDs
  • NODE_ENV=production - Enables production optimizations

Build and Deploy

# Build the application
bun run build

# Start production server
bun start

The built application is in .output/ directory.

Troubleshooting

Database Connection Issues

  • Verify DATABASE_URL is correct
  • Check network connectivity to database

Torn API Errors

  • Verify API key has sufficient access level (limited or higher)
  • Check if API key is still valid (not revoked/expired)
  • Ensure rate limits aren't exceeded

Build Failures

  • Run bun run db:generate-types when schema changes
  • Clear .output/, .nitro/, .tanstack/ directories and rebuild
  • Verify all dependencies are installed: bun install

Contributing

  1. Create a feature branch from main
  2. Make your changes
  3. Run tests: bun test:run
  4. Ensure linting passes: bun lint
  5. Check types: bun typecheck
  6. Format code: bun format
  7. Submit a pull request

License

[Your License Here]