No description
https://torntargets.vercel.app
- TypeScript 95.1%
- SCSS 4.5%
- CSS 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Upgrade dependencies: Vitest 5, kysely 0.29, Sentry 11, recharts 3, TanStack Table 9 and more |
||
| .githooks | ||
| .github/instructions | ||
| .idea | ||
| .vscode | ||
| apps | ||
| docs | ||
| packages | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| .oxfmtrc.json | ||
| .oxlintrc.json | ||
| .prettierignore | ||
| bun.lock | ||
| CLAUDE.md | ||
| package.json | ||
| README.md | ||
| renovate.json | ||
| tsconfig.base.json | ||
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
- Framework: TanStack Start - Full-stack React framework with SSR
- Router: TanStack Router - Type-safe file-based routing
- UI: React 19 + Radix UI + shadcn/ui
- Styling: Tailwind CSS v4
- Database: PostgreSQL + Kysely
- Server: Nitro V2
- Validation: Valibot
- Build: Vite
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:
- Navigate to login page
- Enter Torn API key (limited access or higher)
- Key is validated against Torn API
- User data (ID, faction, company) stored in encrypted session
- 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 encryptionADMIN_USER_IDS- Admin user IDsALLOWABLE_FACTION_IDS- Allowed faction IDsNODE_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_URLis 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-typeswhen schema changes - Clear
.output/,.nitro/,.tanstack/directories and rebuild - Verify all dependencies are installed:
bun install
Contributing
- Create a feature branch from
main - Make your changes
- Run tests:
bun test:run - Ensure linting passes:
bun lint - Check types:
bun typecheck - Format code:
bun format - Submit a pull request
License
[Your License Here]