@gtcx/app-foundation
v0.1.1
Published
Shared application infrastructure — auth, RBAC, resilience, providers for GTCX products
Readme
@gtcx/app-foundation
Shared application infrastructure for GTCX products. Extracts the common auth, authorization, resilience, and provider patterns so every new product starts with production-grade infrastructure instead of copy-pasting.
What's included
| Module | Import | What it provides |
| -------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Auth | @gtcx/app-foundation/auth | RBAC authorization factory, verification token service |
| API | @gtcx/app-foundation/api | Rate limiter, security event logger, reCAPTCHA verification |
| Resilience | @gtcx/app-foundation/resilience | Connectivity detection, form draft persistence (IndexedDB), sync queue, session recovery, conflict resolution |
| Providers | @gtcx/app-foundation/providers | Service worker registration, Web Vitals reporting |
Quick Start
// Auth: create RBAC authorization
import { createAuthz } from '@gtcx/app-foundation/auth';
const { requireAuthenticatedSession, requirePermission } = createAuthz({
getSession: () => getServerSession(authOptions),
getRolePermissions: (roleId) => prisma.userRole.findUnique({ ... }),
});
// API: rate limiting
import { enforceRequestRateLimit } from '@gtcx/app-foundation/api';
const limited = enforceRequestRateLimit(req, {
scope: 'auth:signin',
limit: 10,
windowMs: 10 * 60 * 1000,
message: 'Too many attempts.',
});
// Resilience: offline-aware forms
import { useConnectivity, useFormDraft } from '@gtcx/app-foundation/resilience';
const { status, isOnline } = useConnectivity();
const { clearDraft } = useFormDraft({ formId: 'signup', watch, setValue });Base Prisma Schema
prisma/base.prisma contains the core data model (User, Role, Permission, Account, Session, VerificationToken, SecurityEvent, SystemLog, SystemSetting). Copy and extend for your product:
cp node_modules/@gtcx/app-foundation/prisma/base.prisma prisma/schema.prisma
# Add your domain models below the base