Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

scalable-react/scalable-react-typescript-boilerplate

Repository files navigation

NOTICE:

The maintainers of this repo are no longer able to support a thriving open source community. This repo will stay put to serve as an example for the community, but should not be depended on in a production application unless you and are your team intend to build upon it.

If you're interested in helping to support and grow this library, please let us know in the issues!

Open UI

We are working on a ui kit, which you'll find located in the packages directory. Much like this project, this code is not yet production ready and we have yet to document it. Please stay tuned.

TypeScript

Scalable React TS Boilerplate

Build Status PRs Welcome Roadmap Star on Github Watch on Github Tweet

Checkout our website for documentation and examples.

Background Info

We know that there are a ton of react boilerplates and starter projects to choose from. Our hope with this project is to provide an example of one of the best front-end architectural patterns available: Feature First. We started initially with a vanilla JS version of this architecture and have since converted it entirely to strongly-typed TypeScript. Above all else, the hope of this repository is to provide the open source community with a great example of how to build large-scale apps with React and TypeScript using the feature-first modularization pattern. Read on to get started!

Main Features

  • Feature First
  • Statically Typed
  • TypeScript
  • Lerna
  • Starter UI Kit (Open UI)
  • Redux Logic
  • Webpack 2
  • React
  • Redux
  • Hot Module Reloading
  • Server Side Rendering
  • Highly optimized webpack configuration
    • Code Chunking
    • Lazy route loading
    • Uglification / minification

Getting Started

  1. Clone the Repo git clone https://github.com/RyanCCollins/scalable-react-ts-boilerplate

  2. Install Dependencies From the root of the project directory, run yarn if you have yarn installed globally. --- or --- npm install.

  3. Clear out the code you don't want. Run npm run clean to get rid of the docs package and to reset the codebase to the bare minimum (note: we are still working on this and this would be a great place to submit an improvement).

  4. Start the Development Server Run npm run start then browse http://localhost:1337 to see your running app.

What is Feature First?

In many projects and frameworks, files are organized by their file type. For example, you will find tests in a test folder, reducers in a reducers folder and so on and so forth. This framework takes a different approach.

We encourage modularization / encapsulation of features by asking that you organize your files by feature, rather than file type. When you begin working on your next container, instead of having to root through multiple files to find all of the files that the container depends on, you can expect to find these files in one place: with the feature that they represent. This helps to decouple the features in your app, lending itself well to code reuse, scalability and modularization.

On top of that, we also ask that you think about separation of concern as you are building your features. You will see in the example application in this repository that a feature is built up of a dozen or so small, single purpose modules. By following these simple patterns, you will set yourself up for maximum scalability. Give it a try! We think you will enjoy it.

Lerna

We are hard at work converting the structure of this boilerplate to use Lerna. Stay tuned for more information!

Styled Components

This project embraces styled-components as it's a fantastic way to style your React components.

Check the components directory for examples.

Full Stack

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.

File Tree Structure

Client File Structure

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

Server file structure

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

Apollo GraphQL

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.

UI Components

Build your next UIKit with this library!

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.

React Storybook

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.

Generators

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.

Server Rendering

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.

Testing

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!

Deployment

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.

Scripts

  • npm run setup:yarn
    • Install the package dependencies via yarn (recomended)
  • 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

Resources

Contributing

See here for our contribution guide. We are on slack, please go here for an invite! We'd love to hear from you!

License

See here for the license.

Roadmap

v1.0.2

  • 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)

Troubleshooting

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.