NOTICE: This repository is in active development. We encourage usage and pull requests, but please be advised that it is changing fast!
Checkout our website for documentation and examples.
This project was initially inspired by the Scalable React Boilerplate. It inherits the Feature-First organizational pattern.
The main feature of this project is that it uses TypeScript as its main language. The reasons to use static types for front-end engineering are plentiful, but if you need more convincing, check the resources section below.
-
Clone the Repo
git clone https://github.com/RyanCCollins/scalable-react-ts-boilerplate
-
Install Dependencies From the root of the project directory, run
yarn
if you have yarn installed globally. --- or ---npm install
. -
Start the Development Server Run
npm run start
then browse http://localhost:1337 to see your running app.
In most projects and frameworks, files are organized in a File type first fashion. For example, your tests exist in a test folder, your styles in a styles folder. This boilerplate takes a different approach.
We encourage encapsulation of features by asking that you organize each feature into the same folder. With React, this means that your containers and components exist in their own folders, along with literally every other file that pertains to that one feature. In other words, your actions, reducers, tests, styles, types and everything else are all internal to the feature they represent. By decoupling your features from the rest of your app, you set yourself up to reuse your UI components in future projects. You can thank us later!
Give it a try! We promise you will enjoy it.
We recently migrated to a multi-package approach using Lerna. More info coming soon!
This project embraces styled-components as it's a fantastic way to style your React components.
Check the components directory for examples.
This boilerplate contains setup to quickly get started with a full stack application. Within the src/
directory, you will find a server and a client folder.
src/client
├── apolloClient.ts
├── components
│ ├── Box
│ │ ├── __tests__
│ │ │ ├── __mocks__
│ │ │ │ └── boxMocks.mock.ts
│ │ │ ├── __snapshots__
│ │ │ │ └── index.test.tsx.snap
│ │ │ └── index.test.tsx
│ │ ├── index.tsx
│ │ ├── maps.ts
│ │ ├── styleUtils.ts
│ │ ├── styles.ts
│ │ └── types.ts
│ ├── Section
│ │ ├── __tests__
│ │ │ ├── __mocks__
│ │ │ │ └── sectionMocks.mock.ts
│ │ │ ├── __snapshots__
│ │ │ │ └── index.test.tsx.snap
│ │ │ └── index.test.tsx
│ │ ├── index.tsx
│ │ └── styles.ts
│ └── index.ts
├── containers
│ ├── Blog
│ │ ├── index.tsx
│ │ ├── posts.graphql.ts
│ │ └── styles.ts
│ ├── BlogPost
│ │ ├── comments.graphql.ts
│ │ ├── index.tsx
│ │ ├── post.graphql.ts
│ │ └── styles.ts
│ └── index.ts
├── index.tsx
├── reducers.ts
├── routes.tsx
├── store.tsx
└── styles
└── index.css
src/server
├── db
│ ├── index.ts
│ ├── models
│ │ ├── comment.ts
│ │ └── post.ts
│ └── utils
│ └── uuid.ts
├── graph
│ ├── index.ts
│ ├── mutations
│ │ ├── comment
│ │ │ ├── createComment.ts
│ │ │ └── index.ts
│ │ └── index.ts
│ ├── queries
│ │ ├── comment
│ │ │ ├── comment.ts
│ │ │ ├── comments.ts
│ │ │ └── index.ts
│ │ ├── index.ts
│ │ └── post
│ │ ├── index.ts
│ │ ├── post.ts
│ │ └── posts.ts
│ ├── schema.json
│ └── types
│ ├── comment
│ │ ├── comment.ts
│ │ └── commentInput.ts
│ ├── index.ts
│ └── post
│ ├── post.ts
│ └── postInput.ts
├── graphqlEntry.ts
└── index.tsx
Recently, we've added support for Apollo and GraphQL both server and client side. The starter code in this repo demonstrates how to setup your GraphQL server. The /blog
route will show you a very simple example of loading data via Apollo Graphql.
Included in this project are a few primitive components that you can use to bootstrap your next project, or as a reference for building a UIKit.
- Box
- Flex Box component! Whoot!
- Section
- A section component. Extends the Box component giving flex-box properties.
- Anchor
- Article
- Button
- Footer
- Heading
- Headline
- Hero
- Image
- Markdown
- NavBar
- Paragraph
- SvgIcon
- And more!
We've included react storybook to make it easy for you to test your ui kit components.
Run npm run storybook
and navigate to http://localhost:9001
to see your stories.
You can add more stories as you are building out your components within the ./config/.storybook/stories
folder.
Simply write a story and export it in the stories/index.js
file. Checkout the React Storybook docs for more info!
Note: the components are currently being served from the build
directory, so please make sure you have compiled (npm run compile
) the app before running.
We've included some generators so that you can easily scaffold out components & containers from the command line.
To use the generators, run npm run generator
and select the options you want to use. The generators will create your component or container and their accompanying imports / exports.
We have included setup to get you server-rendering out of the box. Included in the setup is an Express server that will server render. Note that the server-rendering will not work with the TypeScript source code, so you must compile the project into the Build directory first. Also, you must copy any other assets (images, markdown, etc.) into the build folder.
Included is a test framework for all of your React testing needs. We are using Jest to run the test suite and generate snapshots, plus Enzyme for component introspection.
Tests should be collocated within the component / container they represent. Test files should be named index.test.tsx
and mocks must be named myMock.mock.ts
.
Please reference the Box
and Section
components for example tests. More will be added at a later time.
Note that the test are not compiled by TypeScript, that way there is no code duplication and you can use static types in your tests.
P.S. If you are looking to contribute, this would be a great first contribution!
The documentation website built for this boilerplate is deployed to Heroku. Included is a Procfile that will run the server. The deployment is automated completely. After the install script, the deploy script will run on the server in order to compile the bundle and prepare the build folder for server-rendering.
npm run setup:yarn
- Install the package dependencies via yarn
npm install
- Install dependencies (the ol' fashioned way)
npm run start
- Start the dev server
npm run build
- Build the project
npm run deploy
- Create a production bundle for deployment
npm run serve
- Serve the production bundle on port 1337
npm run test
- Run the test suite
npm run test:watch
- Run the test suite in watch mode
npm run test:update
- Update the failing snapshot tests
npm run storybook
- Run the storybook server
- JavaScript Code Quality with Free Tools
- Working with React & TypeScript
- Setting up a New React / TypeScript Project
- Feature First Architecture
See here for our contribution guide. We are on slack, please go here for an invite! We'd love to hear from you!
See here for the license.
- Add CI
- Introduce an async redux workflow
- Redux logic
- Integrate storybook
- Standardize the tslint configuration
- Add more reusable modules, ala box / section
- Refactor reusable modules into uikit
- Remove requires and use es6 imports for all libs
- Add a no any rule and update source to use it
- Migrate to a multi-module pattern using lerna (in progress)
Make sure to use the right version of node. You can reference the version in the .nvmrc
file. For help installing and using NVM, please refer to this gist.