Gatsby Project Structure
Inside a Gatsby project, you may see some or all of the following folders and files:
/ |-- /.cache |-- /plugins |-- /public |-- /src |-- /pages |-- /templates |-- html.js |-- /static |-- gatsby-config.js |-- gatsby-node.js |-- gatsby-ssr.js |-- gatsby-browser.js
/.cacheAutomatically generated. This folder is an internal cache created automatically by Gatsby. The files inside this folder are not meant for modification. Should be .gitignore-d.
/publicAutomatically generated. The output of
gatsby buildprocess will be exposed inside this folder. Should be .gitignore-d.
/pluginsThis folder hosts any project-specific (“local”) plugins that aren’t published as an
npmpackage. Check out the plugin docs for more detail.
/srcThis directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser), like your site header, or a page template. “Src” is a convention for “source code”.
/pagesComponents under src/pages become pages automatically with paths based on their file name. Check out the pages docs for more detail.
/templatesBy convention, templates used across multiple pages are Contains templates for programmatically creating pages. Check out the templates docs for more detail.
html.jsFor custom configuration of default .cache/default_html.js. Check out the custom html docs for more detail.
/staticIf you put a file into the static folder, it will not be processed by Webpack. Instead it will be copied into the public folder untouched. Check out the assets docs for more detail.
gatsby-browser.js: This file is where Gatsby expects to find any usage of the Gatsby browser APIs (if any). These allow customization/extension of default Gatsby settings affecting the browser.
gatsby-config.js: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. Check out the config docs for more detail.
gatsby-node.js: This file is where Gatsby expects to find any usage of the Gatsby node APIs (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.
gatsby-ssr.js: This file is where Gatsby expects to find any usage of the Gatsby server-side rendering APIs (if any). These allow customization of default Gatsby settings affecting server-side rendering.
The file/folder structure described above reflects Gatsby-specific files and folders. Since Gatsby sites are also React apps, it’s common to use standard React code organization patterns such as folders like
/src. The React docs have more information on a typical React app folder structure.