|
1 | 1 | # React Sample |
2 | 2 |
|
3 | 3 | [](https://github.com/raminr77/react_sample/) |
| 4 | +[](https://github.com/raminr77/react_sample/) |
4 | 5 |
|
5 | | -## Start your React Project with a ready config! |
| 6 | +# 🚀 React Sample Project |
6 | 7 |
|
7 | | -this is a sample of the ReactJs project for starting easily and fast. |
| 8 | +A simple and clean React + TypeScript + Vite starter project, configured with essential tools and structured with best practices gained from 7+ years of frontend development experience. |
8 | 9 | <br/> |
9 | | -In this project, we added some configs and installed some necessary packages. they help you to ready very fast and don't waste time them. |
| 10 | +This is a sample of the ReactJs project for starting easily and fast. |
10 | 11 | <br /> |
11 | 12 |
|
12 | | -## Contents |
| 13 | +## 📁 Project Structure |
13 | 14 |
|
14 | | -- [Configs](https://github.com/raminr77/react_sample#Configs) |
15 | | -- [Packages](https://github.com/raminr77/react_sample#Packages) |
16 | | -- [Hooks](https://github.com/raminr77/react_sample#Hooks) |
17 | | -- [Tools (utils)](https://github.com/raminr77/react_sample#tools-utils) |
18 | | -- [How To Run](https://github.com/raminr77/react_sample#how-to-run) |
19 | | -- [API Pattern](https://github.com/raminr77/react_sample#api-pattern) |
20 | | -- [You Can Use In This Project](https://github.com/raminr77/react_sample#you-can-use-in-this-project) |
| 15 | +``` |
| 16 | +scripts/ # For Custom Scripts (Icon Generator, etc.) |
| 17 | +public/ # Application files (PWA, Icons, Splash Screens, etc.) |
| 18 | +src/ |
| 19 | + ├── pages/ # Application pages (auth, landing, main, etc.) |
| 20 | + ├── layout/ # Layout components and containers |
| 21 | + ├── shared/ # Shared logic: helpers, constants, services, types, store |
| 22 | + ├── styles/ # Global styles (SCSS & Tailwind) |
| 23 | + └── __test__/ # Unit tests |
| 24 | +``` |
21 | 25 |
|
22 | | -<br /> |
23 | | -<hr /> |
24 | | -<br /> |
| 26 | +The project includes complete configurations for **ESLint**, **Prettier**, **Stylelint**, **Husky** (pre-commit hooks), and **CI/CD via GitHub Actions**. |
25 | 27 |
|
26 | | -- ## Configs |
27 | | - |
28 | | - - Eslint |
29 | | - - Prettier |
30 | | - - Stylelint |
31 | | - - Dockerfile |
32 | | - - `.env` file |
33 | | - - Commit lint |
34 | | - - Redux Config |
35 | | - - Style Config |
36 | | - - SEO & PWA tags |
37 | | - - `jsconfig` file |
38 | | - - `tsconfig` file |
39 | | - - Folder structure |
40 | | - - API cache system |
41 | | - - Private route system |
42 | | - - `lint-staged` config |
43 | | - - Custom `manigest.json` |
44 | | - - `constants` structure |
45 | | - - First loading animation |
46 | | - - API Pattern for request |
47 | | - - Lock API request system |
48 | | - - Cancel duplicate request |
49 | | - - Reset default browser CSS |
50 | | - - Scroll to the top when route change |
51 | | - - Transform data system for API request |
52 | | - - Pre-Commit and Commit-Message config (husky) |
53 | | - |
54 | | -- ## Packages |
55 | | - |
56 | | -### Dependencies |
57 | | - |
58 | | -- TypeScript |
59 | | -- sass (for component module sass) |
60 | | -- animate.css (for your animations) |
61 | | -- tailwindcss (for main style system) |
62 | | -- lodash (for working easily with array) |
63 | | -- axios (for API service and request system) |
64 | | -- classnames (for merge ClassNames and module sass) |
65 | | -- react-router-dom (for routing system in your project) |
66 | | -- prop-types (for specify type in your JSX & component file) |
67 | | -- react-toastify (for notify message to user in your project) |
68 | | -- react-device-detect (for check devices and specify mobile type) |
69 | | -- @reduxjs/toolkit & react-redux (for state management in your project) |
70 | | - |
71 | | -### DevDependencies |
72 | | - |
73 | | -- husky |
74 | | -- eslint (+ plugins and configs) |
75 | | -- prettier (+ plugins and configs) |
76 | | -- stylelint |
77 | | -- lint-staged |
78 | | -- eslint-config-airbnb |
79 | | -- commitlint + config-conventional |
80 | | -- ## Hooks |
81 | | - |
82 | | - - useApi (for requests) |
83 | | - - usePageData (for page requests) |
84 | | - - useCopyToClipboard (for copy text) |
85 | | - - useOnScreen (for traking an element on screen) |
86 | | - |
87 | | -- ## Tools (utils) |
88 | | - |
89 | | - - Snackbar |
90 | | - - `htmlDecode` function |
91 | | - - URLs for share in social |
92 | | - - `generateSnackbar` function |
93 | | - - `apiRequestObject` for API pattern |
94 | | - - `removeUndefinedFromObject` function |
95 | | - - Log system (Empty function for your config) |
96 | | - - `redirect` and `attachObjectQueriesToUrl` functions |
97 | | - - `truncate` and `shouldTruncate` functions for your texts |
98 | | - - `isDemo`, `isProduction`, `isDevelopment`, `appVersion` and `appName` variables |
99 | | - - `faToEn`, `enToFa`, `arToFa`, `faPriceToEnNumber` and `formatPrice` functions for your numbers (persian language) |
| 28 | +--- |
100 | 29 |
|
101 | | -<br /> |
| 30 | +## ⚙️ Getting Started Locally |
102 | 31 |
|
103 | | -## You Can Use In This Project |
| 32 | +### 1. Install Dependencies |
104 | 33 |
|
105 | | -- You can use the AnimateCSS framework for your animations, add the class `animate__animated` to an element, along with any of the animation names white the `animate__` prefix. |
| 34 | +```bash |
| 35 | +npm install |
| 36 | +``` |
106 | 37 |
|
107 | | - `<h1 class="animate__animated animate__bounce">An animated element</h1>` |
| 38 | +### 2. Create the `.env` File |
108 | 39 |
|
109 | | - REF: https://animate.style/ |
| 40 | +Create your local environment file by copying the example file: |
110 | 41 |
|
111 | | -- You can use `Vazir` font in this project. for change `EN` to `FA` number with font, use `fa-num-font` and `fa-num-font-bold` class. also you can use `vazir-bold` for bold type. |
112 | | -- You can import file from `src` address like this: |
| 42 | +```bash |
| 43 | +cp .env.example .env |
| 44 | +``` |
113 | 45 |
|
114 | | - `import { INDEX_PAGE_ROUTE } from 'routes/RedirectRoutes';` |
| 46 | +Then make sure to configure your **Firebase settings** required for push notifications inside `.env`. |
115 | 47 |
|
116 | | -<br /> |
| 48 | +If you're just testing the app and don't have Firebase set up, you can use dummy values for now. |
117 | 49 |
|
118 | | -## API Pattern |
| 50 | +--- |
119 | 51 |
|
120 | | -- Your API |
| 52 | +## 🐳 Running with Docker |
121 | 53 |
|
122 | | - **TODO** |
| 54 | +### Build and Run |
123 | 55 |
|
124 | | -- useApi |
| 56 | +```bash |
| 57 | +docker build -t react-sample-app . |
| 58 | +docker run -d -p 3000:80 react-sample-app |
| 59 | +``` |
125 | 60 |
|
126 | | - **TODO** |
| 61 | +Visit: [http://localhost:3000](http://localhost:3000) |
127 | 62 |
|
128 | | -- usePageData |
| 63 | +--- |
129 | 64 |
|
130 | | - **TODO** |
| 65 | +## 📦 Using Docker Compose |
131 | 66 |
|
132 | | -<br /> |
| 67 | +```bash |
| 68 | +docker-compose up --build |
| 69 | +``` |
| 70 | + |
| 71 | +To stop and remove containers: |
| 72 | + |
| 73 | +```bash |
| 74 | +docker-compose down |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## ✅ Testing |
| 80 | + |
| 81 | +Unit tests can be added and placed under the `src/__test__` folder. You can use any preferred framework like Vitest or Jest. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## 📄 License |
| 86 | + |
| 87 | +This project is open-source and licensed under the [MIT License](LICENSE). |
| 88 | + |
| 89 | +## 💡 Tips & Features |
| 90 | + |
| 91 | +### ✨ Animations |
| 92 | + |
| 93 | +You can use the [AnimateCSS](https://animate.style/) framework for applying animations by adding the class `animate__animated` and the desired animation class with the `animate__` prefix: |
| 94 | + |
| 95 | +```html |
| 96 | +<h1 class="animate__animated animate__bounce">An animated element</h1> |
| 97 | +``` |
| 98 | + |
| 99 | +🔧 **But there's more!** This project includes a custom helper function for generating animation class names easily: |
| 100 | + |
| 101 | +```ts |
| 102 | +animator({ name: 'fadeIn', speed: 'faster' }); |
| 103 | +``` |
| 104 | + |
| 105 | +This will generate appropriate class names automatically. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +### 📁 Import Aliases |
| 110 | + |
| 111 | +You can import modules from the `src` folder using the `@/` alias: |
| 112 | + |
| 113 | +```ts |
| 114 | +import { APP_ROUTES } from '@/shared/constants'; |
| 115 | +``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## 🧪 Available NPM Commands |
| 120 | + |
| 121 | +Here’s a list of useful scripts for development and maintenance: |
133 | 122 |
|
134 | | -## How To Run |
135 | | - |
136 | | -- First Git Clone Or Download Project |
137 | | -- Copy and rename `.env.example` to `.env` |
138 | | -- `npm install` or `yarn add` |
139 | | -- Just Run: `npm start` |
140 | | -- Run white style watching: |
141 | | - - Windows: `npm run dev:windows` |
142 | | - - Linux or MaxOs: `npm run dev` |
143 | | - |
144 | | -### Other Commands |
145 | | - |
146 | | -- Test: `npm run test` |
147 | | -- Build: `npm run build` |
148 | | -- Eslint: `npm run lint:fix` |
149 | | -- Prettier: `npm run pretty` |
150 | | -- Stylelint: `npm run lint:style` |
151 | | -- Styles (Watching): `npm run styles` |
152 | | -- Build Styles: `npm run build:styles` |
153 | | - |
154 | | -<hr /> |
155 | | - |
156 | | -### Project TODO |
157 | | - |
158 | | -- [ ] Scripts |
159 | | -- [ ] Storybook |
160 | | -- [ ] Test config |
161 | | -- [ ] E2E test config |
162 | | -- [ ] Folder Structure |
163 | | -- [ ] Convert js to ts |
164 | | -- [ ] Add API pattern Doc to MD file |
165 | | -- [ ] Add usePageData & UseApi Doc to MD file |
| 123 | +| Command | Description | |
| 124 | +|------------------|----------------------------------------------| |
| 125 | +| `dev` | Run the project locally using Vite | |
| 126 | +| `test` | Run unit tests with Vitest | |
| 127 | +| `prepare` | Prepare Git hooks using Husky | |
| 128 | +| `lint` | Run ESLint and fix issues automatically | |
| 129 | +| `format` | Format the code using Prettier | |
| 130 | +| `build` | Build TypeScript and the app bundle | |
| 131 | +| `check-lint` | Check lint issues without fixing | |
| 132 | +| `check-format` | Check code formatting | |
| 133 | +| `preview` | Preview production build at port 8080 | |
| 134 | +| `check-types` | Type-check the project without emitting files| |
| 135 | +| `pretty` | Format all JS/TS/CSS/SCSS source files | |
| 136 | +| `lint:style` | Run Stylelint for style file validation | |
0 commit comments