Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions demo/the-epic-stack/.cursor/rules/avoid-use-effect.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
description:
globs: *.tsx,*.jsx
alwaysApply: false
---
### Avoid useEffect

[You Might Not Need `useEffect`](https://react.dev/learn/you-might-not-need-an-effect)

Instead of using `useEffect`, use ref callbacks, event handlers with
`flushSync`, css, `useSyncExternalStore`, etc.

```tsx
// This example was ripped from the docs:
// ✅ Good
function ProductPage({ product, addToCart }) {
function buyProduct() {
addToCart(product)
showNotification(`Added ${product.name} to the shopping cart!`)
}

function handleBuyClick() {
buyProduct()
}

function handleCheckoutClick() {
buyProduct()
navigateTo('/checkout')
}
// ...
}

useEffect(() => {
setCount(count + 1)
}, [count])

// ❌ Avoid
function ProductPage({ product, addToCart }) {
useEffect(() => {
if (product.isInCart) {
showNotification(`Added ${product.name} to the shopping cart!`)
}
}, [product])

function handleBuyClick() {
addToCart(product)
}

function handleCheckoutClick() {
addToCart(product)
navigateTo('/checkout')
}
// ...
}
```

There are a lot more examples in the docs. `useEffect` is not banned or
anything. There are just better ways to handle most cases.

Here's an example of a situation where `useEffect` is appropriate:

```tsx
// ✅ Good
useEffect(() => {
const controller = new AbortController()

window.addEventListener(
'keydown',
(event: KeyboardEvent) => {
if (event.key !== 'Escape') return

// do something based on escape key being pressed
},
{ signal: controller.signal },
)

return () => {
controller.abort()
}
}, [])
```
29 changes: 29 additions & 0 deletions demo/the-epic-stack/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
LITEFS_DIR="/litefs/data"
DATABASE_PATH="./prisma/data.db"
DATABASE_URL="file:./data.db?connection_limit=1"
CACHE_DATABASE_PATH="./other/cache.db"
SESSION_SECRET="super-duper-s3cret"
HONEYPOT_SECRET="super-duper-s3cret"
RESEND_API_KEY="re_blAh_blaHBlaHblahBLAhBlAh"
SENTRY_DSN="your-dsn"

# this is set to a random value in the Dockerfile
INTERNAL_COMMAND_TOKEN="some-made-up-token"

# the mocks and some code rely on these two being prefixed with "MOCK_"
# if they aren't then the real github api will be attempted
GITHUB_CLIENT_ID="MOCK_GITHUB_CLIENT_ID"
GITHUB_CLIENT_SECRET="MOCK_GITHUB_CLIENT_SECRET"
GITHUB_TOKEN="MOCK_GITHUB_TOKEN"
GITHUB_REDIRECT_URI="https://example.com/auth/github/callback"

# set this to false to prevent search engines from indexing the website
# default to allow indexing for seo safety
ALLOW_INDEXING="true"

# Tigris Object Storage (S3-compatible) Configuration
AWS_ACCESS_KEY_ID="mock-access-key"
AWS_SECRET_ACCESS_KEY="mock-secret-key"
AWS_REGION="auto"
AWS_ENDPOINT_URL_S3="https://fly.storage.tigris.dev"
BUCKET_NAME="mock-bucket"
15 changes: 15 additions & 0 deletions demo/the-epic-stack/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Summary: Put your summary here -->

## Test Plan

<!-- What steps need to be taken to verify this works as expected? -->

## Checklist

- [ ] Tests updated
- [ ] Docs updated

## Screenshots

<!-- If what you're changing is within the app, please show before/after.
You can provide a video as well if that makes more sense -->
229 changes: 229 additions & 0 deletions demo/the-epic-stack/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
name: 🚀 Deploy
on:
push:
branches:
- main
- dev
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: read

jobs:
lint:
name: ⬣ ESLint
runs-on: ubuntu-22.04
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 22

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: 🛠 Setup Database
run: npx prisma migrate deploy && npx prisma generate --sql

- name: 🔬 Lint
run: npm run lint

typecheck:
name: ʦ TypeScript
runs-on: ubuntu-22.04
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 22

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 🏗 Build
run: npm run build

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: 🛠 Setup Database
run: npx prisma migrate deploy && npx prisma generate --sql

- name: 🔎 Type check
run: npm run typecheck --if-present

vitest:
name: ⚡ Vitest
runs-on: ubuntu-22.04
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 22

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: 🛠 Setup Database
run: npx prisma migrate deploy && npx prisma generate --sql

- name: ⚡ Run vitest
run: npm run test -- --coverage

playwright:
name: 🎭 Playwright
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 22

- name: 📥 Download deps
uses: bahmutov/npm-install@v1

- name: 📥 Install Playwright Browsers
run: npm run test:e2e:install

- name: 🛠 Setup Database
run: npx prisma migrate deploy && npx prisma generate --sql

- name: 🏦 Cache Database
id: db-cache
uses: actions/cache@v4
with:
path: prisma/data.db
key:
db-cache-schema_${{ hashFiles('./prisma/schema.prisma')
}}-migrations_${{ hashFiles('./prisma/migrations/*/migration.sql')
}}

- name: 🌱 Seed Database
if: steps.db-cache.outputs.cache-hit != 'true'
run: npx prisma migrate reset --force

- name: 🏗 Build
run: npm run build

- name: 🎭 Playwright tests
run: npx playwright test

- name: 📊 Upload report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

container:
name: 📦 Prepare Container
runs-on: ubuntu-24.04
# only prepare container on pushes
if: ${{ github.event_name == 'push' }}
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 50

- name: 👀 Read app name
uses: SebRollen/[email protected]
id: app_name
with:
file: 'fly.toml'
field: 'app'

- name: 🎈 Setup Fly
uses: superfly/flyctl-actions/[email protected]

- name: 📦 Build Staging Container
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
flyctl deploy \
--build-only \
--push \
--image-label ${{ github.sha }} \
--build-arg COMMIT_SHA=${{ github.sha }} \
--app ${{ steps.app_name.outputs.value }}-staging
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

- name: 📦 Build Production Container
if: ${{ github.ref == 'refs/heads/main' }}
run: |
flyctl deploy \
--build-only \
--push \
--image-label ${{ github.sha }} \
--build-arg COMMIT_SHA=${{ github.sha }} \
--build-secret SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
--app ${{ steps.app_name.outputs.value }}
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

deploy:
name: 🚀 Deploy
runs-on: ubuntu-24.04
needs: [lint, typecheck, vitest, playwright, container]
# only deploy on pushes
if: ${{ github.event_name == 'push' }}
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: '50'

- name: 👀 Read app name
uses: SebRollen/[email protected]
id: app_name
with:
file: 'fly.toml'
field: 'app'

- name: 🎈 Setup Fly
uses: superfly/flyctl-actions/[email protected]

- name: 🚀 Deploy Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
flyctl deploy \
--image "registry.fly.io/${{ steps.app_name.outputs.value }}-staging:${{ github.sha }}" \
--app ${{ steps.app_name.outputs.value }}-staging
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

- name: 🚀 Deploy Production
if: ${{ github.ref == 'refs/heads/main' }}
run: |
flyctl deploy \
--image "registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.sha }}"
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
28 changes: 28 additions & 0 deletions demo/the-epic-stack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
node_modules
.DS_store

/build
/server-build
.env
.cache

/prisma/data.db
/prisma/data.db-journal
/tests/prisma

/test-results/
/playwright-report/
/playwright/.cache/
/tests/fixtures/email/
/tests/fixtures/uploaded/
/tests/fixtures/openimg/
/coverage

/other/cache.db

# Easy way to create temporary files/folders that won't accidentally be added to git
*.local.*

# generated files
/app/components/ui/icons
.react-router/
2 changes: 2 additions & 0 deletions demo/the-epic-stack/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy-peer-deps=true
registry=https://registry.npmjs.org/
Loading