Phase 1: Monorepo scaffold, database, and dev environment

Turborepo monorepo with @forte/shared and @forte/backend workspaces.
Docker Compose dev env with PostgreSQL 16 + Valkey 8.
Fastify server with Pino JSON logging, request ID tracing, and
health endpoint. Drizzle ORM with company + location tables.

Includes:
- Root config (turbo, tsconfig, eslint, prettier)
- @forte/shared: types, schemas, currency/date utils
- @forte/backend: Fastify entry, plugins (database, redis, cors,
  error-handler, dev-auth), health route, Drizzle schema + migration
- Dev auth bypass via X-Dev-Company/Location/User headers
- Vitest integration test with clean DB per test (forte_test)
- Seed script for dev company + location
This commit is contained in:
Ryan Moon
2026-03-27 14:51:46 -05:00
parent 5f8726ee4e
commit c1cddd6b74
37 changed files with 1700 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/**
* Format a number as USD currency string.
*/
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
}).format(amount)
}
/**
* Round to 2 decimal places using banker's rounding (round half to even).
*/
export function roundCurrency(amount: number): number {
return Math.round((amount + Number.EPSILON) * 100) / 100
}
/**
* Convert dollars to cents (integer) for safe arithmetic.
*/
export function toCents(dollars: number): number {
return Math.round(dollars * 100)
}
/**
* Convert cents (integer) back to dollars.
*/
export function toDollars(cents: number): number {
return cents / 100
}

View File

@@ -0,0 +1,27 @@
/**
* Cap a billing anchor day to 28 (avoids issues with Feb and short months).
*/
export function capBillingDay(day: number): number {
return Math.min(Math.max(1, Math.floor(day)), 28)
}
/**
* Get today's date as YYYY-MM-DD string.
*/
export function todayISO(): string {
return new Date().toISOString().split('T')[0]
}
/**
* Check if a date of birth makes someone a minor (under 18).
*/
export function isMinor(dateOfBirth: Date | string): boolean {
const dob = typeof dateOfBirth === 'string' ? new Date(dateOfBirth) : dateOfBirth
const today = new Date()
const age = today.getFullYear() - dob.getFullYear()
const monthDiff = today.getMonth() - dob.getMonth()
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < dob.getDate())) {
return age - 1 < 18
}
return age < 18
}

View File

@@ -0,0 +1,2 @@
export { formatCurrency, roundCurrency, toCents, toDollars } from './currency.js'
export { capBillingDay, todayISO, isMinor } from './dates.js'