redwoodjs/graphql

RedwoodGraphQL

17,621 stars TypeScript 8 components

Provides development tools and runtime framework for building full-stack React applications with GraphQL APIs

The framework operates on multiple data flows: CLI commands parse arguments and execute generators or build processes that transform TypeScript templates into project files. During runtime, HTTP requests enter through Fastify servers, get processed through authentication middleware that parses tokens from headers, execute in async context storage that maintains request-scoped state, and return responses. Code transformations flow through jscodeshift runners that apply automated refactoring using AST manipulation.

Under the hood, the system uses 2 feedback loops, 3 data pools, 4 control points to manage its runtime behavior.

A 8-component fullstack. 2295 files analyzed. Data flows through 6 distinct pipeline stages.

How Data Flows Through the System

The framework operates on multiple data flows: CLI commands parse arguments and execute generators or build processes that transform TypeScript templates into project files. During runtime, HTTP requests enter through Fastify servers, get processed through authentication middleware that parses tokens from headers, execute in async context storage that maintains request-scoped state, and return responses. Code transformations flow through jscodeshift runners that apply automated refactoring using AST manipulation.

  1. CLI Command Processing — The CLI parser in packages/cli/src/index.js processes command arguments, loads project configuration from redwood.toml, and dispatches to specific command handlers like generate, build, or dev [Command Arguments → Command Configuration]
  2. Template Generation — CLI generators use transformTSToJS in cli-helpers to convert TypeScript templates into JavaScript using Babel, then prettify the output with project-specific Prettier configuration [TypeScript Templates → Generated Project Files]
  3. Server Initialization — createFastifyInstance loads server configuration from the project's server.config.js, creates a Fastify instance with custom logging, and registers async context middleware for request isolation [Server Configuration → FastifyInstance]
  4. Request Authentication — parseAuthorizationHeader extracts Bearer or Basic tokens from Authorization headers, while parseAuthorizationCookie handles cookie-based auth providers using the AUTH_PROVIDER_HEADER [HTTP Headers → AuthorizationHeader]
  5. Context Management — The createContextProxy creates a proxy that stores request-scoped data in AsyncLocalStorage, allowing global context access throughout the request lifecycle without explicit parameter passing [Request Context → GlobalContext]
  6. Code Transformation — runTransform executes jscodeshift transformations on source files, using specified parsers (babel, ts, tsx) to apply automated code modifications during upgrades or refactoring [Source Code Files → Transformed Code Files]

Data Models

The data structures that flow between stages — the contracts that hold the system together.

RedwoodFastifyWebOptions packages/adapters/fastify/web/src/types.ts
interface with redwood?: { apiUrl?: string, apiProxyTarget?: string, apiHost?: string }
Created during server initialization to configure API routing and proxy behavior
AuthorizationHeader packages/api/src/auth/index.ts
interface with schema: 'Bearer' | 'Basic' | string, token: string
Parsed from incoming HTTP Authorization headers and used for token-based authentication
GlobalContext packages/context/src/context.ts
Record<string, unknown> extended interface stored in AsyncLocalStorage
Created per request in async storage, populated with user data and request state, accessed throughout request lifecycle
FastifyInstance packages/api-server/src/fastify.ts
Fastify server instance with registered hooks and global context middleware
Created with configuration, enhanced with context middleware, used to handle all API requests
RunTransform packages/codemods/src/lib/runTransform.ts
interface with transformPath: string, targetPaths: string[], parser?: 'babel'|'ts'|'tsx', options?: jscodeshift options
Created to specify code transformation parameters, passed to jscodeshift runner for automated code changes

Hidden Assumptions

Things this code relies on but never validates. These are the things that cause silent failures when the system changes.

critical Environment weakly guarded

Assumes redwood.toml exists at path.join(cwd, 'redwood.toml') when cwd is set via --cwd or RWJS_CWD environment variable

If this fails: CLI crashes with 'no such file or directory' error when user specifies a directory that doesn't contain a redwood.toml file, providing no guidance on what went wrong

packages/cli/src/index.js:main
critical Environment unguarded

Assumes server.config.js file can be dynamically imported via file:// protocol and exports a default object with config and configureFastify properties

If this fails: Server startup fails with cryptic import errors if server.config.js has syntax errors, missing exports, or uses CommonJS instead of ES modules, with no validation of the structure

packages/api-server/src/fastify.ts:loadFastifyConfig
warning Shape guarded

Assumes Authorization header splits into exactly 2 parts on space character and both parts have non-zero length

If this fails: Function throws generic 'not valid' error for headers like 'Bearer token extra' or 'Bearer' without token, making debugging auth issues harder

packages/api/src/auth/index.ts:parseAuthorizationHeader
critical Domain weakly guarded

Assumes apiUrl from getConfig().web.apiUrl is always a valid URL string and never null, undefined, or malformed

If this fails: isFullyQualifiedUrl() function receives invalid input causing URL validation logic to fail silently or throw runtime errors during proxy setup

packages/adapters/fastify/web/src/resolveOptions.ts:resolveOptions
critical Contract unguarded

Assumes getAsyncStoreInstance() always returns a valid AsyncLocalStorage instance that supports the run() method

If this fails: Server crashes during request handling if context initialization fails, breaking all request isolation and potentially corrupting global state

packages/api-server/src/fastify.ts:createFastifyInstance
warning Ordering weakly guarded

Assumes server configuration loading happens before any request processing and uses module-level caching via isServerConfigLoaded flag

If this fails: Race condition during concurrent server startup could result in loading config multiple times or serving requests with incomplete configuration

packages/api-server/src/fastify.ts:loadFastifyConfig
warning Environment weakly guarded

Assumes prettier.config.js exists at project root and exports a default object, with optional tailwindConfig property being a string

If this fails: Template generation silently continues without formatting if prettier config is malformed, corrupted, or uses named exports instead of default, resulting in inconsistent code style

packages/cli-helpers/src/lib/index.ts:getPrettierOptions
warning Scale unguarded

Assumes babel.transform() can handle any TypeScript file size and complexity in memory during CLI operations

If this fails: Process runs out of memory or hangs when transforming very large generated files, especially in monorepos with complex TypeScript configurations

packages/cli-helpers/src/lib/index.ts:transformTSToJS
info Environment weakly guarded

Assumes process.env.NODE_ENV controls babel configuration discovery, with 'test' bypassing getPaths().base cwd setting

If this fails: Babel loads wrong configuration during test runs if NODE_ENV is not exactly 'test', causing template generation to fail with different syntax rules

packages/cli-helpers/src/lib/index.ts:transformTSToJS
warning Contract weakly guarded

Assumes input logData has numeric level property (10,20,30,40,50,60) mapping to standard log levels, but only checks logData.level existence

If this fails: Log formatter breaks or produces garbled output when receiving custom log levels, non-numeric levels, or levels outside the expected range

packages/api-server/src/logFormatter/index.ts:LogFormatter

System Behavior

How the system operates at runtime — where data accumulates, what loops, what waits, and what controls what.

Data Pools

AsyncLocalStorage Context (in-memory)
Request-scoped context storage maintaining currentUser and other state throughout function execution
Server Configuration Cache (cache)
Cached server configuration loaded once from server.config.js to avoid repeated file system access
Generated File System (file-store)
Project files generated from templates, cached and formatted for consistent output

Feedback Loops

Delays

Control Points

Technology Stack

Fastify (framework)
HTTP server framework providing request handling, logging, and plugin system for API functions
Babel (build)
TypeScript to JavaScript compilation for generated templates and code transformations
jscodeshift (build)
AST-based code transformations for automated refactoring and framework upgrades
AsyncLocalStorage (runtime)
Request-scoped context storage without explicit parameter passing through function chains
Yargs (library)
CLI argument parsing and command routing for the main Redwood CLI interface
Prettier (build)
Code formatting for generated templates using project-specific configuration
Listr2 (library)
Task runner with progress display for CLI operations like setup and generation

Key Components

Package Structure

adapters (library)
Server adapters for integrating Redwood with different hosting platforms like Fastify
api (library)
Core API framework providing authentication, event handling, and serverless function utilities
api-server (app)
Fastify-based server runtime for hosting API functions in development and production
auth (library)
Authentication framework providing hooks and context for user management across web and API sides
babel-config (config)
Standardized Babel configurations for transforming TypeScript and React code in web and API contexts
cli (tooling)
Primary command-line interface providing generators, build tools, dev server, and deployment commands
cli-helpers (library)
Shared utilities for CLI commands including file operations, template processing, and project configuration
codemods (tooling)
Automated code transformations using jscodeshift for framework upgrades and refactoring
context (library)
Global context management using async storage to maintain request-scoped state across function calls

Explore the interactive analysis

See the full architecture map, data flow, and code patterns visualization.

Analyze on CodeSea

Related Fullstack Repositories

Frequently Asked Questions

What is graphql used for?

Provides development tools and runtime framework for building full-stack React applications with GraphQL APIs redwoodjs/graphql is a 8-component fullstack written in TypeScript. Data flows through 6 distinct pipeline stages. The codebase contains 2295 files.

How is graphql architected?

graphql is organized into 4 architecture layers: CLI & Development Tools, Core Runtime, Build & Transform, Integration & Adapters. Data flows through 6 distinct pipeline stages. This layered structure keeps concerns separated and modules independent.

How does data flow through graphql?

Data moves through 6 stages: CLI Command Processing → Template Generation → Server Initialization → Request Authentication → Context Management → .... The framework operates on multiple data flows: CLI commands parse arguments and execute generators or build processes that transform TypeScript templates into project files. During runtime, HTTP requests enter through Fastify servers, get processed through authentication middleware that parses tokens from headers, execute in async context storage that maintains request-scoped state, and return responses. Code transformations flow through jscodeshift runners that apply automated refactoring using AST manipulation. This pipeline design reflects a complex multi-stage processing system.

What technologies does graphql use?

The core stack includes Fastify (HTTP server framework providing request handling, logging, and plugin system for API functions), Babel (TypeScript to JavaScript compilation for generated templates and code transformations), jscodeshift (AST-based code transformations for automated refactoring and framework upgrades), AsyncLocalStorage (Request-scoped context storage without explicit parameter passing through function chains), Yargs (CLI argument parsing and command routing for the main Redwood CLI interface), Prettier (Code formatting for generated templates using project-specific configuration), and 1 more. A focused set of dependencies that keeps the build manageable.

What system dynamics does graphql have?

graphql exhibits 3 data pools (AsyncLocalStorage Context, Server Configuration Cache), 2 feedback loops, 4 control points, 3 delays. The feedback loops handle retry and circuit-breaker. These runtime behaviors shape how the system responds to load, failures, and configuration changes.

What design patterns does graphql use?

5 design patterns detected: Async Context Propagation, Configuration Validation with Descriptive Errors, Dynamic Module Loading with Caching, Template-Based Code Generation, Plugin Architecture.

Analyzed on April 20, 2026 by CodeSea. Written by .