create-nova-expo-template
Version:
A template for creating a new React Native app using Expo and TypeScript, with a focus on performance and best practices.
434 lines (352 loc) ⢠14.9 kB
Markdown
# š Your Nova Expo App
A modern React Native application built with Expo 57, featuring a comprehensive development setup with TypeScript, navigation, state management, internationalization, and atomic design components.
## š Table of Contents
- [⨠Features](#-features)
- [š ļø Installation](#ļø-installation)
- [āļø Prerequisites](#ļø-prerequisites)
- [š Usage](#-usage)
- [šļø Project Structure](#ļø-project-structure)
- [šØ Component Architecture](#-component-architecture)
- [š API Integration](#-api-integration)
- [š Internationalization](#-internationalization)
- [š§ Development Scripts](#-development-scripts)
- [š± Building for Production](#-building-for-production)
- [š¤ Contributing](#-contributing)
- [š License](#-license)
## ⨠Features
- **[React Native](https://reactnative.dev/)**: A framework for building native apps using React.
- **[Expo](https://expo.dev/)**: A framework and platform for universal React applications.
- **[TypeScript](https://www.typescriptlang.org/)**: A strongly typed programming language that builds on JavaScript.
- **[Expo Router](https://docs.expo.dev/routing/introduction/)**: File-based routing for React Native and web.
- **[Redux Toolkit](https://redux-toolkit.js.org/)**: A toolset for efficient Redux development.
- **[RTK Query](https://redux-toolkit.js.org/rtk-query/overview)**: Powerful data fetching and caching tool.
- **[React Toastify](https://fkhadra.github.io/react-toastify/)**: Easy-to-use toast notifications.
- **[React-i18next](https://react.i18next.com/)**: Internationalization for React Native.
- **[Day.js](https://day.js.org/)**: A lightweight JavaScript date library.
- **[Flashlist](https://shopify.github.io/flash-list/)**: A performant list component for React Native.
- **[React Hook Form](https://react-hook-form.com/)**: Performant, flexible, and extensible forms with easy-to-use validation.
- **[Atomic Design System](https://bradfrost.com/blog/post/atomic-web-design/)**: A methodology for creating design systems.
- **[Biometric Authentication](https://docs.expo.dev/versions/latest/sdk/local-authentication/)**: Fingerprint and face recognition support.
- **[Sentry Integration](https://sentry.io/)**: Error monitoring and performance tracking.
- **Dark/Light Theme Support**: Built-in theme switching capability.
- **Custom Hooks**: Pre-built hooks for common functionality.
- **Development Scripts**: Automated tools for SVG generation, translation management, and more.
## š ļø Installation
1. Install dependencies:
```bash
npm install
```
2. Start the development server:
```bash
npm start
```
## āļø Prerequisites
Ensure you have the following installed:
- **Node.js**: v16.14.0 or higher
- **npm**: v8.5.0 or higher
- **Expo CLI**: Latest version
- **iOS Simulator** (for iOS development)
- **Android Studio** (for Android development)
## š Usage
### Development Commands
- **Start the development server:**
```bash
npm start
```
- **Run on Android:**
```bash
npm run android
```
- **Run on iOS:**
```bash
npm run ios
```
- **Run on Web:**
```bash
npm run web
```
- **Type checking:**
```bash
npm run type-check
```
### Development Scripts
- **Generate SVG components:**
```bash
npm run generate-svg
```
- **Sync translations:**
```bash
npm run sync-translations
```
- **Auto-translate content:**
```bash
npm run translate
```
- **Remove console logs for production:**
```bash
npm run remove-logs
```
- **Remove console logs for production:**
```bash
npm run remove-logs
```
## šļø Project Structure
```
your-app-name/ # Your new Expo app
āāā š app.json # Expo app configuration
āāā š eas.json # EAS Build configuration
āāā š expo-env.d.ts # Expo environment types
āāā š package.json # Project dependencies
āāā š tsconfig.json # TypeScript configuration
ā
āāā š @types/ # Global TypeScript definitions
ā āāā š static-files.d.ts # Static file types
ā āāā š TranslationKeyEnum.ts # Translation key enums
ā
āāā š apis/ # API layer
ā āāā š Domain.ts # API domain configuration
ā āāā š index.ts # API exports
ā āāā š tagTypes.ts # RTK Query tag types
ā āāā š @types/ # Shared API type definitions
ā āāā š middlewares/ # API middlewares
ā āāā š services/ # API service endpoints (one folder per feature)
ā
āāā š app/ # App routing (Expo Router)
ā āāā š _layout.tsx # Root layout
ā āāā š +not-found.tsx # 404 page
ā āāā š index.tsx # Home/Landing page
ā āāā š (auth)/ # Authentication stack
ā ā āāā š _layout.tsx # Auth layout
ā ā āāā š forgotPassword/ # Password reset screens
ā ā āāā š login/ # Login screens
ā ā āāā š signup/ # Registration screens
ā ā āāā š welcome/ # Welcome/onboarding
ā āāā š (main)/ # Main app stack
ā āāā š _layout.tsx # Main layout
ā āāā š (tabs)/ # Tab navigation
ā āāā š screen1/ # Feature screens
ā āāā š screen2/
ā āāā š screen3/
ā
āāā š assets/ # Static assets
ā āāā š fonts/ # Custom fonts
ā āāā š icons/ # Icon components
ā āāā š images/ # Image assets
ā āāā š svgs/ # SVG components
ā
āāā š components/ # UI Components (Atomic Design)
ā āāā š atoms/ # Basic building blocks
ā ā āāā š Button/ # Button component
ā ā āāā š Input/ # Input component
ā ā āāā š Text/ # Text component
ā ā āāā š index.ts # Atom exports
ā āāā š molecules/ # Component combinations
ā ā āāā š common/ # Shared molecules
ā ā āāā š scoped/ # Feature-specific molecules
ā āāā š organisms/ # Complex components
ā ā āāā š common/ # Shared organisms
ā ā āāā š scoped/ # Feature-specific organisms
ā āāā š templates/ # Page templates
ā āāā š wrappers/ # Higher-order components
ā
āāā š constants/ # App constants
ā āāā š Colors.ts # Color palette
ā āāā š FontFamily.ts # Font definitions
ā āāā š GlobalStyles.ts # Global styles
ā āāā š Metrics.ts # Screen dimensions
ā āāā š TranslationConfig.ts # i18n configuration
ā
āāā š hooks/ # Custom React hooks
ā āāā š useBiometricLogin.tsx # Biometric authentication
ā āāā š useColorScheme.ts # Theme management
ā āāā š useFetchTranslation.ts # Localization hook
ā āāā š useThemeColor.ts # Color theme hook
ā
āāā š locale/ # Internationalization
ā āāā š ar.json # Arabic translations
ā āāā š en.json # English translations
ā āāā š index.ts # i18n exports
ā
āāā š redux/ # State management
ā āāā š index.ts # Store configuration
ā āāā š appReducer.ts # App state slice
ā āāā š authReducer.ts # Auth state slice
ā
āāā š scripts/ # Development scripts
ā āāā š generate-svg.js # SVG component generator
ā āāā š removeLogs.js # Production log removal
ā āāā š sync-translations.js # Translation sync
ā āāā š translate.js # Auto-translation tool
ā
āāā š styles/ # Global styles
ā
āāā š utils/ # Utility functions
āāā š debounce.ts # Debounce utility
āāā š handleErrors.ts # Error handling
āāā š loginHandler.ts # Authentication helpers
āāā š showSuccessMsg.ts # Success messaging
```
### š Key Directories Explained
- **`app/`**: Uses Expo Router for file-based routing with layout components
- **`components/`**: Follows Atomic Design methodology (atoms ā molecules ā organisms ā templates)
- **`apis/`**: Centralized API layer with RTK Query for data fetching and caching
- **`redux/`**: State management using Redux Toolkit with separate slices
- **`hooks/`**: Custom React hooks for reusable logic
- **`constants/`**: App-wide constants including colors, fonts, and metrics
- **`locale/`**: Multi-language support with JSON translation files
- **`utils/`**: Helper functions and utilities
- **`scripts/`**: Development automation scripts
## šØ Component Architecture
This template follows the **Atomic Design** methodology:
### Atoms (`components/atoms/`)
Basic building blocks like buttons, inputs, and text components.
```tsx
import { Button } from '@/components/atoms';
<Button variant="primary" onPress={handlePress}>
Click me
</Button>
```
### Molecules (`components/molecules/`)
Simple combinations of atoms that work together.
```tsx
import { SearchInput } from '@/components/molecules/common';
<SearchInput onSearch={handleSearch} placeholder="Search..." />
```
### Organisms (`components/organisms/`)
Complex components made up of molecules and atoms.
```tsx
import { UserProfile } from '@/components/organisms/common';
<UserProfile user={currentUser} onEdit={handleEdit} />
```
### Templates (`components/templates/`)
Page-level components that define layout structure.
## š API Integration
The template includes a pre-configured API layer using RTK Query:
### Setting up your API
1. Configure your API domain in `apis/Domain.ts`
2. Define each feature's endpoints in `apis/services/<feature>/index.ts`
3. Co-locate that feature's request/response types in `apis/services/<feature>/types.ts`
(cross-cutting types like `PaginatedResponse` stay in `apis/@types/`)
> Tip: scaffold the whole layer with `npx plop create <Name> integration`.
### Example API Service
```tsx
// apis/services/user/types.ts
export interface User {
id: number;
name: string;
}
```
```tsx
// apis/services/user/index.ts
import api from '@/apis';
import { User } from './types';
export const userApi = api.injectEndpoints({
endpoints: (builder) => ({
getUser: builder.query<User, number>({
query: (id) => `users/${id}`,
}),
updateUser: builder.mutation<User, { id: number } & Partial<User>>({
query: ({ id, ...patch }) => ({
url: `users/${id}`,
method: 'PATCH',
body: patch,
}),
}),
}),
});
export const { useGetUserQuery, useUpdateUserMutation } = userApi;
```
## š Internationalization
### Adding Translations
1. Add your translations to `locale/en.json` and `locale/ar.json`
2. Use the `useTranslation` hook in your components
```tsx
import { useTranslation } from 'react-i18next';
const MyComponent = () => {
const { t } = useTranslation();
return <Text>{t('welcome.title')}</Text>;
};
```
### Auto-translation
Use the built-in script to automatically translate your content:
```bash
npm run translate
```
## š§ Development Scripts
### SVG Component Generation
Automatically generate React components from SVG files:
```bash
npm run generate-svg
```
Place your SVG files in `assets/svgs/` and run the script to generate typed React components.
### Translation Management
Sync translations across different language files:
```bash
npm run sync-translations
```
### Production Optimization
Remove console logs for production builds:
```bash
npm run remove-logs
```
## š± Building for Production
### Using EAS Build
```bash
# Install EAS CLI
npm install -g @expo/eas-cli
# Configure EAS
eas build:configure
# Build for iOS
eas build --platform ios
# Build for Android
eas build --platform android
# Build for both platforms
eas build --platform all
```
### Local Builds
```bash
# Create production build
expo export
# Preview production build
npx serve dist
```
# Preview production build
npx serve dist
```
## š¤ Contributing
Contributions are welcome! Please follow these steps:
1. Fork the repository
2. Create a new branch for your feature or bug fix:
```bash
git checkout -b feature/your-feature-name
```
3. Make your changes and commit them:
```bash
git commit -m "Add your feature description"
```
4. Push the branch:
```bash
git push origin feature/your-feature-name
```
5. Submit a pull request
### Development Guidelines
- Follow the existing code style and conventions
- Add TypeScript types for all new code
- Update translations when adding new text content
- Test your changes on both iOS and Android
- Write clear commit messages
## š License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## š Acknowledgments
- [Expo](https://expo.dev/) for providing an excellent development platform
- [Redux Toolkit](https://redux-toolkit.js.org/) for simplified state management
- [React Navigation](https://reactnavigation.org/) for routing solutions
- The open-source community for their valuable contributions
## š Additional Resources
- [Expo Documentation](https://docs.expo.dev/)
- [React Native Documentation](https://reactnative.dev/docs/getting-started)
- [TypeScript Documentation](https://www.typescriptlang.org/docs/)
- [Redux Toolkit Documentation](https://redux-toolkit.js.org/)
- [Atomic Design Methodology](https://bradfrost.com/blog/post/atomic-web-design/)
---
**Happy coding! š**