Remix TypeScript monorepo with Turborepo pipelines, Prisma, PostgreSQL, Docker deploy to Fly.io, pnpm, TailwindCSS and Tsyringe for DI.

Overview

Remix Gospel stack with Turborepo

The Remix Gospel Stack

Remix TypeScript monorepo with Turborepo pipelines, Prisma, PostgreSQL, Docker deploy to Fly.io, pnpm, TailwindCSS and Tsyringe for DI.

git clone [email protected]:PhilDL/remix-gospel-stack.git
cd remix-gospel-stack

💽 Unfortunately due to the fact that pnpx create-remix cli replace the "*" in your package.json, it messes up the monorepo workspace package references by replacing them to the current Remix version, meaning that you can't use this template with create-remix and the --template flag. So for now you will have to clone and install.

What's in the stack

This stack is a Remix oriented Monorepo powered by turborepo abd pnpm workspaces. Containing a ready-to-deploy Remix App on fly.io via the building of a Docker container.

This Package uses pnpm as the package manager of choice to manage workspaces. It may work with yarn and npm if you put the workspace definitions in the package.json file but there is no guarantee.

Monorepo architecture powered by Turborepo and pnpm workspaces:

  • apps Folder containing the applications

  • packages Folder containing examples

    • database: a Prisma wrapper ready to be used in other packages, or apps. Bundled with tsup.
    • business: an example package using Tsyringe to inject the Prisma database as a dependency and using a repository pattern like example.
    • internal-nobuild: an example package that is pure TypeScript with no build steps. The main entrypoint to the package is directly src/index.ts. Remix takes care of compiling with its own build step (with esbuild). This packages also contains unit test with Vitest. Remix uses tsconfig.json paths to reference to that project and its types. I would recommend these types of internal packages when you don't plan on publishing the package.
    • ui: a dummy React UI library (which contains a single
  • config-packages:

    • Eslint packages with different preset configs.
    • TS Configs, also with different presets.
    • Tailwind configs.

What else ?

Warning All the following commands should be launched from the monorepo root directory

Developement

  • Install the dependencies.

    pnpm install

    You also have to copy the example .env.example:

    cp .env.example .env
    cp .env.example .env.docker
  • Start the postgresql docker container

    pnpm run docker:db

    Note: The npm script will complete while Docker sets up the container in the background. Ensure that Docker has finished and your container is running before proceeding.

  • Generate prisma schema

    pnpm run generate
  • Run the Prisma migration to the database

    pnpm run db:migrate:deploy
  • Run the first build (with dependencies via the ... option)

    pnpm run build --filter=remix-app...

    Running simply pnpm run build will build everything, including the NextJS app.

  • Run the Remix dev server

    pnpm run dev --filter=remix-app

Tests, Typechecks, Lint, Install packages...

Check the turbo.json file to see the available pipelines.

  • Run the Cypress tests and Dev
    pnpm run test:e2e:dev --filter=remix-app
  • Lint everything
    pnpm run lint
  • Typecheck the whole monorepo
    pnpm run typecheck
  • Test the whole monorepo
    pnpm run test
    or
    pnpm run test:dev 
  • How to install an npm package in the Remix app ?
    pnpm add dayjs --filter remix-app
  • Tweak the tsconfigs, eslint configs in the config-package folder. Any package or app will then extend from these configs.

Deployement

Warning All the following commands should be launched from the monorepo root directory

Setup Deployement to fly.io

Prior to your first deployment, you'll need to do a few things:

  • First singup the fly CLI

    fly auth signup
  • Create two apps on Fly, one for staging and one for production:

    fly apps create remix-gospel-stack
    fly apps create remix-gospel-stack-staging

    Note: Once you've successfully created an app, double-check the fly.toml file to ensure that the app key is the name of the production app you created. This Stack automatically appends a unique suffix at init which may not match the apps you created on Fly. You will likely see 404 errors in your Github Actions CI logs if you have this mismatch.

  • Initialize Git.

    git init
  • Create a new GitHub Repository, and then add it as the remote for your project. Do not push your app yet!

    git remote add origin <ORIGIN_URL>
  • Add a FLY_API_TOKEN to your GitHub repo. To do this, go to your user settings on Fly and create a new token, then add it to your repo secrets with the name FLY_API_TOKEN.

  • Create a database for both your staging and production environments. Run the following:

    fly postgres create --name remix-gospel-stack-db
    fly postgres attach --app remix-gospel-stack remix-gospel-stack-db
    
    fly postgres create --name remix-gospel-stack-staging-db
    fly postgres attach --app remix-gospel-stack-staging remix-gospel-stack-staging-db

    Note: You'll get the same warning for the same reason when attaching the staging database that you did in the fly set secret step above. No worries. Proceed!

Fly will take care of setting the DATABASE_URL secret for you.

Now that everything is set up you can commit and push your changes to your repo. Every commit to your main branch will trigger a deployment to your production environment, and every commit to your dev branch will trigger a deployment to your staging environment.

If you run into any issues deploying to Fly, make sure you've followed all of the steps above and if you have, then post as many details about your deployment (including your app name) to the Fly support community. They're normally pretty responsive over there and hopefully can help resolve any of your deployment issues and questions.

Multi-region deploys

Once you have your site and database running in a single region, you can add more regions by following Fly's Scaling and Multi-region PostgreSQL docs.

Make certain to set a PRIMARY_REGION environment variable for your app. You can use [env] config in the fly.toml to set that to the region you want to use as the primary region for both your app and database.

Testing your app in other regions

Install the ModHeader browser extension (or something similar) and use it to load your app with the header fly-prefer-region set to the region name you would like to test.

You can check the x-fly-region header on the response to know which region your request was handled by.

GitHub Actions

We use GitHub Actions for continuous integration and deployment. Anything that gets into the main branch will be deployed to production after running tests/build/etc. Anything in the dev branch will be deployed to staging.

Manually Build The Docker Image to deploy with Fly.io

  • Create a docker network
    docker network create app_network
    
  • Build the docker image
    pnpm docker:build:remix-app
  • Run the docker Image
    pnpm docker:run:remix-app
  • (Optionnal) If you want to manually deploy to fly.io:
    DOCKER_DEFAULT_PLATFORM=linux/amd64 flyctl deploy --config ./apps/remix-app/fly.toml --dockerfile ./apps/remix-app/Dockerfile

Useful Turborepo Links

Learn more about the power of Turborepo:

Support

If you found the template useful, please consider giving it a Star . Thanks you!

Disclaimer

I am in no way an expert on Monorepo, Docker or CI. The setup proposed here is one of many and probably could be improved 10x, but I am learning by myself along the way, so if you see any possible improvement please submit a PR. I will appreciate it greatly !

You might also like...

Projen project type for Turborepo monorepo setup.

📦 projen-turborepo Projen project type for Turborepo monorepo setup. Getting Started To create a new project, run the following command and follow th

Oct 4, 2022

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using remix.run and TailwindCSS. It supports markdown and MDX for the blog posts. You can clone it and star

Dec 8, 2022

This is boilerplate of express, typescript and postgreSql with typeorm and docker based setup

express-typescript-postgres-typeorm-docker-swagger-boilerplate This is boilerplate of express, typescript and postgreSql with typeorm and docker based

Jun 2, 2022

Remix + Cloudflare Workers + DO + Turborepo

Remix + Cloudflare Workers + DO + Turborepo A starter to get you up and going with Remix on Cloudflare with all the latest and greatest. What's inside

Dec 12, 2022

A starter template for Remix + Cloudflare Workers + DO + KV + Turborepo

Remix + Cloudflare Workers starter with Turborepo 🚀 Starter to get going with Remix and Cloudflare Workers. This template is based on the starter cre

Jan 2, 2023

Node.js TypeScript project demonstrating a Prisma integration with PostgreSQL

Prisma with PostgreSQL, TypeScript, Serverless and Parameter Store This project is the outcome of following the Prisma Getting Started guide. In addit

Aug 28, 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

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

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

Jan 3, 2023
Comments
  • tailwindcss missing attribute

    tailwindcss missing attribute

    It looks incomplete, for example I use w-16, but it doesn't actually work. I went to check the generated tailwind.css file, and there is no w-16 item in it, only w-32 item.

    opened by Alvazz 8
  • Update all dependencies

    Update all dependencies

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @testing-library/cypress | ^8.0.7 -> ^9.0.0 | age | adoption | passing | confidence | | @vitest/coverage-c8 | ^0.25.7 -> ^0.26.0 | age | adoption | passing | confidence | | vitest | ^0.25.7 -> ^0.26.0 | age | adoption | passing | confidence |


    ⚠ Dependency Lookup Warnings ⚠

    Warnings were logged while processing this repo. Please check the logs for more information.


    Release Notes

    kentcdodds/cypress-testing-library

    v9.0.0

    Compare Source

    chore
    BREAKING CHANGES
    • Use addQuery interface, which is only present in Cypress 12+.
    vitest-dev/vitest

    v0.26.0

    Compare Source

       🚨 Breaking Changes
       🚀 Features
       🐞 Bug Fixes
        View changes on GitHub

    Configuration

    📅 Schedule: Branch creation - "before 3am on Monday" (UTC), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update all dependencies

    Update all dependencies

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | SebRollen/toml-action | action | patch | v1.0.0 -> v1.0.2 | | pnpm/action-setup | action | patch | v2.2.2 -> v2.2.4 | | styfle/cancel-workflow-action | action | minor | 0.9.1 -> 0.11.0 |


    ⚠ Dependency Lookup Warnings ⚠

    Warnings were logged while processing this repo. Please check the logs for more information.


    Release Notes

    SebRollen/toml-action

    v1.0.2

    Compare Source

    Fixes an issue where dotted keys could not be read from TOML files - https://github.com/SebRollen/toml-action/issues/3 Upgrades the node runtime to node 16 - https://github.com/SebRollen/toml-action/issues/3

    v1.0.1

    Compare Source

    Updates to a later version of @actions/core ahead of the set-output deprecation. See: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

    Thank you to @​loispostula for the contribution!

    pnpm/action-setup

    v2.2.4

    Compare Source

    No deprecation warnings are printed about set-state and set-output commands (https://github.com/pnpm/action-setup/issues/57)

    v2.2.3

    Compare Source

    Bump Node.js version to 16 https://github.com/pnpm/action-setup/pull/56

    styfle/cancel-workflow-action

    v0.11.0

    Compare Source

    Minor Changes
    Credits

    Huge thanks to @​mattjohnsonpint for helping!

    v0.10.1

    Compare Source

    Patches
    Credits

    Huge thanks to @​licitdev and @​MichaelDeBoey for helping!

    v0.10.0

    Compare Source

    Changes
    Credits

    Huge thanks to @​MichaelDeBoey and @​anshulsahni for helping!


    Configuration

    📅 Schedule: Branch creation - "before 3am on Monday" (UTC), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Configure Renovate - autoclosed

    Configure Renovate - autoclosed

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • docker-compose-ci.yml (docker-compose)
    • docker-compose.yml (docker-compose)
    • apps/remix-app/Dockerfile (dockerfile)
    • .github/workflows/deploy.yml (github-actions)
    • apps/nextjs-app/package.json (npm)
    • apps/remix-app/package.json (npm)
    • config-packages/eslint-config-custom-next/package.json (npm)
    • config-packages/eslint-config-custom/package.json (npm)
    • config-packages/eslint-config-vite/package.json (npm)
    • config-packages/tailwind-config/package.json (npm)
    • config-packages/tsconfig/package.json (npm)
    • package.json (npm)
    • packages/business/package.json (npm)
    • packages/database/package.json (npm)
    • packages/internal-nobuild/package.json (npm)
    • packages/ui/package.json (npm)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • If Renovate detects semantic commits, it will use semantic commit type fix for dependencies and chore for all others.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Autodetect whether to pin dependencies or maintain ranges.
    • Rate limit PR creation to a maximum of two per hour.
    • Limit to maximum 10 open PRs at any time.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • A collection of workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 7 Pull Requests:

    Update SebRollen/toml-action action to v1.0.2
    • Schedule: ["at any time"]
    • Branch name: renovate/sebrollen-toml-action-1.x
    • Merge into: main
    • Upgrade SebRollen/toml-action to v1.0.2
    Update dependency eslint-plugin-react to v7.31.11
    • Schedule: ["at any time"]
    • Branch name: renovate/eslint-plugin-react-7.x
    • Merge into: main
    • Upgrade eslint-plugin-react to 7.31.11
    Update pnpm/action-setup action to v2.2.4
    • Schedule: ["at any time"]
    • Branch name: renovate/pnpm-action-setup-2.x
    • Merge into: main
    • Upgrade pnpm/action-setup to v2.2.4
    Update styfle/cancel-workflow-action action to v0.11.0
    • Schedule: ["at any time"]
    • Branch name: renovate/styfle-cancel-workflow-action-0.x
    • Merge into: main
    • Upgrade styfle/cancel-workflow-action to 0.11.0
    Update vitest monorepo to ^0.25.0
    • Schedule: ["at any time"]
    • Branch name: renovate/vitest-monorepo
    • Merge into: main
    • Upgrade @vitest/coverage-c8 to ^0.25.0
    • Upgrade vitest to ^0.25.0
    Update Node.js to v19
    • Schedule: ["at any time"]
    • Branch name: renovate/node-19.x
    • Merge into: main
    • Upgrade node to 19-bullseye-slim
    Update dependency cypress to v11
    • Schedule: ["at any time"]
    • Branch name: renovate/cypress-11.x
    • Merge into: main
    • Upgrade cypress to ^11.0.0

    🚸 Branch creation will be limited to maximum 2 per hour, so it doesn't swamp any CI resources or spam the project. See docs for prhourlylimit for details.


    ⚠ Dependency Lookup Warnings ⚠

    Please correct - or verify that you can safely ignore - these lookup failures before you merge this PR.

    • Failed to look up npm dependency @remix-gospel-stack/tsconfig
    • Failed to look up npm dependency eslint-config-custom-next
    • Failed to look up npm dependency @remix-gospel-stack/tailwind-config
    • Failed to look up npm dependency eslint-config-vite

    Files affected: apps/nextjs-app/package.json, apps/remix-app/package.json, packages/business/package.json, packages/database/package.json, packages/internal-nobuild/package.json, packages/ui/package.json


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
Owner
Philippe L'ATTENTION
Software Architect @SOGEXIS, owner of @Coding-Dodo. Writes about Python, ERP, Odoo dev
Philippe L'ATTENTION
VS Code Extension for pnpm, pnpm workspace and more.

pnpm-vscode-helper VS Code Extension for better DX with pnpm. Quick Start Type Ctrl(Command) + Shift + P to open workbench commands input. Type ext in

LinbuduLab 21 Dec 10, 2022
A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose

Turborepo + Strapi + Next.js + Docker A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose. ⚠️ Prerequisit

Elvin Chu 60 Dec 29, 2022
Turborepo starter with pnpm

Turborepo starter with pnpm This is an official starter turborepo. What's inside? This turborepo uses pnpm as a packages manager. It includes the foll

Jack Herrington 23 Dec 18, 2022
An Open Source Remix template that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. PostgreSQL version. Deploys to Fly.io

Live Demo · Twitter An open source Remix Stack that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. PostgreSQ

xo 25 Dec 7, 2022
The Remix Stack for deploying to Fly with PostgreSQL, authentication, testing, linting, formatting, etc.

The Remix Stack for deploying to Fly with PostgreSQL, authentication, testing, linting, formatting, etc.

Remix 677 Jan 2, 2023
sveltekit + turborepo + histoire in a turborepo

swyx's SvelteKit monorepo starter This is my starter for a monorepo with 2022 tech: SvelteKit Turborepo Histoire pnpm - brew install pnpm Demo Proof t

swyx 36 Nov 25, 2022
Get packages from a monorepo (pnpm, yarn, npm, lerna)

?? You can help the author become a full-time open-source maintainer by sponsoring him on GitHub. @egoist/get-packages Get packages from a monorepo (p

EGOIST 45 Jun 1, 2022
A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Prisma ORM. Deploys to Fly.io

Live Demo · Twitter A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Pris

Remix Stacks 18 Oct 31, 2022
Remix Stack for deploying to Vercel with remix-auth, Planetscale, Radix UI, TailwindCSS, formatting, linting etc. Written in Typescript.

Remix Synthwave Stack Learn more about Remix Stacks. npx create-remix --template ilangorajagopal/synthwave-stack What's in the stack Vercel deploymen

Ilango 56 Dec 25, 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