Kaol Stack - Prisma, Expo, Next, TRPC, Solito, Tailwind - A monorepo template for a truly universal app

Overview

Kaol Stack

untitled-project@2x (1)

🔦 About

A monorepo with Prisma, Next.js, Expo, tRPC, Authentication and Solito setup and configured to work together. With this setup you can build a fullstack application with backend, frontend and mobile sharing 99% of the code, with full support for SSR and file structure navigation on nextjs, and full support for react native navigation on expo.

Use this template

To create a repo based on this template:

use this template

?Why

I created this project for a personal need, I wanted something like the create-t3-app, but sharing code between the mobile app and the nextjs app. I could not get any of the available repos on github to work the way I wanted, so I decided to try and put a few of them together and after a few days of banging my head against the wall I finally managed to do it in a good way. There are still a few things I want to do, but it's currently the best universal app monorepo template amongst what I could find.

📦 Included packages

  • Prisma
  • solito for cross-platform navigation
  • moti for animations (basically framer-motion but works in both expo and web)
  • twrnc tailwind for react native
  • Expo SDK 44
  • Next.js 12
  • tRPC 9
  • React Navigation 6
  • Authentication with email/password pre-configured

🗂 Folder layout

  • apps entry points for each app

    • expo
    • next
  • packages/ shared packages across apps

    • app/ this is your main application that's used in both expo and next apps
      • features/ screens of your app, organized by domains/feature
      • provider/ (all the providers that wrap the app, and some no-ops for Web.)
      • navigation/
        • native/ Next.js has a pages/ folder. React Native doesn't. This folder contains react-navigation-related code for RN, you should place yours navigations like StackNavigation, BottomNavigation, etc, here.
          • index.tsx Entrypoint for react-navigation
        • routePaths.tsx - !! IMPORTANT !! Here you setup the route mapping between react-navigation routes and the URLs that they map to in your NextJS app.
    • api/ your trpc api with your routes
    • db/ prisma db with some example models
      • seeds/ Seeds for pre-populating the postgres database in development
    • config/ your environment configs
    • universal/ a place to put your universal components / design system.
      • universal/tailwind exports some tailwind utilities that you will use to make components support tailwind className/tw prop.

You can add other folders inside of packages/ if you know what you're doing and have a good reason to.

🏁 Start the app

Dependencies: You need docker installed and running to be able to run this stack, as the postgres database is in a docker container. If you're on mac or windows, just make sure docker desktop is opened.

  • Install dependencies: yarn

  • Run yarn dev for local development using turbo

  • Or run yarn dev:tabs if you want to run web and mobile on different terminal tabs (needed if want to interact with expo CLI)

  • It will open:

    • Prisma Studio localhost:5555
    • Expo default to iOS simulator
    • Next.js localhost:4000

🆕 Add new dependencies

Pure JS dependencies

If you're installing a JavaScript-only dependency that will be used across platforms, install it in packages/app:

cd packages/app
yarn add date-fns
cd ../..
yarn

Native dependencies

If you're installing a library with any native code, you must install it in apps/expo:

cd apps/expo
yarn add react-native-reanimated

cd ../..
yarn

You can also install the native library inside of packages/app if you want to get autoimport for that package inside of the app folder. However, you need to be careful and install the exact same version in both packages. If the versions mismatch at all, you'll potentially get terrible bugs. This is a classic monorepo issue. I use lerna-update-wizard to help with this (you don't need to use Lerna to use that lib).

IMPORTANT

A lot of libraries aren't transpiled for next by default, so when you add a library make sure to add it to the transpile list in next.config.js, else they will problably not work.

const withTM = require('next-transpile-modules')([
    ...
    // add it here
])

Deploying to production (web and api)

This monorepo is pre-configured to work with vercel. You will need a postgres database, preferably with pgBounger enabled in session mode.

Start the project in vercel

  • Head to vercel.com/new and import your git repo that you created from this template.
  • That's it for now, we'll come back to it later.

Create a free database in supabase

  • Setup a new database in supabase, wait a few minutes until it's fully setup.
  • Head to Settings -> Database
  • Scroll down until you found the section called Connection Pooling
  • Make sure it's ENABLED
  • Change the pool mode to Session
  • Copy the connection string

With that connection string, you will have two environment variabled you need.

First one is the MIGRATION_DB_URL, this will be the connection string you copied above. This will be used during deployment to migrate the db to the latest migration.

Second one is the DATABASE_URL, it will be the same connection string you copied above, but with ?pgbouncer=true&schema=public&connection_limit=1 appended at the end. This is what the app will use, and it's has connection pool enabled, which is a requirement for serverless environments

Setup environment variables in vercel

  • Back to vercel.com, head to your app, then go to Settings -> Environment Variables
  • Add the following environment variables (replace the values with your specific values)
    • Make sure to uncheck Preview and Development, and leave only Production
MIGRATION_DB_URL="postgres://<user>:<password>@<supabase_db_url>:6543/postgres"

DATABASE_URL="postgres://<user>:<password>@<supabase_db_url>:6543/<database>?pgbouncer=true&schema=public&connection_limit=1"

TOKEN_KEY="SOME_VERY_STRONG_SECRET_THAT_WILL_HASH_THE_PASSWORDS"

!! IMPORTANT !!

This will break preview apps because they won't have any databases. If you want them to work you can repeat the same steps above to create a NEW database on supabase, and setup new environment variables only for the Preview environment.

Redeploy the app

After changing the environement variables, you will need to redeploy the app. To do that you need to push a new commit to the repository. You can have an empty commit like this:

git commit --alow-empty -m "redeploy"
git push origin master

Expo

Expo Configuration

When you're ready for staging and production build, you'll need to configure your environment variabled that your Expo app will use. To do that, you can head to packages/app/config.ts, and update the apiUrl for production (and staging, if applicable):

const enviromentConfigs: { [key in UpdateChannel]: IConfig } = {
  development: {
    // Don't touch this
    apiUrl: `http://${localhost}:4000/api/trpc`,
  },
  staging: {
    // Update this to your api url in staging
    apiUrl: 'https://staging-kaol.vercel.app/api/trpc',
  },
  production: {
    // Update this to your api url in production
    apiUrl: 'https://kaol.vercel.app/api/trpc',
  },
}

You should use EAS or Expo Build to build your app and deploy to the stores.

One thing to keep in mind when you are building is that you need to define the release channel as one of the ones defined above (development | preview | staging | production), or update the type definition for extra release channels you may want to use.

!! Attention: Run everything inside apps/expo

With Expo Classic Builds

Build the app

expo prebuild
cd ios
pod install    # Or `arch -x86_64 pod install for mac m1 users`
expo build:ios --release-channel <your-channel>
expo build:android --release-channel <your-channel>

Publish the app to Expo Go

expo publish --release-channel <your-channel>

After this is done, you can preview the app in Expo Go via:

exp://exp.host/@<your-user>/<your-app>?release-channel=<your-channel>

You can see all your release channels by simply opneing the Expo Go app, you don't need to create the url above.

Publish app to app store

Publishing Expo Classic Builds with EAS

With Expo new EAS CLI

EAS CLI is the new default for expo builds. It has a severe disavantage in the fact that you can't publish to expo go for free anymore, so I'd just use expo classic build while possible (but it will be discontinued in the next SDK)

Install the EAS cli

npm install -g eas-cli

Login to your expo account

eas login

Build the app

You can build the app for each release channel by running:

# Building for development (debug)
eas build --profile development

# Building for development (non-debug)
eas build --profile preview

# Building for staging environment
eas build --profile staging

# Building for production environment
eas build --profile production

To publish your production app to the store:

eas submit --profile production

Done

Your are now done, your app should be up and running with authentication working.

🎙 Credits

This setup is heavily inspired on a few projects:

Comments
  • Steps missing for deploying?

    Steps missing for deploying?

    Hi! :) I've tried to use this template but when deploying to Vercel I first get issues with env variables for Prisma. image

    if I push my env variables to the repository as well as Vercel I manage to get it deployed but none of my paths are working.

    I enabled directory listing but I'm relatively new to Next.js (only tried it a bit through Solito) so it didn't make me much wiser. https://gig-hub.vercel.app/

    image

    Are there some steps missing on how I should get this template deployded? I'm looking to move my Solito project to this template but sadly I'm a bit stuck.

    opened by wezter96 4
  • NativeWind instead of twrnc ?

    NativeWind instead of twrnc ?

    Would you consider using NativeWind instead of twrnc for this repo?

    twrnc aka. tailwind-react-native-classnames does its work during runtime, and since it has its own interpreter the repo would need to be maintained in sync with compiler updates in new Tailwind releases.

    NativeWind just uses the Tailwind compiler itself, so is automatically in sync. It also supports the crucial feature: responsive CSS media queries during SSR.

    Further comparison of twrnnc vs. NativeWind, by the NativeWind creator.

    opened by redbar0n 2
  • NextAuth

    NextAuth

    Hi @chamatt, you've done a pretty decent job here. Everything has been working out of the box for me. Sweet!

    You mention in the README that this starter has been inspired by the t3 stack. So I'm wondering why you've decided against using NextAuth and instead roll your own authentication mechanism?

    With the availability of all the providers and adapters, NextAuth has become a no-brainer in many projects.

    Would you consider creating a separate branch with a working NextAuth integration?

    opened by alexthewilde 2
  • Upgrade NextJS to 12.3, Upgrade Expo to SDK46, Add Expo-Router

    Upgrade NextJS to 12.3, Upgrade Expo to SDK46, Add Expo-Router

    • Upgrade NextJS to version 12.3
    • Upgrade Expo SDK to version 46
    • Replace navigation with expo-router. It's still in beta, but whatevs, it makes navigation really similar to NextJS so I added it :D
    opened by chamatt 1
  • Update server and db dependencies

    Update server and db dependencies

    @chamatt A start of trying to bump the app to using latest version of @tanstack/react-query, prisma and tRPC. If I use interop and don't replace the v9 with the v10 stuff I got it to work but as soon as I tried replacing the routers and so on I couldn't get it working.

    It would be highly appreciated if someone could help looking at this.

    opened by wezter96 2
Owner
Matheus Vicente
Software Engineer at Oyster. Computer Engineering Student at UFES.
Matheus Vicente
Prisma +2 generator to emit a tRPC shield from your Prisma schema

Prisma tRPC Shield Generator Automatically generate a tRPC Shield from your Prisma Schema. Updates every time npx prisma generate runs. Table of Conte

Omar Dulaimi 27 Dec 24, 2022
Next.js + tRPC + Blitz.js Auth + Prisma. Fullstack app example

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Daiki Okumura 6 Oct 12, 2022
A NestJS module that allows you use Prisma, set up multiple Prisma services, and use multi-tenancy in each Prisma service.

NestJS Prisma Module Installation To use this package, first install it: npm i @sabinthedev/nestjs-prisma Basic Usage In order to use this package, yo

Sabin Adams 39 Dec 2, 2022
Prisma 2+ generator to emit fully implemented tRPC routers

Prisma tRPC Generator Automatically generate fully implemented tRPC routers from your Prisma Schema. This includes routers, app router and of course a

Omar Dulaimi 370 Jan 3, 2023
A fullstack TikTok clone with Nextjs, Prisma, trpc

TikTok Clone A fullstack TikTok clone with Nextjs, Prisma, trpc Live demo Official website: https://toptop-clone.vercel.app/ Main technology used The

Phong Nguyen 115 Dec 19, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A jquery plugin that makes images truly responsive, without sacrificing anyone's face. Give it more stars!

Responsify.js A jquery plugin that makes images truly responsive, without sacrificing anyone's face :D When images are used in a responsive container

Wenting Zhang 1.3k Dec 14, 2022
Example setup with Solito & Nativewind

Blank Solito Example Monorepo ?? npx create-solito-app@latest my-solito-app ?? View the website ⚡️ Instantly clone & deploy ?? About This monorepo is

Enes 8 Nov 15, 2022
A fullstack next.js template with all the fun stuff like next auth, mongodb, prisma, chakra ui

Welcome to FullStack Next.js template ?? A fullstack next.js template with all the fun stuff like next auth, mongodb, prisma, chakra ui ✨ Demo Tech Ne

Avneesh Agarwal 10 Oct 16, 2022
Remix TypeScript monorepo with Turborepo pipelines, Prisma, PostgreSQL, Docker deploy to Fly.io, pnpm, TailwindCSS and Tsyringe for DI.

Remix template with Turborepo, TypeScript and pnpm. The remix app deploys to fly.io or build to Docker image. Example packages for Database with prisma, Tsyringe dependency injection, UI, and internal TypeScript packages.

Philippe L'ATTENTION 33 Dec 29, 2022
Next.js + Tailwind + Typescript + Prisma + NextAuth starter project

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Steven Tey 106 Jan 3, 2023
End-to-end typed monorepo template for your next project ⌨️

TYPE ⌨️ TRPC + Yarn Monorepo + Prisma + Expo This template project is a Yarn monorepo with full end-to-end type safety. Powered by: TRPC (on Fastify)

Matteo Lobello 35 Oct 22, 2022
Scaffold a full-stack SvelteKit application with tRPC and WindiCSS out of the box

create-sweet-app Interactive CLI to quickly set up an opinionated, full-stack, typesafe SvelteKit project. Inspired by the T3 Stack and create-t3-app

David Hrabě 10 Dec 16, 2022
A utility-first universal design system - powered by Tailwind CSS

tailwindcss-react-native tailwindcss-react-native uses Tailwind CSS as universal design system for all React Native platforms. It lets you share code

Mark Lawlor 1.5k Jan 4, 2023
Prisma +2 generator to emit Yup schemas from your Prisma schema

Prisma Yup Generator Automatically generate Yup schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 31 Dec 24, 2022
Prisma 2+ generator to emit Joi schemas from your Prisma schema

Prisma Joi Generator Automatically generate Joi schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 26 Dec 24, 2022
Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma Zod Generator Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 212 Dec 27, 2022