- React - library to build user interfaces
- Tailwind CSS - utility-first CSS framework
- tailwindcss-animate - Tailwind plugin for creating animations
- tailwind-merge - merge Tailwind classes without conflicts
- clsx - utility to construct classNames conditionally
- cva - utility to create style variants
- Radix UI - low-level UI component library with a focus on a11y
- shadcn/ui - collection of designed components mostly based on Radix UI with focus on a11y
- lucide icons - icons set
- Postcss
- postcss-nesting - supports nesting CSS, following the CSS Nesting specification
- autoprefixer - parse CSS and add vendor prefixes to rules by (caniuse.com)[https://caniuse.com/]
- Theme Provider - supports Light, Dark and System themes
- TanStack Query - asynchronous state management with declarative, always-up-to-date auto-managed queries and mutations
- Zod - TypeScript-first schema validation with static type inference
- Fetch based API client
- zod-fetch - to make API client type-safe
- i18next - internationalization framework
- i18next-browser-languagedetector - language detection plugin
- i18next-parser - parses the code, extracts translation keys and produces i18n resource file
- Jotai - state management library
- React Router - declarative routing
- react-error-boundary - simple reusable React error boundary component
- JWT Authentication - including all the common features such as Sign-up, Sign-in, Sign-out, Reset password, Email confirmation
- TypeScript - typed superset of JavaScript
- @tsconfig/bases - strictest & Vite-React
- ts-reset - a 'CSS reset' for TypeScript, improving types for common JavaScript API's
- Vite - next generation frontend tooling
- React SWC plugin - speed up Vite dev server with SWC
- SVG plugin - transform SVGs into React components
- TypeScript & ESLint check plugin
- TSConfig paths plugin - support for TypeScript's path mapping in Vite
- Validate ENV vars plugin
- Vitest - blazing fast Vite-native unit test framework
- Testing Library - simple and complete testing utilities that encourage good testing practices
- user-event - simulates user interactions
- jest-dom - provides custom DOM element matchers
- jsdom-testing-mocks - a set of tools for emulating browser behavior in jsdom environment
- MSW - API mocking library for browser and Node.js
- @mswjs/data - data modeling and relation library for testing
- Testing Library - simple and complete testing utilities that encourage good testing practices
- Prettier - opinionated code formatter
- package.json plugin - to sort the keys of a
package.json
file - TW plugin - to sort Tailwind classes
- package.json plugin - to sort the keys of a
- ESLint - pluggable linting utility
- Husky & lint-staged - run ESLint & Prettier before commiting new code
- CI/CD - Github Actions to run integration tests on each PR & Main branch
- source-map-explorer - analyze and debug space usage through source maps
- rollup-plugin-visualizer - visualize and analyze the production bundle
A token-based API agnostic authentication is already included in this project. It resides in src/common/auth and provides a useAuth
hook. This hook returns current auth state (token
, userId
, isLoggedIn
, and loading indicators), signIn
method to perform a Sign-in operation, relogin
method to renew the token, and signOut
method to perform a Sign-out operation.
It also provides 2 guard components, RequireIsLoggedIn and RequireIsAnonymous, to wrap routes.
Internally, all auth state is stored by Jotai in src/common/auth/state.ts. The JWT token is persisted in localStorage
.
There is also a src/app/PersistAuthGate.tsx to automatically relogin a user after the page reloads if token is present in localStorage
.
- Install nvm (Node version manager)
- Install Node v20 and upgrade npm
nvm install 20 nvm use 20 npm upgrade -g npm
- Clone this repository
git clone https://github.com/Kamahl19/react-starter.git
- Install project dependencies
npm i
- Edit the
.env
file
Start the app locally
npm start
Vite will run web server in the development mode at http://localhost:3000
.
This project includes Mock Service Worker to mock API. It starts automatically and provides API for authentication and user functionality.
Build the app for production
npm run build
The app is then ready to be deployed from the /dist
folder. See the Building for Production and Deploying a Static Site for more information.
Read more about how to deploy to Vercel here. In short, these are the necessary steps:
- Confugiration file vercel.json is already created in this project
- Create new Vercel Project
- Import GitHub repository
- Add environment variable
VITE_API_URL
with value/api
- Hit Deploy
Now each commit pushed to the main
branch will be deployed to production automatically. Each branch or Pull Request will be deployed as preview.
There are 2 different tools to analyze and visualize the production JS bundle:
- source-map-explorer
npm run analyze
- rollup-plugin-visualizer
npm run visualize
Launch the test runner in the interactive watch mode
npm run test
Vitest also provides a neat UI to view and interact with the tests. Open it by running npm run test:ui
.
See Vitest docs for more information.
This project uses Prettier, an opinionated code formatter, to ensure that the whole codebase conforms to a consistent style.
Prettier runs when:
- developer manually executes
npm run format
command - in IDE on file-save if configured (VSCode, IntelliJ IDEA)
- automatically on
pre-commit
hook, right before code is committed - during CI
Project comes with ESLint configured. It helps us prevent common errors.
Code quality concerns, best practices, possible logical issues etc. are checked by ESLint. Our custom ESLint configuration .eslintrc.cjs includes these rules and plugins:
ESLint runs when:
- developer manually executes
npm run lint
command - developer starts Vite dev server by
npm start
command - in IDE on background if supported (VSCode, IntelliJ IDEA)
- automatically on
pre-commit
hook, right before code is committed- defining actions (.husky/pre-commit) for git hooks is enabled by Husky
- linting only the files and changes being committed enables lint-staged
- during continuous integration defined in .github/workflows/test.yml
Running npm run i18n
will first parse the whole codebase to find all used i18n keys. Then it inserts missing keys into the JSON files and removes deprecated keys which are not used in the codebase anymore. The result will be an alphabetically sorted JSONs containing all the currently used i18n keys in the codebase.
This project is using GitHub's Actions to run integration tests on each PR and Main branch. It includes running eslint, prettier, tests and building the app. PR becomes mergable only if it passes. We also show badge on top of README.md
to show Main branch status.
There is also a code-quality action to run Github's CodeQL analysis.
If you don't use GitHub you can remove the .github
folder, otherwise follow these steps to configure your GitHub repository:
- Go to Settings -> Branches -> Add rule
- Apply to your main branch
- Require status checks to pass before merging
- Select build checks being run in test.yml
- Update path to your repository (eg.
Kamahl19/react-starter
) and name of the branch for CI badge inREADME.md
Once you start building your own app on top of React Starter you will probably want to keep up-to-date with the new updates of React Starter. This can be easily achieved using GitHub's compare feature. We suggest this process:
- When you clone the React Starter repo, don't forget to write down the hash of latest main's commit
- Every once in a while, compare the version of React Starter you used with the current version of React Starter like this
https://github.com/Kamahl19/react-starter/compare/{YOUR_LATEST_REACT_STARTER_COMMIT_HASH}...main
- Go through the diff and apply the changes in your own app
- Commit these changes into your own repo with this commit message:
Updating to React Starter hash: {LATEST_REACT_STARTER_COMMIT_HASH}
. This way you always keep the hash of the React Starter's version you currently use in your app
This is open source software licensed as MIT.