Skip to content

File Organization Patterns

This reference documents the file organization patterns used throughout the codebase, including glob patterns for locating specific file types.

src/pages/
├── {routeName}/
│ ├── index.astro # Page component
│ ├── _graphql/ # Page-specific GraphQL (underscore prefix hides from routing)
│ │ ├── page.query.graphql # Main page query
│ │ ├── api.ts # API functions
│ │ └── transform.ts # Data transformations
│ ├── _components/ # Page-specific components (underscore prefix)
│ │ └── feature/
│ │ ├── Feature.astro
│ │ └── Feature.tsx
│ └── [...slug].astro # Dynamic route segment
src/components/
├── feature/
│ ├── index.ts # Exports
│ ├── feature.tsx # Component implementation
│ ├── feature.test.ts # Component tests
│ ├── graphql/ # Component-specific GraphQL
│ │ ├── query.graphql
│ │ ├── api.ts
│ │ └── transform.ts
│ └── utils.ts # Feature utilities
src/graphql/
├── fragments/ # Shared fragments
│ ├── imageProps.fragment.graphql
│ └── articleListItem.fragment.graphql
├── generated/ # Auto-generated types
│ └── contentful/
│ └── schema.ts
└── codegen.ts # Codegen configuration
PatternDescriptionExample
*.query.graphqlQuery operationspage.query.graphql
*.mutation.graphqlMutation operationssubmit.mutation.graphql
*.fragment.graphqlReusable fragmentsimageProps.fragment.graphql
*.cms.graphqlContentful queries (for codegen)pageQuery.cms.graphql
*.api.graphqlAPI queries (internal)validate.api.graphql
PatternDescriptionExample
api.tsAPI functionsapi.ts
transform.tsData transformationstransform.ts
transform.types.tsTransform type definitionstransform.types.ts
utils.tsUtility functionsutils.ts
*.test.tsTest filesfeature.test.ts
PatternDescriptionExample
{name}.tsxSolidJS componentnewsletterForm.tsx
{name}.astroAstro componentPageHeader.astro
index.tsModule exportsindex.ts
PrefixPurposeExample
_ (underscore)Hidden from Astro routing_graphql/, _components/
NoneStandard feature/component directoriescomponents/header/
PatternDescriptionExample
{name}Static routearticles/
[param]Dynamic route segment[slug]/
[...slug]Rest parameters[...slug].astro

Rule: Page-specific files must be in a directory with an underscore prefix to prevent Astro from creating routes for them.

✅ src/pages/articles/_graphql/api.ts
✅ src/pages/articles/_components/related.tsx
❌ src/pages/articles/graphql/api.ts # Wrong: creates /articles/graphql route
❌ src/pages/articles/components/related.tsx # Wrong: creates /articles/components route

Rule: Component GraphQL files can use either graphql/ or _graphql/ depending on context:

✅ src/components/header/graphql/query.graphql # Shared component
✅ src/pages/articles/_components/hero/graphql/ # Page component

Rule: Shared GraphQL fragments must be in src/graphql/fragments/:

✅ src/graphql/fragments/imageProps.fragment.graphql
❌ src/components/image/fragments/imageProps.fragment.graphql

Use TypeScript path aliases for cleaner imports:

// ✅ Using path aliases
import { graphqlApi } from "#graphql/graphqlClient";
import type { Article } from "#types/content";
import FRAGMENT from "#graphql/fragments/image.fragment.graphql";
// ❌ Relative paths
import { graphqlApi } from "../../../graphql/graphqlClient";
import type { Article } from "../../../types/content";