A feature-rich shopping basket application built with React Native and JavaScript, showcasing modern development practices. The project emphasizes component-based architecture using the Atomic Design methodology, ensuring modularity, scalability, and maintainability. With a strong focus on testing, it integrates unit testing using Jest and UI testing with the React Native Testing Library. This app demonstrates best practices in React Native development, including robust state management, credit card validation, and continuous integration workflows powered by GitHub Actions.
- Demo
- Visuals
- Core Features
- Development Standards
- Folder Structure
- Tech Stack
- Atomic Web Design
- Credit Card Validation
- Installation
- Testing
- Continuous Integration
- Contributing
- License
- Contact
Watch the app in action:
Click the image above to view the demo video.
- β DONE
- π’ IN PROGRESS
- π‘ TODO
-
Product List View
- β Display products with details.
- β Add items to the basket, with a maximum quantity of 5 per item.
- β Disable the "Add" button when the limit is reached and show a message on the product card.
- β Display total items in the basket.
- β Navigate to the Basket Checkout View if at least one item is in the basket.
- β Show a message if no products are available.
-
Basket Checkout View
- β Display basket items with quantities and prices.
- β Calculate and display the total price.
- β
Apply discounts using promo codes (e.g.,
A10
for 10% off,A80
for 80% off). - β
Validate promo codes via API, update the total, and display appropriate messages:
- β Empty basket message.
- β Invalid promo code message.
- βοΈ Successful promo code application message.
- β Allow removing items from the basket.
- β Navigate to the Payment View if at least one item is in the basket.
-
Payment View
- β Secure payment form with credit card validation and error messages.
- β
Navigate to:
- βοΈ Success Screen on successful payment.
- β Error Screen on failed payment.
-
Payment Result Views
- β Success Screen: Features a progress bar animation.
- β Error Screen: Displays error details with a progress bar animation.
-
UX/UI
- β Supports light and dark themes.
- β Design inspired by the Amazon app (for the light theme).
- β Component structure based on Atomic Web Design principles.
- β
Component-Based Architecture: Implements the Atomic Design methodology, organizing components into
atoms
,molecules
,organisms
,templates
, andscreens
to ensure modularity, scalability, reusability, testability, and maintainability. - β
Centralized Components: Core components are built in the
atoms
folder and reused across the application. - β Folder Organization: Test and style files are colocated with their respective components for better maintainability.
- β Styling: Inline styles are avoided; constants like colors, fonts, and spacing are defined in a centralized theme file.
- β Functional Components: All components use a functional programming approach.
- β
Performance Optimization: Utilize
useMemo
anduseCallback
to prevent unnecessary re-renders, validated with "why-did-you-render."
- β
Linting & Formatting:
- Enforce error-free commits using Husky and lint-staged.
- Ensure valid commit messages with Commitlint.
- β
Testing Standards:
- Maintain a minimum of 90% test coverage across branches, functions, lines, and statements to ensure high code quality.
- Use
--findRelatedTests
in pre-commit hooks to run only tests relevant to changed files, improving efficiency.
- β
API Mocking: Use
mock-service-worker
to mock API calls and responses, ensuring reliable and consistent testing without depending on live backend services.
- β
Form Validation: Manage forms efficiently and robustly using
react-hook-form
. - β
State Management: Leverage Redux Toolkit for centralized state management and
rtk-query
for API data fetching. - β Context API: Implement Context API for managing global state effectively.
- β
Validation Utilities: Include reusable validation utilities in a dedicated
validate
folder. - β Custom Hooks: Develop custom hooks to encapsulate shared logic and state management.
- β Path Aliases: Simplify import paths with aliases for improved readability.
- β Folder Structure: Adheres to a well-organized structure to ensure maintainability. See the Folder Structure section for details.
- β Continuous Integration: Automated testing, validation, and coverage updates are handled through GitHub Actions. Refer to the Continuous Integration section for details.
Here is the folder structure for key parts of the project:
βββ assets/ # Images, fonts, and static assets
βββ badges/ # Test coverage badges
βββ src/ # Application source code
βββ __tests__/ # Test files
β βββ mocks/ # Mock data for tests
β βββ utils/ # Test utility functions
βββ ...
src/
βββ components/ # Reusable UI components
β βββ atoms/ # Small building blocks of UI
β β βββ Button/
β β β βββ index.js
β β β βββ Button.style.js
β β β βββ Button.test.js
β β βββ index.js # Exports for atoms
β β βββ ...
β βββ molecules/ # Combined components (atoms + logic)
β β βββ index.js # Exports for molecules
β βββ ...
β βββ organisms/ # Complex reusable components
β β βββ index.js # Exports for organisms
β βββ ...
β βββ templates/ # Reusable layout components
β βββ index.js # Exports for templates
β βββ ...
βββ screens/ # Application screens
β βββ ProductListScreen/
β β βββ index.js
β β βββ ProductListScreen.style.js
β β βββ ProductListScreen.test.js
β βββ SuccessScreen/
β β βββ index.js
β β βββ SuccessScreen.style.js
β β βββ SuccessScreen.test.js
β βββ index.js # Exports for screens
β βββ ...
βββ redux/ # State management logic
βββ constants/ # Application constants (e.g., themes, URLs)
β βββ index.js # Exports for constants
βββ utils/ # Helper functions and utilities
βββ context/ # Context API files
βββ validate/ # Validation utilities
β βββ index.js # Exports for validate
βββ ...
- React Native: Core development framework.
- Expo: Quick setup and development environment.
- Redux Toolkit: State Management with rtk query.
react-hook-form
: Form Management easy and efficient.- Testing: Jest,
@testing-library/react-native
,mock-service-worker
mock-service-worker
: Mock backend for development environment and mock API calls for testing.- UI Components: React Native Paper, custom components.
- Performance Optimization:
useCallback
,useMemo
. - Code Quality: ESLint, Prettier, Husky, Commitlint.
-
This app follows the Atomic Web Design methodology, which structures UI components into five hierarchical
categories:
Atoms, Molecules, Organisms, Templates, and Pages(or Screens in terms of mobile).
-
Explore Components
Visit the Components Folder to see reusable UI elements organized by this structure. -
Learn More About Atomic Design
Dive deeper into the methodology by reading the official guide by Brad Frost: Atomic Design Principles.
- Reusability: Create small, reusable components and combine them into complex designs.
- Scalability: Build a consistent and maintainable design system as the app grows.
- Separation of Concerns: Clearly delineate the responsibilities of each layer in your UI hierarchy.
- VALID card number: 5566561551349323
- INVALID card number: 1234567890123456
- VALID according to Luhn algoritm but mock-server-worker adjusted to always generate an error response (a failed transaction): 5249045959484101
- Generate dummy card numbers with Credit Card Generator
-
Clone the repository:
git clone https://github.com/abdullahbayram/shopping-basket-rn-js.git cd shopping-basket
-
Install dependencies:
npm install
-
Start the app:
npx expo start
To ensure the robustness of the application, the following testing strategies and practices are implemented:
β
Unit Testing: All components and utility functions are covered with unit tests to ensure correctness of
individual units of code.
β
Integration Testing: Critical workflows, such as adding items to the basket, applying promo codes, and
navigating between screens, are tested to validate seamless interaction between components.
β
Code Coverage: Coverage reports are generated with Jest, with a minimum(%90) threshold enforced to maintain
code
quality.
To run the tests:
npm test
Run the tests with coverage:
npm test -- --coverage
Test coverage reports are automatically generated in the coverage
directory for review.
This project leverages GitHub Actions to automate testing, validation, and coverage updates.
- Trigger: Runs on every
pull_request
targeting themain
branch. - Steps:
- Checkout repository and set up Node.js environment.
- Install dependencies.
- Run
npm run validate:pr
to ensure project-specific validations.
- Trigger: Executes on every
push
to themain
branch. - Steps:
- Generate or update test coverage reports.
- Commit and push updated coverage badges and summary to the repository.
- Minimum global test coverage enforced by Jest:
- Branches: 90%
- Functions: 90%
- Lines: 90%
- Statements: 90%
- Pull requests must meet these thresholds before merging.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/new-feature
). - Open a pull request.
Make sure your code adheres to the projectβs linting and testing standards. Additionally, provide clear documentation for any new features.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to reach out via email at [email protected]