Skip to content

Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay

License

Notifications You must be signed in to change notification settings

kriasoft/react-firebase-starter

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e9fa473 Β· Jul 26, 2021
Jul 8, 2019
Aug 20, 2020
Sep 4, 2019
Mar 17, 2019
Feb 25, 2018
Nov 26, 2019
May 12, 2018
Dec 28, 2019
Nov 26, 2019
Sep 7, 2018
Feb 27, 2018
Mar 16, 2019
Jun 5, 2021
Mar 13, 2019
Jul 19, 2019
Aug 7, 2017
Aug 31, 2019
May 12, 2018
Dec 16, 2017
Aug 7, 2017
Jun 4, 2021
Jul 19, 2019
Nov 26, 2019
Jul 26, 2021
Sep 4, 2019
Dec 16, 2017
Jul 26, 2021

Repository files navigation

React Starter Kit for Firebase   a.k.a. Serverless Edition
Build Status Dependabot Twitter

React Starter Kit for Firebase is a popular project template (aka, boilerplate) for building modern, scalable web applications with React, Relay, and GraphQL using serverless infrastructure provided by Google Cloud (Cloud SQL, Cloud Functions, CDN hosting, and file storage). It allows you to save time and build upon a solid foundation and design patterns.

View online demo (API, data model)  |  Follow us on Twitter  |  Get FREE support on Discord  |  We're hiring!

    


This project was bootstrapped with React Starter Kit for Firebase by Kriasoft.

Tech Stack

Also, you need to be familiar with HTML, CSS, JavaScript (ES2015) and React.

Directory Layout

β”œβ”€β”€ build/                         # Compiled output
β”œβ”€β”€ migrations/                    # Database schema migration files
β”œβ”€β”€ node_modules/                  # 3rd-party libraries and utilities
β”œβ”€β”€ public/                        # Static files such as favicon.ico etc.
β”œβ”€β”€ scripts/                       # Automation scripts (yarn update-schema etc.)
β”œβ”€β”€ src/                           # Application source code
β”‚   β”œβ”€β”€ admin/                     # Admin section (Dashboard, User Management etc.)
β”‚   β”œβ”€β”€ common/                    # Shared React components and HOCs
β”‚   β”œβ”€β”€ hooks/                     # React.js hooks and Context providers
β”‚   β”œβ”€β”€ icons/                     # Icon components
β”‚   β”œβ”€β”€ legal/                     # Terms of Use, Privacy Policy, etc.
β”‚   β”œβ”€β”€ misc/                      # Other pages (about us, contacts, etc.)
β”‚   β”œβ”€β”€ mutations/                 # GraphQL mutations to be used on the client
β”‚   β”œβ”€β”€ news/                      # News section (example)
β”‚   β”œβ”€β”€ server/                    # Server-side code (API, authentication, etc.)
β”‚   β”‚   β”œβ”€β”€ mutations/             # GraphQL mutations
β”‚   β”‚   β”œβ”€β”€ queries/               # The top-level GraphQL query fields
β”‚   β”‚   β”œβ”€β”€ templates/             # HTML templates for server-side rendering
β”‚   β”‚   β”œβ”€β”€ types/                 # GraphQL types: User, UserRole, UserIdentity etc.
β”‚   β”‚   β”œβ”€β”€ api.js                 # GraphQL API middleware
β”‚   β”‚   β”œβ”€β”€ app.js                 # Express.js application
β”‚   β”‚   β”œβ”€β”€ config.js              # Configuration settings to be passed to the client
β”‚   β”‚   β”œβ”€β”€ context.js             # GraphQL context wrapper
β”‚   β”‚   β”œβ”€β”€ db.js                  # PostgreSQL database client (Knex.js)
β”‚   β”‚   β”œβ”€β”€ relay.js               # Relay factory method for Node.js environment
β”‚   β”‚   β”œβ”€β”€ index.js               # Node.js app entry point
β”‚   β”‚   β”œβ”€β”€ login.js               # Authentication middleware (e.g. /login/facebook)
β”‚   β”‚   β”œβ”€β”€ schema.js              # GraphQL schema
β”‚   β”‚   └── ssr.js                 # Server-side rendering, e.g. ReactDOMServer.renderToString(<App />)
β”‚   β”œβ”€β”€ user/                      # User pages (login, account settings, user profile, etc)
β”‚   β”œβ”€β”€ utils/                     # Utility functions
β”‚   β”œβ”€β”€ relay.js                   # Relay factory method for browser environment
β”‚   β”œβ”€β”€ index.js                   # Client-side entry point, e.g. ReactDOM.render(<App />, container)
β”‚   β”œβ”€β”€ router.js                  # Universal application router
β”‚   β”œβ”€β”€ serviceWorker.js           # Service worker helper methods
β”‚   └── theme.js                   # Overrides for Material UI default styles
β”œβ”€β”€ ssl/                           # SSL certificates for connecting to Cloud SQL instance
β”œβ”€β”€ .env                           # Environment variables for local development
β”œβ”€β”€ .env.production                # Environment variables for the production build
β”œβ”€β”€ .env.test                      # Environment variables for the test build
β”œβ”€β”€ graphql.schema                 # GraphQL schema (auto-generated, used by Relay)
└── package.json                   # The list of project dependencies + NPM scripts

Prerequisites

Getting Started

Just clone the repo, update environment variables in .env and/or .env.local file, and start hacking:

$ git clone https://github.com/kriasoft/react-firebase-starter.git MyApp
$ cd MyApp
$ yarn setup                       # Installs dependencies; creates PostgreSQL database
$ yarn start                       # Compile the app and opens it in a browser with "live reload"

Then open http://localhost:3000/ to see your app.

npm start

In order to re-compile GraphQL fragments, run yarn relay or yarn relay --watch (in watch mode).

How to Migrate Database Schema

While the app is in development, you can use a simplified migration workflow by creating a backup of your existing database, making changes to the existing migration file (see migrations/20180101000000_initial.js), re-apply the migration and restore data from the backup file (backup.sql):

$ yarn db-backup --env=dev         # Or, yarn db-backup --env=test
$ yarn db-reset-dev                # Or, yarn db-reset-test

Upon deployment to production, switch to normal migration workflow:

$ yarn db-change <name>            # Create a new database migration file
$ yarn db-migrate --env=dev        # Migrate database to the latest version

HINT: Test your migration thoroughly with a local instance of the DB first (by using --env=local or --env=dev (default) flag) then apply it to your test or prod database instance using --env=test or --env=prod command argument.

Other helpful database scripts:

$ yarn db-version --env=dev        # Print the version number of the last migration
$ yarn db-rollback --env=dev       # Rollback the latest migration
$ yarn db-restore --env=dev        # Restore database from backup.sql
$ yarn db-seed --env=dev           # Seed database with test data
$ yarn db --env=dev                # Open Knex.js REPL shell (type ".exit" for exit)
$ yarn psql --env=dev              # Open PostgreSQL shell (type "\q" for exit)

How to Test

$ yarn lint                        # Check JavaScript and CSS code for potential issues
$ yarn lint-fix                    # Attempt to automatically fix ESLint warnings
$ yarn test                        # Run unit tests. Or, `yarn test -- --watch`

How to Deploy

$ yarn build                       # Build the in production mode (NODE_ENV=production)
$ yarn deploy-test                 # Deploy the app to TEST environment
$ yarn deploy-prod                 # Deploy the app to PROD environment

For more information refer to the Deployment guide in the project's Wiki.

How to Update

If you keep the original Git history after cloning this repo, you can always fetch and merge the recent updates back into your project by running:

$ git remote add rsk https://github.com/kriasoft/react-firebase-starter.git
$ git checkout master
$ git fetch rsk
$ git merge rsk/master
$ yarn install

NOTE: Try to merge as soon as the new changes land on the master branch in the upstream repository, otherwise your project may differ too much from the base/upstream repo. Alternatively, you can use a folder diff tool like Beyond Compare for keeping your project up to date with the base repository.

Backers

              

How to Contribute

Anyone and everyone is welcome to contribute to this project. The best way to start is by checking our open issues, submit a new issues or feature request, participate in discussions, upvote or downvote the issues you like or dislike, send pull requests.

Learn React.js and ES6

πŸŽ“   React for Beginners and ES6 Training Course by Wes Bos
πŸ“—   React: Up & Running: Building Web Applications by Stoyan Stefanov (Aug, 2016)
πŸ“—   Getting Started with React by Doel Sengupta and Manu Singhal (Apr, 2016)
πŸ“—   You Don't Know JS: ES6 & Beyond by Kyle Simpson (Dec, 2015)

Related Projects

  • React App SDK β€” Create React App modification that unlocks server-side rendering
  • React Starter Kit β€” Boilerplate and tooling for building isomorphic web apps with React and Relay
  • Node.js API Starter Kit β€” Boilerplate and tooling for building data APIs with Docker, Node.js and GraphQL

License

Copyright Β© 2015-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE.txt file.


Made with β™₯ by Konstantin Tarkus (@koistya, blog) and contributors πŸ‘‹ Get in touch!