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
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
# Next.js Prisma Starter

This is a simple Next.js template that incorporates [Prisma](https://prisma.io/) as the Object-Relational Mapping (ORM) tool. The following instructions guide you on how to effectively use this template.
A Next.js template using [Prisma](https://prisma.io/) as the ORM.

## Step-by-step Usage Guide
## Getting Started

### Step 1: Clone and Install Dependencies

The first step is to clone this repository and install dependencies. This can be done in a couple ways:
### 1. Install Dependencies

```bash
pnpm create next-app --example https://github.com/moonpay/devops-challenge

# or

git clone https://github.com/moonpay/devops-challenge
cd devops-challenge
pnpm install
```

### Step 2: Set Up Environment Variables
### 2. Set Up Environment Variables

Once you've cloned the project, you need to configure the environment variables. Start by creating a `.env` file by copying the provided `.env.example` file in this directory. You can do this using the command:
Create a `.env` file with your database connection:

```bash
cp .env.example .env
echo 'POSTGRES_PRISMA_URL=postgres://postgres:postgres@localhost:5432/currencies?schema=public' > .env
```

Please note that the `.env` file is ignored by Git for security reasons.
### 3. Start the Database

### Step 3: Start the Database and Seed Data
```bash
docker compose up -d postgres
```

Next, you need to start the database and seed the data. You can do this by running the following command:
### 4. Seed the Database

```bash
docker run --rm --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=currencies -p 5432:5432 -d postgres:17-alpine

pnpm db:seed
```

# or

docker compose up -d
### 5. Start Development Server

pnpm db:seed
```bash
pnpm dev
```

### Step 4: Start Development Server
The app will be available at [http://localhost:3000](http://localhost:3000).

## Useful Commands

Finally, you are ready to run the Next.js development server. Execute the following command in your terminal:
| Command | Description |
|---------|-------------|
| `pnpm dev` | Start the development server |
| `pnpm build` | Build for production |
| `pnpm db:seed` | Push schema and seed the database |
| `pnpm db:studio` | Open Prisma Studio to inspect the database |

## Docker

To run the full stack with Docker:

```bash
pnpm dev
docker compose up -d
```

Once this command runs successfully, the project is up and ready. You might be missing some components (like a Dockerfile), but you can add them as you go.
This starts both PostgreSQL and the Next.js app (once we have a Dockerfile)
28 changes: 9 additions & 19 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# compose for postgres, pgadmin, and nextjs
services:
postgres:
image: postgres:17-alpine
Expand All @@ -12,24 +11,15 @@ services:
volumes:
- postgres:/var/lib/postgresql/data

# pgadmin:
# image: dpage/pgadmin4
# restart: always
# environment:
# PGADMIN_DEFAULT_EMAIL: admin@example.com
# PGADMIN_DEFAULT_PASSWORD: admin
# ports:
# - 5050:80

# nextjs:
# build: .
# restart: always
# environment:
# POSTGRES_PRISMA_URL: postgres://postgres:postgres@postgres:5432/currencies?schema=public
# ports:
# - 3000:3000
# depends_on:
# - postgres
nextjs:
build: .
restart: always
environment:
POSTGRES_PRISMA_URL: postgres://postgres:postgres@postgres:5432/currencies?schema=public
ports:
- 3000:3000
depends_on:
- postgres

volumes:
postgres:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "prisma generate && next build",
"db:schema:push": "prisma generate && prisma db push",
"db:seed": "prisma generate && prisma db push && prisma db seed",
"start": "next start",
"lint": "next lint"
"db:studio": "prisma studio",
"start": "next start"
},
"dependencies": {
"@prisma/client": "6.16.3",
Expand Down
19 changes: 14 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -12,23 +16,28 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
"@/*": [
"./*"
]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"prisma/seed.ts"
"prisma/seed.ts",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}