|
1 | | -# <img height="45" src="./src/assets/Logo.png" alt="Logo" style="margin-bottom:-11px;"> Rick & Morty Memory Game |
| 1 | +# <img height="45" src="./public/favicon.ico" alt="Logo" style="margin-bottom:-11px;"> Rick & Morty Memory Game |
2 | 2 |
|
3 | 3 | <div align="center"> |
4 | 4 |
|
5 | | - |
6 | | - |
7 | | -# A React Class-Component Masterclass |
8 | | - |
9 | | -**A production-grade React application engineered to demonstrate a deep understanding of core React fundamentals. Built entirely with Class-Based Components to showcase explicit lifecycle management, rigorous state architecture, and enterprise-level CI pipelines and seamless deployment via GitHub Pages.** |
10 | | - |
11 | | -[](https://reactjs.org/) |
12 | | -[](https://jestjs.io/) |
13 | | -[](https://github.com/features/actions) |
14 | | -[](https://www.framer.com/motion/) |
15 | | -[](https://prettier.io/) |
16 | | -[](https://eslint.org/) |
| 5 | +### A React Class-Component Masterclass. |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + <strong>A production-grade React application engineered to demonstrate a deep understanding of core React fundamentals. Built entirely with Class-Based Components to showcase explicit lifecycle management, rigorous state architecture, and enterprise-level CI pipelines.</strong> |
| 9 | +</p> |
| 10 | + |
| 11 | +<p align="center"> |
| 12 | + <a href="https://umarsiddique010.github.io/rick-morty-game-react/"><strong>View Live Production Deployment</strong></a> |
| 13 | + • |
| 14 | + <a href="#setup-instructions"><strong>Local Setup</strong></a> |
| 15 | + • |
| 16 | + <a href="https://github.com/umarSiddique010/rick-morty-game-react"><strong>Repository</strong></a> |
| 17 | + • |
| 18 | + <a href="https://github.com/umarSiddique010/rick-morty-game-react/issues"><strong>Report an Issue</strong></a> |
| 19 | +</p> |
| 20 | + |
| 21 | +[](https://reactjs.org/) |
| 22 | +[](https://developer.mozilla.org/en-US/docs/Web/JavaScript) |
| 23 | +[](https://jestjs.io/) |
| 24 | +[](https://motion.dev/) |
| 25 | +[](https://typicode.github.io/husky/) |
| 26 | +[](https://eslint.org/) |
| 27 | +[](https://prettier.io/) |
| 28 | +[](https://github.com/features/actions) |
| 29 | +[](https://pages.github.com/) |
17 | 30 |
|
18 | 31 | </div> |
19 | 32 |
|
20 | 33 | --- |
21 | 34 |
|
22 | | ---- |
23 | | - |
24 | | -## 🚀 Features & Architecture |
| 35 | +## Overview |
25 | 36 |
|
26 | | -### 🧐 The Philosophy: Why Class Components? |
| 37 | +This repository demonstrates **"Class Components done right"** — a deliberate architectural choice in an era dominated by Hooks. `App.js` acts as the single source of truth, lifting state up and passing callbacks down, ensuring strict unidirectional data flow across the entire game. |
27 | 38 |
|
28 | | -In an era dominated by Functional Components and Hooks, this project serves as a **deliberate architectural showcase** of core React fundamentals. By strictly utilizing Class Components, this codebase demonstrates: |
| 39 | +## Game Preview |
29 | 40 |
|
30 | | -- **Explicit Lifecycle Management:** Granular control over component behavior using `componentDidMount` (for API calls and timers), `componentDidUpdate` (for score tracking and game-over logic), and `componentWillUnmount` (for preventing memory leaks by clearing intervals and audio streams). |
31 | | -- **Context Binding & `this`:** A deep understanding of JavaScript scope, `this` binding in constructors, and event handler management without relying on `useCallback`. |
32 | | -- **State Architecture:** `App.js` acts as the single source of truth, lifting state up and passing callbacks down to children like `ScoreBoard` and `Card`, ensuring unidirectional data flow. |
| 41 | + |
33 | 42 |
|
34 | | -### ⚡ Core Functionality |
| 43 | +## Features & Architecture |
35 | 44 |
|
36 | | -- **REST API Integration:** Asynchronously fetches character data from the **Rick and Morty API**, handling loading states and errors gracefully within the `CardContainer` lifecycle. |
37 | | -- **Fluid Animations:** Utilizes **Framer Motion** (`motion/react`) to orchestrate complex entrance and exit animations for the game board, modals, and score updates. |
38 | | -- **Immersive Audio Engine:** Features a dedicated `GameSounds.js` class that manages `Audio` instances, background music loops, and sound effects with a global mute toggle. |
39 | | -- **Responsive UI:** Built with **CSS Modules** to ensure locally scoped styles, preventing class name collisions while maintaining a fully responsive design across devices. |
| 45 | +### 1. The Philosophy: Why Class Components? |
40 | 46 |
|
41 | | ---- |
| 47 | +In an era dominated by Functional Components and Hooks, this project serves as a deliberate architectural showcase of core React fundamentals. By strictly utilizing Class Components, this codebase demonstrates: |
42 | 48 |
|
43 | | -## 🛠 Tech Stack |
| 49 | +- **Explicit Lifecycle Management:** Granular control using `componentDidMount` (API calls and timers), `componentDidUpdate` (score tracking and game-over logic), and `componentWillUnmount` (clearing intervals and audio streams to prevent memory leaks) |
| 50 | +- **Context Binding & `this`:** A deep understanding of JavaScript scope, `this` binding in constructors, and event handler management without relying on `useCallback` |
| 51 | +- **State Architecture:** `App.js` as the single source of truth — state lifted up, callbacks passed down, unidirectional data flow enforced throughout |
44 | 52 |
|
45 | | -| Category | Technology | |
46 | | -| :----------------------- | :---------------------------------- | |
47 | | -| **Core Framework** | React 19 (Class-Based Architecture) | |
48 | | -| **Language** | JavaScript (ES6+) | |
49 | | -| **Styling** | CSS Modules, Utility Classes | |
50 | | -| **Animation** | Framer Motion (`motion/react`) | |
51 | | -| **Testing** | Jest, React Testing Library | |
52 | | -| **Linting & Formatting** | ESLint, Prettier | |
53 | | -| **CI & Hosting** | GitHub Actions, GitHub Pages | |
| 53 | +### 2. Core Gameplay |
54 | 54 |
|
55 | | ---- |
| 55 | +- 3 difficulty levels — Easy (210s), Medium (120s), Hard (40s) |
| 56 | +- Click each card only once; duplicate click = Game Over |
| 57 | +- High score persisted to `localStorage` across sessions |
56 | 58 |
|
57 | | -## 🧪 Testing Strategy |
| 59 | +### 3. Key Technical Features |
58 | 60 |
|
59 | | -This project employs a "Test-Driven mindset" with a robust suite covering Unit, Integration, and Logic tests. |
| 61 | +- **Rick & Morty API** — Characters fetched asynchronously in `CardContainer`'s `componentDidMount` with loading and error states |
| 62 | +- **Audio Engine** — Dedicated `GameSounds.js` class managing BGM, SFX, and global mute toggle, fully decoupled from UI |
| 63 | +- **Animations** — `motion/react` spring physics for entrance/exit transitions on the game board and modals |
| 64 | +- **CSS Modules** — Scoped styles, zero class name collisions |
60 | 65 |
|
61 | | -- **Unit Testing:** Individual components like `Card.js` and `TimerBoard.js` are tested in isolation to ensure they render props correctly and fire events as expected. |
62 | | -- **Integration Testing:** `App.test.js` simulates full user flows—starting the game, clicking cards, and triggering game-over states—to verify component interaction. |
63 | | -- **Mocking:** |
64 | | - - **Audio API:** The `GameSounds.js` class is fully mocked in `src/__mocks__/GameSounds.js` to prevent audio playback issues in the test environment. |
65 | | - - **Fetch API:** Global `fetch` is mocked to simulate API responses for deterministic testing of the `CardContainer`. |
66 | | -- **Coverage:** The pipeline enforces high test coverage, runnable via `npm run test:coverage`. |
| 66 | +### 4. Testing |
67 | 67 |
|
68 | | ---- |
| 68 | +- Unit tests for isolated components (`Card`, `TimerBoard`, `ScoreBoard`) |
| 69 | +- Integration tests in `App.test.js` covering full user flows — start game, card clicks, Game Over |
| 70 | +- `GameSounds.js` fully mocked in `src/__mocks__/`; global `fetch` mocked for deterministic API tests |
| 71 | +- Coverage enforced in CI via `npm run test:coverage` |
69 | 72 |
|
70 | | -## ⚙️ CI, Quality Assurance & Deployment |
| 73 | +### 5. CI Pipeline |
71 | 74 |
|
72 | | -Code quality is enforced via a strict **GitHub Actions** pipeline defined in `.github/workflows/ci.yml`. No code reaches production without passing these gates: |
| 75 | +Every push and PR must pass `.github/workflows/ci.yml` before merging: |
73 | 76 |
|
74 | | -1. **Dependency Installation:** Ensures a clean slate using `npm install --legacy-peer-deps`. |
75 | | -2. **Linting:** Runs `npm run lint` (ESLint) to catch static errors and enforce coding standards. |
76 | | -3. **Formatting:** Runs `npm run format:check` (Prettier) to ensure stylistic consistency. |
77 | | -4. **Test Suite:** Executes `npm run test:coverage` to verify business logic and prevent regressions. |
78 | | -5. **Deployment (GitHub Pages):** Utilizes `gh-pages` for controlled manual deployments. This leverages GitHub's native ecosystem to securely and freely host the static React build, ensuring only fully-tested code reaches production. |
| 77 | +- ESLint → Prettier format check → Jest coverage → coverage report uploaded as CI artifact |
79 | 78 |
|
80 | | ---- |
| 79 | +## Tech Stack |
81 | 80 |
|
82 | | -## 🚀 Setup Instructions |
| 81 | +| Category | Technology | Usage | |
| 82 | +| :----------------- | :---------------------------- | :------------------------------------------------------------------------------------ | |
| 83 | +| **Core Framework** | **React 19** | Class-Based Components, lifecycle methods | |
| 84 | +| **Bundler** | **Create React App** | Build tooling; intentionally chosen over Vite for CRA + class component compatibility | |
| 85 | +| **Language** | **JavaScript (ES6+)** | Class architecture, `this` binding | |
| 86 | +| **Styling** | **CSS Modules** | Scoped styles, zero collisions | |
| 87 | +| **Animation** | **Motion (`motion/react`)** | Spring physics, entrance/exit animations | |
| 88 | +| **Audio** | **Web Audio API** | Custom `GameSounds` class for SFX and BGM | |
| 89 | +| **Testing** | **Jest + RTL** | Unit and integration tests | |
| 90 | +| **Code Quality** | **ESLint + Prettier + Husky** | Pre-commit and CI enforcement | |
| 91 | +| **CI** | **GitHub Actions** | Lint → Format → Test → Coverage artifact | |
| 92 | +| **Hosting** | **GitHub Pages** | Manual deployment via `npm run deploy` | |
83 | 93 |
|
84 | | -Follow these steps to run the application locally. |
| 94 | +## Setup Instructions |
85 | 95 |
|
86 | 96 | ### Prerequisites |
87 | 97 |
|
88 | | -- Node.js (v18 or v20 recommended) |
| 98 | +- Node.js v18 or v20 |
89 | 99 | - npm |
90 | 100 |
|
91 | | -### Installation |
92 | | - |
93 | | -1. **Clone the repository:** |
94 | | - |
95 | | - ```bash |
96 | | - git clone https://github.com/umarSiddique010/rick-morty-game-react.git |
97 | | - |
98 | | - cd rick-morty-game-react |
99 | | - ``` |
| 101 | +### 1. Clone & Install |
100 | 102 |
|
101 | | -2. **Install dependencies:** |
102 | | - _Note: The project uses React 19 with some legacy dependencies._ |
103 | | - |
104 | | - ```bash |
105 | | - npm install --legacy-peer-deps |
106 | | - ``` |
| 103 | +```bash |
| 104 | +git clone https://github.com/umarSiddique010/rick-morty-game-react.git |
| 105 | +cd rick-morty-game-react |
| 106 | +npm install --legacy-peer-deps |
| 107 | +``` |
107 | 108 |
|
108 | | -3. **Start the development server:** |
| 109 | +> `--legacy-peer-deps` is required — CRA has peer dependency conflicts with React 19. |
109 | 110 |
|
110 | | - ```bash |
111 | | - npm start |
112 | | - ``` |
| 111 | +### 2. Run |
113 | 112 |
|
114 | | -4. **Run Quality Checks** |
| 113 | +```bash |
| 114 | +npm start |
| 115 | +``` |
115 | 116 |
|
116 | | - ```bash |
117 | | - # Run Linter |
118 | | - npm run lint |
| 117 | +Open [http://localhost:3000](http://localhost:3000). |
119 | 118 |
|
120 | | - # Check Formatting |
121 | | - npm run format:check |
| 119 | +### 3. Quality Checks |
122 | 120 |
|
123 | | - # Run Test Suite with Coverage |
124 | | - npm run test:coverage |
125 | | - ``` |
| 121 | +```bash |
| 122 | +npm run lint |
| 123 | +npm run format:check |
| 124 | +npm run test:coverage |
| 125 | +``` |
126 | 126 |
|
127 | | -### Development Commands |
| 127 | +### 4. Deploy to GitHub Pages |
128 | 128 |
|
129 | | -| Command | Description | |
130 | | -| :---------------------- | :----------------------------------------------------------- | |
131 | | -| `npm start` | Runs the app in development mode at `http://localhost:3000`. | |
132 | | -| `npm run test` | Launches the test runner in interactive watch mode. | |
133 | | -| `npm run test:coverage` | Runs tests once and generates a coverage report. | |
134 | | -| `npm run lint` | Checks the codebase for linting errors. | |
135 | | -| `npm run format` | Auto-formats code using Prettier. | |
| 129 | +```bash |
| 130 | +npm run deploy |
| 131 | +``` |
136 | 132 |
|
137 | | ---- |
| 133 | +> This runs `npm run build` then pushes the build to the `gh-pages` branch. Deployment is manual — run this only after all quality checks pass. |
138 | 134 |
|
139 | | -## 📂 Project Structure |
| 135 | +## Project Structure |
140 | 136 |
|
141 | | -```text |
| 137 | +``` |
142 | 138 | src/ |
143 | | -├── __mocks__/ # Jest mocks for GameSounds and Audio |
144 | | -├── __test__/ # Comprehensive test suite (Unit & Integration) |
145 | | -├── assets/ # Fonts, Images, and Wallpapers |
| 139 | +├── __mocks__/ # Jest mock for GameSounds and Audio API |
| 140 | +├── __test__/ # Full test suite (Unit & Integration) |
| 141 | +├── assets/ # Fonts, images, wallpaper |
146 | 142 | ├── Components/ |
147 | | -│ ├── Card/ # Individual Memory Card component |
148 | | -│ ├── CardContainer/ # Grid layout and API fetching logic |
149 | | -│ ├── GameOver/ # Game Over modal with score summary |
150 | | -│ ├── PlayGame/ # Main game orchestrator |
151 | | -│ ├── ScoreBoard/ # HUD for Score, High Score, and Cards Left |
152 | | -│ ├── SoundToggleButton/# Global audio control |
153 | | -│ ├── StartGame/ # Landing page and Level selection |
154 | | -│ └── TimerBoard/ # Countdown timer logic |
155 | | -├── App.js # Root Component & State Container |
156 | | -├── GameSounds.js # Audio Class for SFX and BGM management |
157 | | -├── index.css # Global variables and resets |
158 | | -└── setupTests.js # Jest configuration |
| 143 | +│ ├── Card/ # Individual memory card |
| 144 | +│ ├── CardContainer/ # Card grid + API fetching |
| 145 | +│ ├── GameOver/ # Game Over modal |
| 146 | +│ ├── PlayGame/ # Main game orchestrator |
| 147 | +│ ├── ScoreBoard/ # Score, high score, cards left HUD |
| 148 | +│ ├── SoundToggleButton/ # Global mute control |
| 149 | +│ ├── StartGame/ # Landing page and difficulty selection |
| 150 | +│ └── TimerBoard/ # Countdown timer |
| 151 | +├── App.js # Root component and state container |
| 152 | +├── GameSounds.js # Audio class: SFX and BGM |
| 153 | +└── index.css # Global CSS variables and resets |
159 | 154 | ``` |
160 | 155 |
|
161 | 156 | --- |
162 | 157 |
|
163 | | -## 🤝 Contributing |
164 | | - |
165 | | -Contributions are welcome! Please follow these steps: |
166 | | - |
167 | | -1. Fork the repository. |
168 | | -2. Create a feature branch (`git checkout -b feature/AmazingFeature`). |
169 | | -3. Commit your changes (`git commit -m 'Add some AmazingFeature'`). |
170 | | -4. Push to the branch (`git push origin feature/AmazingFeature`). |
171 | | -5. Open a Pull Request. |
172 | | - |
173 | | -## 📝 License |
174 | | - |
175 | | -Distributed under the MIT License. See `LICENSE` for more information. |
| 158 | +<div align="center"> |
176 | 159 |
|
177 | | ---- |
| 160 | +### Developer & Maintainer |
178 | 161 |
|
179 | | -<div align="center"> |
180 | | - <p><strong>Developed by Md Umar Siddique</strong></p> |
| 162 | +**Md Umar Siddique** |
181 | 163 |
|
182 | | - <a href="https://www.linkedin.com/in/md-umar-siddique-1519b12a4/"> |
183 | | - <img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn" /> |
184 | | - </a> |
185 | | - <a href="https://www.npmjs.com/~umarSiddique010"> |
186 | | - <img src="https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white" alt="NPM" /> |
| 164 | +<p align="center"> |
| 165 | + <a href="https://www.umarsiddique.dev/"> |
| 166 | + <img src="https://img.shields.io/badge/Portfolio-umarsiddique.dev-000000?style=flat-square&logo=googlechrome&logoColor=white" alt="Portfolio Website" /> |
187 | 167 | </a> |
188 | | - <a href="https://dev.to/umarsiddique010"> |
189 | | - <img src="https://img.shields.io/badge/DEV.to-0A0A0A?style=for-the-badge&logo=dev.to&logoColor=white" alt="DEV Community" /> |
| 168 | + <a href="https://www.linkedin.com/in/md-umar-siddique-1519b12a4/"> |
| 169 | + <img src="https://img.shields.io/badge/LinkedIn-0077B5?style=flat-square&logo=linkedin&logoColor=white" alt="LinkedIn" /> |
190 | 170 | </a> |
191 | 171 | <a href="https://github.com/umarSiddique010"> |
192 | | - <img src="https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white" alt="GitHub" /> |
| 172 | + <img src="https://img.shields.io/badge/GitHub-181717?style=flat-square&logo=github&logoColor=white" alt="GitHub" /> |
193 | 173 | </a> |
194 | | - <a href="mailto:us70763@gmail.com"> |
195 | | - <img src="https://img.shields.io/badge/Email-D14836?style=for-the-badge&logo=gmail&logoColor=white" alt="Email" /> |
| 174 | + <a href="https://www.npmjs.com/~umarsiddique010"> |
| 175 | + <img src="https://img.shields.io/badge/NPM-CB3837?style=flat-square&logo=npm&logoColor=white" alt="NPM" /> |
| 176 | + </a> |
| 177 | + <a href="https://dev.to/umarsiddique010"> |
| 178 | + <img src="https://img.shields.io/badge/Dev.to-0A0A0A?style=flat-square&logo=dev.to&logoColor=white" alt="Dev.to" /> |
196 | 179 | </a> |
| 180 | + <a href="mailto:us70763@gmail.com"> |
| 181 | + <img src="https://img.shields.io/badge/Email-D14836?style=flat-square&logo=gmail&logoColor=white" alt="Email" /> |
| 182 | +</a> |
| 183 | +</p> |
197 | 184 |
|
198 | | -<br/><br/> |
| 185 | +© 2024 - Present. Released under the MIT License. |
199 | 186 |
|
200 | | - <p> |
201 | | - <strong>Project Links:</strong> |
202 | | - <a href="https://umarsiddique010.github.io/rick-morty-game-react/">🚀 Live Demo</a> • |
203 | | - <a href="https://github.com/umarSiddique010/rick-morty-game-react/issues">🐞 Report an Issue</a> • |
204 | | - <a href="https://github.com/umarSiddique010/rick-morty-game-react">⭐ Star this Repo</a> |
205 | | - </p> |
206 | 187 | </div> |
0 commit comments