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
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Dockerfile.*

.DS_Store
node_modules
.turbo
*.log
.next
dist
dist-ssr
*.local
.env
.cache
server/dist
public/dist
coverage
.husky/prepare-commit-msg
.idea
.terraform
*.tfstate
~
db-data
tmp
# Sentry Config File
.sentryclirc

# Vercel linking
.vercel

# vim: ft=.gitignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist
# Sentry Config File
.env.sentry-build-plugin
.sentryclirc
.aider*

# Logs
logs
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
########
# BASE #
########
FROM node:20 AS base
WORKDIR /ize

WORKDIR /app
COPY . .
RUN npm i

WORKDIR apps/backend

# ENV TS_NODE_BASEURL="./dist"
ENTRYPOINT ["npm", "run", "start:dev:docker"]
58 changes: 16 additions & 42 deletions SETUP.MD → SETUP.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,34 @@
# Local setup

## Setting up your local dev environment

Install Homebrew

`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`

Install Postgres 16

`brew install postgresql@16`

Run Postgres

`brew services start postgresql@16`

Create database

`createdb izedev`

Install nvm

`curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash`

Install packages

`npm i`

Update local database schema with prisma schema

`cd apps/backend && npx prisma db push`

Add database URL to your backend env file.

```
DATABASE_URL="postgresql://<username>@localhost:5432/izedev"
```

Create a port forwarding tunnel from port 3000. You can use a service like ngrok or vs code. Set the address in the backend env file. This is used so that external services like Telegram API can communicate with local server via SSL.

```
PORT_FORWARDING_ADDRESS=""
```

Use .env.sample to create rest of your backend env file. Email [email protected] if you're interested in developing Ize and getting access to existing running infrastructure. Otherwise, you'll need to add your own API keys for Stytch, Alchemy, OpenAI, Discord, and Telegram.
Use .env.sample to create your backend env file. Email [email protected] if you're interested in developing Ize and getting access to existing running infrastructure. Otherwise, you'll need to add your own API keys for Stytch, Alchemy, OpenAI, Discord, and Telegram.

## Running Ize in dev mode

Runs in dev mode with hot module reloading on both the backend server and frontend Vite server. Note that frontend assets are served differently in dev than during production. In development, a Vite server serves static assets whereas in production, these assets are served by express server

Build the database and run the backend

`cd apps/backend && npx prisma db push && npm run start:dev`
```sh
docker compose up
```

Run the frontend.

`sudo cd apps/frontend && npm run dev`
```sh
npm i
cd apps/frontend && sudo npm run dev
```

The reason we're running sudo here is because the Telegram login widget needs access to port 80 to work. This is definitely not ideal and something we should fix so contributors don't need to run sudo.

`sudo` is only needed to access port 80.

Navigate to [127.0.0.1](http://127.0.0.1/)

## Development workflow
Expand All @@ -79,14 +50,17 @@ When you make an update to the GraphQL schema or queries, run `npm run codegen`
## Testing production build locally

Build backend and frontend.

`npm run build`
```sh
npm run build
```

This will build both the frontend and backend. Frontend dist files are output in backend dist folder.

Start the express server

`cd apps/backend && npm run start:prod`
```
cd apps/backend && npm run start:prod
```

Navigate to [127.0.0.1](http://127.0.0.1v)

Expand Down
4 changes: 3 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"schema": "src/prisma/schema.prisma"
},
"scripts": {
"build": "tsc --project ./ && npm run sentry:sourcemaps",
"build": "tsc --project ./",
"start:dev": "nodemon src/express/server.ts",
"start:dev:docker": "npx prisma db push && npm run start:dev",
"start:prod": "node -r ts-node/register/transpile-only -r tsconfig-paths/register dist/src/express/server.js",
"cron": "CRON=true npx ts-node src/cron/cron.ts",
"prisma-migrate-dev": "npx prisma migrate dev",
Expand Down Expand Up @@ -50,6 +51,7 @@
"stytch": "^11.10.0",
"telegraf": "^4.16.3",
"tldts": "^6.1.63",
"viem": "^2.24.1",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
// CRON is set only in cron npm command, not the env file
CRON: process.env.CRON === "true",
PORT: process.env.PORT ? Number(process.env.PORT) : 3000,
HOST: process.env.HOST ?? "::1",
HOST: process.env.HOST ?? "127.0.0.1",
ALCHEMY_API_KEY: process.env.ALCHEMY_API_KEY,
DISCORD_IZE_BOT_API_TOKEN: process.env.DISCORD_IZE_BOT_API_TOKEN,
PROD_RENDER_URL: process.env.PROD_RENDER_URL ?? "https://ize.onrender.com",
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/components/Auth/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const LoginModal = () => {
loadMe();
return;
case StytchEventType.PasswordCreate:
case StytchEventType.PasswordAuthenticate:
await fetch("/api/auth/password", { method: "POST" });
loadMe();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TelegramBotSetup = () => {

return (
<>
{/* In local dev, you need to set bot's domain to 127.0.0.1:80 for FE button to work
{/* In local dev, you need to set bot's domain to 127.0.0.1 for FE button to work
But the backend validation will fail if the bot's domain is not the same as the one set in the backend
*/}
{!telegramIdentity && <TelegramLogin />}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig(({ mode }) => {
},
server: {
host: "127.0.0.1",
port: 80,
port: 3001,
proxy: {
"/api": {
target: env.VITE_LOCAL_BACKEND_URL,
Expand Down
63 changes: 63 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
services:
postgres:
image: postgres:16
container_name: postgres_izedev
environment:
POSTGRES_DB: izedev
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d izedev"]
interval: 10s
retries: 5
start_period: 30s
timeout: 10s

backend:
depends_on:
postgres:
condition: service_healthy
restart: true
build:
dockerfile: Dockerfile.backend
ports:
- "3000:3000"
environment:
- MODE=development
- HOST=0.0.0.0
- PORT
- LOCAL_URL=http://127.0.0.1
- PORT_FORWARDING_ADDRESS
## Alchemy
- ALCHEMY_API_KEY
- DATABASE_URL=postgresql://postgres:postgres@postgres_izedev:5432/izedev
# there are seperate dev and prod discord apps
- DISCORD_IZE_BOT_API_TOKEN
# there are seperate dev and prod telegram bots
- TELEGRAM_BOT_TOKEN
# STYTCH AUTH
- STYTCH_PROJECT_ID
- STYTCH_PROJECT_SECRET
## ENCRYPTION
## Call logEncryptionKeyAndIv() in the backend to generate a new key and iv
## Note: This is not the key/iv used in production
- ENCRYPTION_KEY
- ENCRYPTION_IV
- OPEN_AI_KEY

proxy:
image: nginx:alpine
container_name: proxy_izedev
network_mode: host
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
restart: unless-stopped

volumes:
postgres_data:
name: izedev_postgres_data
17 changes: 17 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
events {
worker_connections 1024;
}

http {
server {
listen 80;

location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Loading