Skip to main content
Refract is a layered TypeScript monorepo. Each layer has a single responsibility and communicates with the next through explicit typed contracts — so AI agents and human developers always know where a change belongs.

The layers

LayerLocationResponsibility
Frontendapps/frontend/src/React SPA — pages, components, Redux, Apollo Client
GraphQL resolversapps/backend/src/gql/Thin HTTP boundary — receive input, call utilities, return output
Utilitiesapps/backend/src/utilities/Business logic — pure functions, no direct HTTP or SDK calls
Toolsapps/backend/src/tools/External service adapters — database, cache, queue, mailer, etc.
Configurationapps/backend/src/configuration/One typed ConfigType per environment — no scattered process.env
Sharedapps/shared/src/Contracts, Zod schemas, and types shared between backend and tool packages
Tool packagesapps/tools/<tool>/<impl>/Pluggable vendor implementations (pino, BullMQ, StatsD, etc.)

Key principles

Resolvers are thin. A GraphQL resolver receives input, calls a utility function, and returns a result. It never contains business logic, never calls the database directly, and never imports a vendor SDK. Tools are injected, not imported. Every resolver and utility receives a tools object. No part of the codebase imports pino, Stripe, or redis directly — it only calls tools.logger, tools.paymentProcessor, tools.cache. Configuration resolves once. process.env is read exactly once, in apps/backend/src/configuration/<env>.ts. Everything downstream receives a typed, validated ConfigType. Implementations are swappable. Every external dependency — logger, queue, metrics, mailer, analytics — is pluggable. Change the client value in config and the loader dynamically imports the right package. Nothing else changes.

Architecture deep dives

TopicWhere to go
Authentication and sessionsAuthentication
Role-based access control and scopesRBAC
Billing, Stripe, and webhooksBilling
Pluggable tools and the loader patternTooling system
ConfigType, env vars, and provider swappingConfiguration system

What’s next?

Start with whichever system you’re about to touch:
  • Authentication — sessions, Passport, email verification, OAuth
  • RBAC — roles, scopes, and how feature access is gated
  • Billing — Stripe subscriptions, webhooks, checkout, downgrades
  • Tooling system — how pluggable tools are loaded and swapped