- Install Node Version Manager (NVM). Installation: macOS/Linux, Windows.
- Install Node.js Iron (LTS):
# For macOS/Linux
nvm install --lts=iron
nvm use --lts=iron
# For Windows
nvm install lts
nvm use lts
- Install pnpm using Corepack (or alternatively, using npm):
corepack enable pnpm
- Install dependencies:
pnpm install
- Copy
.env.example
contents to.env.development.local
and fill the environment variables (instructions inside file):
# For macOS/Linux
cp .env.example .env.development.local
# For Windows
copy .env.example .env.development.local
- Start the development database:
pnpm dev:db:start
- Initialize the development database with sample data:
pnpm dev:db:reset
- Run the development server:
pnpm dev
- Open http://localhost:3000 with your browser to see the result.
See development database contents:
pnpm dev:db:studio
Listen for Stripe events and trigger webhooks in development environment:
- Sign up for a Stripe account or sign in to your Stripe account. No need to activate payments.
- Add your API secret key and publishable key to
.env.development.local
. - Setup 2FA for your Stripe account and generate a restricted key.
- Setup Stripe CLI for development.
- Run the Stripe CLI:
pnpm dev:stripe
Send emails:
- Create new feature branch with the following format
name/feature
and push the new branch to remote (this repository):
git checkout -b bob/leaderboard-router
git push -u origin bob/leaderboard-router
- Stage changes, commit on your feature branch, and push to remote (note: do not commit on
main
branch):
git add .
git commit -m "feat: add leaderboard router"
git push
- Use kebab case to name files, e.g.,
leaderboard-router.ts
- Use kebab case + full component name for component files, e.g.,
button-group-card.tsx
for<ButtonGroupCard />
- Use import aliases instead of relative paths for package imports, e.g.
import { Button } from "@/components/ui/button";
- Git commits style guide: Conventional Commits 1.0.0
- Use TypeScript types instead of interfaces unless necessary (why?)
- Use
function
declarations for React components and event handlers- Learn more:
function
declaration vsfunction
expression vs arrow function
- Learn more:
Path | Import Alias | Usage |
---|---|---|
src/app |
@/app |
Next.js App Router |
src/app/_components |
@/components |
App-wide components |
src/app/_components/ui |
@/components/ui |
Components scaffolded by shadcn/ui |
src/lib |
@/lib |
Library/package-related files |
src/server |
@/server |
Server-related files |
src/assets |
@/assets |
App-wide assets |
public |
~/public |
Public assets |
emails |
~/emails |
React Email templates |
- pnpm can automatically resolve lockfile conflicts. Run:
pnpm install
- Stage and commit the lockfile:
git add pnpm-lock.yaml
git commit -m "chore: resolve lockfile conflict"
- Sign up for a user at
/dashboard/signup
. - Open Prisma Studio:
pnpm dev:db:studio
-
Save changes in Prisma Studio.
-
Log in as the user at
/dashboard/login
. You should be able to access the dashboard now.
- Remove the
.next
folder:
rm -rf .next
- Retry.
- Reset the development database by first removing the image:
docker image rm -f gtd-xxvi/db-dev
- Remove the volume where the development database data is stored:
docker volume rm gtd-xxvi-db-pgdata-dev
- Restart the development database:
pnpm dev:db:start
- Remove unused packages:
pnpm prune
- Remove unused and dangling Docker containers and images:
docker system prune
Use the tRPC client api
defined in src/trpc/server
. Example:
// example-page.tsx
import { api } from "@/server/trpc";
export default async function ExamplePage() {
const event = await api.event.getById(1);
return <main>{event?.name}</main>;
}
Use the tRPC client api
defined in src/trpc/client
. Example:
// example-page.tsx
"use client";
import { api } from "@/lib/trpc/provider";
export default function ExamplePage() {
const { data: event } = api.event.getById.useQuery(1);
return <main>{event?.name}</main>;
}
Do:
- Use Day.js to parse, find difference, format, etc.
Date
toString
Don't:
- Use Day.js as prop/state. Use
Date
instead (dayjs().toDate()
)
Compress one image into .webp
:
pnpm dlx sharp-cli -f webp --effort 6 -q 75 -i large-image.jpg -o {dir}
Compress all images in the current working directory into .webp
:
pnpm dlx sharp-cli -f webp --effort 6 -q 75 -i ./* -o {dir}
More info: Sharp CLI documentation
- Learning resources: github.com/GTD-IT-XXIV/gtd-xxvi-learning-resources
- Learning articles:
- Official documentation: Tailwind CSS, shadcn/ui, Next.js, tRPC, Zod, Prisma