Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to more modern toolset (Vite, Vitest, Playwright) + Upgrade dependencies + More Improvements #152

Merged
merged 34 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a3aff53
show author for discussion and comment
alan2207 Apr 27, 2024
45fba58
migrate to modern stack - almost fully working
alan2207 Apr 28, 2024
31aeb1b
tests working
alan2207 Apr 28, 2024
dd427db
update pipeline
alan2207 Apr 28, 2024
d5d4355
upgrade rest of dependencies
alan2207 Apr 30, 2024
4243e83
update docs
alan2207 May 1, 2024
8a83d18
add some changes from https://github.com/alan2207/bulletproof-react/p…
alan2207 May 1, 2024
5545b97
no need to run prettier, all formatting is handled by eslint-plugin-p…
alan2207 May 1, 2024
977a77e
update react-query-auth
alan2207 May 2, 2024
af4bfcf
update license
alan2207 May 2, 2024
0658e52
update zustand mocks for testing
alan2207 May 3, 2024
74c7612
validate env variables
alan2207 May 3, 2024
e74349e
store the auth token in a cookie instead of localStorage
alan2207 May 3, 2024
4046a41
prevent circular dependencies
alan2207 May 3, 2024
be8f370
restructure routes
alan2207 May 4, 2024
1679821
switch to shadcn ui and update components
alan2207 May 5, 2024
a1cfae7
prefer types over interfaces
alan2207 May 5, 2024
3c3d455
use kebab case for all files
alan2207 May 5, 2024
9411b74
improve type inference and api input validation
alan2207 May 5, 2024
c8cd689
improve testing setup
alan2207 May 6, 2024
fc87fac
add storybook a11y addon - https://github.com/alan2207/bulletproof-re…
alan2207 May 6, 2024
2ca9398
remove redundant fragments - https://github.com/alan2207/bulletproof-…
alan2207 May 6, 2024
49c5092
update formatting rules
alan2207 May 6, 2024
d7e71d7
more generic api client
alan2207 May 7, 2024
60d95a3
update docs
alan2207 May 7, 2024
7ddd5c4
improve query keys
alan2207 May 7, 2024
513d8bd
skip ci when only docs change have been made
alan2207 May 7, 2024
9a62bf1
prefer mutate over mutateAsync
alan2207 May 10, 2024
76065e9
refactor playwright tests
alan2207 May 11, 2024
51dd805
improve api hooks
alan2207 May 11, 2024
7fe5817
fix app file case
alan2207 May 11, 2024
9f57a2b
better usage of query options
alan2207 May 13, 2024
b898a0d
update docs
alan2207 May 13, 2024
1fb422b
update
alan2207 May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
REACT_APP_API_URL=https://api.bulletproofapp.com
REACT_APP_API_MOCKING=true
TSC_COMPILE_ON_ERROR=true
ESLINT_NO_DEV_ERRORS=true
CHOKIDAR_USEPOLLING=true
VITE_APP_API_URL=https://api.bulletproofapp.com
VITE_APP_ENABLE_API_MOCKING=true
11 changes: 4 additions & 7 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
es6: true,
},
parserOptions: { ecmaVersion: 8, sourceType: 'module' },
ignorePatterns: ['node_modules/*'],
ignorePatterns: ['node_modules/*', 'public/mockServiceWorker.js', 'generators/*'],
extends: ['eslint:recommended'],
overrides: [
{
Expand Down Expand Up @@ -34,6 +34,8 @@ module.exports = {
'plugin:prettier/recommended',
'plugin:testing-library/react',
'plugin:jest-dom/recommended',
'plugin:tailwindcss/recommended',
'plugin:vitest/legacy-recommended',
],
rules: {
'no-restricted-imports': [
Expand All @@ -42,9 +44,9 @@ module.exports = {
patterns: ['@/features/*/*'],
},
],
'import/no-cycle': 'error',
'linebreak-style': ['error', 'unix'],
'react/prop-types': 'off',

'import/order': [
'error',
{
Expand All @@ -56,18 +58,13 @@ module.exports = {
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',

'react/react-in-jsx-scope': 'off',

'jsx-a11y/anchor-is-valid': 'off',

'@typescript-eslint/no-unused-vars': ['error'],

'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-module-boundary-types': ['off'],
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],

'prettier/prettier': ['error', {}, { usePrettierrc: true }],
},
},
Expand Down
63 changes: 41 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
name: CI
on:
push:
branches:
- master
branches: ['*']
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
branches:
- master
branches: [master]
paths-ignore:
- 'README.md'
- 'docs/**'
jobs:
all-cli-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '14.16'
- run: mv .env.example .env
- run: yarn install
- run: yarn build
- run: yarn test:jest
- run: yarn lint
- run: yarn check-format
- run: yarn check-types
cypress-run:
node-version: lts/*
- name: Set environment variables
run: mv .env.example .env
- name: Install dependencies
run: yarn install
- name: Build application
run: yarn build
- name: Run tests
run: yarn test
- name: Run linter
run: yarn lint
- name: Check types
run: yarn check-types
e2e:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '14.16'
- run: mv .env.example .env
- uses: cypress-io/github-action@v2
node-version: lts/*
- name: Set environment variables
run: mv .env.example .env
- name: Install dependencies
run: npm install -g yarn && yarn
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
build: yarn build
start: yarn serve
name: playwright-report
path: playwright-report/
retention-days: 30
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@

# testing
/coverage
/cypress/videos
/cypress/screenshots
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/e2e/.auth/

# storybook
migration-storybook.log
storybook.log
storybook-static


# production
/build
/dist

# misc
.DS_Store
Expand All @@ -24,3 +33,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn validate
yarn lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.hbs
6 changes: 3 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100,
"trailingComma": "all",
"printWidth": 80,
"tabWidth": 2,
"useTabs": false
}
}
41 changes: 0 additions & 41 deletions .storybook/main.js

This file was deleted.

23 changes: 23 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],

addons: [
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/node-logger',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-docs',
'@storybook/addon-a11y',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
docs: {
autodocs: 'tag',
},
typescript: {
reactDocgen: 'react-docgen-typescript',
},
};
6 changes: 3 additions & 3 deletions .storybook/preview.js → .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AppProvider } from '../src/providers/app';
import { BrowserRouter as Router } from 'react-router-dom';
import '../src/index.css';

export const parameters = {
Expand All @@ -8,8 +8,8 @@ export const parameters = {

export const decorators = [
(Story) => (
<AppProvider>
<Router>
<Story />
</AppProvider>
</Router>
),
];
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
4 changes: 2 additions & 2 deletions LICENCE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Alan Alickovic
Copyright (c) 2024 Alan Alickovic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bulletproof React 🛡️ ⚛️

[![MIT License](https://img.shields.io/github/license/alan2207/bulletproof-react)](https://github.com/alan2207/bulletproof-react/blob/master/LICENCE)
[![MIT License](https://img.shields.io/github/license/alan2207/bulletproof-react)](https://github.com/alan2207/bulletproof-react/blob/master/LICENSE)
[![CI](https://github.com/alan2207/bulletproof-react/actions/workflows/ci.yml/badge.svg)](https://github.com/alan2207/bulletproof-react/actions/workflows/ci.yml)

A simple, scalable, and powerful architecture for building production ready React applications.
Expand All @@ -9,21 +9,36 @@ A simple, scalable, and powerful architecture for building production ready Reac

React is an excellent tool for building front-end applications. It has a diverse ecosystem with hundreds of great libraries for literally anything you might need. However, being forced to make so many choices can be overwhelming. It is also very flexible, you can write React applications in any way you like, but that flexibility comes with a cost. Since there is no pre-defined architecture that developers can follow, it often leads to a messy, inconsistent, and over-complicated codebase.

This repo attempts to present a way of creating React applications using some of the best tools in the ecosystem with a good project structure that scales very well. Based on my vast experience working with different codebases, this architecture turns out to be the most effective.
This repo attempts to present a way of creating React applications using some of the best tools in the ecosystem with a good project structure that scales very well. Based on my experience working with a lot of different codebases, this architecture turns out to be the most effective.

The goal here is to serve as a collection of resources and best practices when developing React applications. It is supposed to showcase solving most of the real-world problems of an application in a practical way and help developers write better applications.

Feel free to explore the codebase to get the most value out of the repo.
Feel free to explore the sample app codebase to get the most value out of the repo.

## What makes a React application "bulletproof"?

This repo doesn't aim to be a silver bullet for all React applications as there are many different use cases, but it tries to provide a solid foundation for building applications based on the following principles:

- Easy to get started with
- Simple to understand and maintain
- Uses the right tools for the job
- Clean boundaries between different parts of the application
- Everyone on the team is on the same page when it comes to how things are done
- Security
- Performance
- Scalability in terms of codebase and team size
- Issues detectable as early as possible

#### Disclaimer:

This is not supposed to be a template, boilerplate or a framework. It is an opinionated guide that shows how to do some things in a certain way. You are not forced to do everything exactly as it is shown here, decide what works best for you and your team and stay consistent with your style.

To get most out of it, do not get limited by the technologies used in this sample app, but rather focus on the principles and the concepts that are being presented here. The tools and libraries used here are just a suggestion, you can always replace them with something that fits your needs better Sometimes, your project might require a slightly different approach, and that's totally fine.

## Table Of Contents:

- [💻 Application Overview](docs/application-overview.md)
- [⚙️ Project Configuration](docs/project-configuration.md)
- [👁️ Style Guide](docs/style-guide.md)
- [⚙️ Project Standards](docs/project-standards.md)
- [🗄️ Project Structure](docs/project-structure.md)
- [🧱 Components And Styling](docs/components-and-styling.md)
- [📡 API Layer](docs/api-layer.md)
Expand All @@ -47,4 +62,4 @@ Contributions are always welcome! If you have any ideas, suggestions, fixes, fee

## License

[MIT](https://choosealicense.com/licenses/mit/)
[MIT](/LICENSE)
2 changes: 2 additions & 0 deletions __mocks__/vitest-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vitest/globals" />
Loading