Skip to content

iDanielLaw/astraea

 
 

Repository files navigation

Astraea TypeScript + React + Redux Boilerplate

https://img.shields.io/travis/jupl/astraea/master.svg?label=travis&style=flat-square https://img.shields.io/david/jupl/astraea/master.svg?style=flat-square https://img.shields.io/david/dev/jupl/astraea/master.svg?style=flat-square

Table of Contents

About

This is a boilerplate project for developing a mid to large scale client-side application(s) using TypeScript, React, and Redux. For an example project, visit the example branch.

Back to top

Prerequisites

Back to top

Getting Started

  1. Clone/download this repository.
  2. Install dependencies using npm or Yarn:
    • npm install
    • yarn
  3. Start running tasks as described below in the tasks section.

Back to top

Project structure

Overview

astraea/
├─ .storybook/                 # Storybook configuration
├─ coverage/                   # Code coverage reports
├─ dist/assets/                # Result assets from build tasks
├─ src/                        # Source code
│  ├─ app/                     # Application domain
│  │  ├─ components/root/      # Top level application view
│  │  ├─ actions.test.ts       # Test to ensure all actions are valid
│  │  └─ reducer.ts            # Reducer for whole application
│  ├─ assets/                  # Static files and entry points to include in builds
│  │  └─ app.tsx               # An application entry point
│  ├─ common/                  # Shared code used throughout project
│  │  ├─ components/container/ # Application wrapper component
│  │  └─ store.ts              # Helper to create a Redux store
│  └─ webpack/                 # Webpack related code
│     ├─ config/               # Webpack build configurations
│     ├─ plugin/               # Webpack plugins
│     └─ server.ts             # Local development server
├─ story/                      # Result storybook build
├─ declarations.d.ts           # TypeScript declarations
├─ package.json                # Configuration, tasks, and dependencies
├─ package-lock.json           # Dependency pinning from NPM
├─ setup-tests.ts              # Code that runs before tests are run
├─ tsconfig.json               # TypeScript configuration
├─ tslint.json                 # TypeScript linting rules
├─ webpack.config.ts           # Webpack build configuration
└─ yarn.lock                   # Dependency pinning from Yarn

Entry Points

When TypeScript code is built, any files directly inside the src/assets/ directory are used to create the output files. The boilerplate currently generates app.js, as there is a single entry point inside src/assets/. (src/assets/index.js) If there are more than one entry points more files generated as well as an additional file common.js, which contains shared code across all entry points. common.js must be loaded before you load an entry point. You can see what gets generated by running the build:dev / build:prod task. (see the tasks section)

Domains

domain/
├─ components/
│  ├─ component1/ # See Component sections below
│  ├─ component2/
│  └─ componentX/
├─ actions.ts # Redux actions for domain
└─ reducer.ts # Domain reducer

Rather than group items by things like components/reducers/actions/etc., items are grouped by domain which can be a saner option as the project grows. Examples of domains can be things like resources (ex. blog/, users/) or other things. (ex. ui/) Domains may include things like components, actions, reducer, etc. but they don’t have to include all of them. In fact, you can think of app/ and common/ as domains. Other files may be present as well.

Components

component/
├─ index.ts
└─ template.tsx

React components are grouped in a directory.

  • template.tsx defines the React component without any knowledge of Redux specifics or other things like React DnD. (sometimes referred as dumb component)
  • index.ts is the entry point of the component when used by others.
    • If template does not require data/action bindings then it can just pass through the template. (see src/app/components/root/index.ts)
    • If template requires data/action bindings then it is done here. (sometimes refereed as smart component)

Other Files

*.test.ts, *.test.tsx

Tests for components/domains/logic/etc. If code needs to be run before tests are executed see setup-tests.ts Some guides on tests include:

*.stories.tsx

Defines a story to display in React Storybook. Typically this file is in a component. (ex. index.stories.tsx) This guide provides information on how to write stories.

__snapshots__

Generated files/directories when using Jest’s snapshot feature. These files should be left to Jest and not touched manually.

Back to top

Tasks

Tasks can be executed in the following manner:

npm run [command]  # npm
yarn run [command] # Yarn

Examples:

npm run server
yarn run lint

start

Alias for build:prod.

server

Alias for server:hot.

server:hot

Start a local development server with hot reloading. To override the port change the environment variable PORT. The following is provided:

server:story

Start a local server for React Storybook on port 9001. For more information visit the documentation for React Storybook.

build:dev / build:prod

Build application and include assets into a packaged build in the dist/assets/ directory. The build for build:dev is not minifed and includes source maps, making it ideal for development. The build for build:prod is minified (with dead code elimination) and does not include source maps, making it ideal for production.

build:story

Generate a static build of React Storybook in the story/ disrectory.

test / test:watch / coverage / coverage:watch

Execute tests once or continuously on file changes. In addition, code coverage can be determined. For more information visit the documentation for Jest.

lint / lint:fix

Check codebase against linting rules. Optionally, some errors can be fixed automatically.

Back to top

Project Resources

Back to top

About

TypeScript + React + Redux Boilerplate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 90.2%
  • JavaScript 5.5%
  • HTML 4.3%