joonshakya / turborepo-trpc-fastify-prisma-expo-react-navigation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

turborepo-trpc-fastify-prisma-expo-react-navigation

Installation

To initialize this turborepo, you can use Turbo's CLI. Use PNPM as package manager:

npx create-turbo@latest -e https://github.com/joonshakya/turborepo-trpc-fastify-prisma-expo-react-navigation

About

This is my template to create a fullstack typescript mobile application using Expo, React Navigation, tRPC, Fastify and Prisma.

It uses Turborepo and contains:

.vscode
  └─ Recommended extensions and settings for VSCode users
apps
  ├─ db
  |   └─ Typesafe db calls using Prisma
  ├─ expo
  |   ├─ Expo SDK 49
  |   ├─ React Native 0.72.6 using React 18
  |   ├─ Navigation using React Navigation v6
  |   ├─ Tailwind using Nativewind
  |   └─ Typesafe API calls using tRPC
  └─ server
      ├─ Standalone tRPC server using Fastify
      └─ Transpilation to JS using esbuild
tooling
  ├─ eslint
  |   └─ shared, fine-grained, eslint presets
  ├─ prettier
  |   └─ shared prettier configuration
  ├─ tailwind
  |   └─ shared tailwind configuration
  └─ typescript
      └─ shared tsconfig you can extend from

In this template, we use @acme as a placeholder for package names. As a user, you might want to replace it with your own organization or project name. You can use find-and-replace to change all the instances of @acme to something like @my-company or @project-name.

Quick Start

To get it running, follow the steps below:

1. Setup dependencies

# Install dependencies
pnpm i

# Configure environment variables
# There is an `.env.example` in the root directory you can use for reference
cp .env.example .env

# Push the Prisma schema to the database
pnpm db:push

2. When it's time to add a new package

To add a new package, simply run pnpm turbo gen init in the monorepo root. This will prompt you for a package name as well as if you want to install any dependencies to the new package (of course you can also do this yourself later).

The generator sets up the package.json, tsconfig.json and a index.ts, as well as configures all the necessary configurations for tooling around your package such as formatting, linting and typechecking. When the package is created, you're ready to go build out the package.

FAQ

Does this pattern leak backend code to my client applications?

No, it does not. The server package should only be a production dependency in the Expo application where it's served. All other apps you may add in the future, should only add the server package as a dev dependency. This lets you have full typesafety in your client applications, while keeping your backend code safe.

If you need to share runtime code between the client and server, such as input validation schemas, you can create a separate shared package for this and import it on both sides.

Deployment

tRPC Fastify Server

To deploy the fastify server you just need to modify the DATABASE_URL variable in .env to point to your database's production URL and run the following command:

pnpm serve

Expo

To deploy the app you need to submit production builds of your app to app stores, like Apple App Store and Google Play. You can read the full guide to distributing your app, including best practices, in the Expo docs.

  1. Make sure to modify the apiUrl variable in \apps\expo\src\config\settings.ts to point to your backend's production URL.

  2. Let's start by setting up EAS Build, which is short for Expo Application Services. The build service helps you create builds of your app, without requiring a full native development setup. The commands below are a summary of Creating your first build.

    # Install the EAS CLI
    pnpm add -g eas-cli
    
    # Log in with your Expo account
    eas login
    
    # Configure your Expo app
    cd apps/expo
    eas build:configure
  3. After the initial setup, you can create your first build. You can build for Android and iOS platforms and use different eas.json build profiles to create production builds or development, or test builds. Let's make a production build for iOS.

    eas build --platform ios --profile production

    If you don't specify the --profile flag, EAS uses the production profile by default.

  4. Now that you have your first production build, you can submit this to the stores. EAS Submit can help you send the build to the stores.

    eas submit --platform ios --latest

    You can also combine build and submit in a single command, using eas build ... --auto-submit.

  5. Before you can get your app in the hands of your users, you'll have to provide additional information to the app stores. This includes screenshots, app information, privacy policies, etc. While still in preview, EAS Metadata can help you with most of this information.

  6. Once everything is approved, your users can finally enjoy your app. Let's say you spotted a small typo; you'll have to create a new build, submit it to the stores, and wait for approval before you can resolve this issue. In these cases, you can use EAS Update to quickly send a small bugfix to your users without going through this long process. Let's start by setting up EAS Update.

    The steps below summarize the Getting started with EAS Update guide.

    # Add the `expo-updates` library to your Expo app
    cd apps/expo
    pnpm expo install expo-updates
    
    # Configure EAS Update
    eas update:configure
  7. Before we can send out updates to your app, you have to create a new build and submit it to the app stores. For every change that includes native APIs, you have to rebuild the app and submit the update to the app stores. See steps 2 and 3.

  8. Now that everything is ready for updates, let's create a new update for production builds. With the --auto flag, EAS Update uses your current git branch name and commit message for this update. See How EAS Update works for more information.

    cd apps/expo
    eas update --auto

    Your OTA (Over The Air) updates must always follow the app store's rules. You can't change your app's primary functionality without getting app store approval. But this is a fast way to update your app for minor changes and bug fixes.

  9. Done! Now that you have created your production build, submitted it to the stores, and installed EAS Update, you are ready for anything!

References

The stack originates from create-t3-turbo.

About

License:MIT License


Languages

Language:TypeScript 91.2%Language:JavaScript 7.9%Language:Handlebars 0.9%