Skip to content

Commit b5c2f08

Browse files
committed
chore: move .env file to monorepo root
1 parent 8577c53 commit b5c2f08

File tree

6 files changed

+68
-114
lines changed

6 files changed

+68
-114
lines changed

.env.example

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Connection string for a Postgres database
2+
DATABASE_URL=
3+
4+
# API key for E2B, obtainable at https://e2b.dev/
5+
E2B_API_KEY=
6+
7+
# API key and publishable key for Clerk, obtainable at https://clerk.com/
8+
CLERK_SECRET_KEY=
9+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
10+
11+
# API key for OpenAI, obtainable at https://openai.com/api/
12+
OPENAI_API_KEY=
13+
14+
# API key for Anthropic, obtainable at https://console.anthropic.com/api
15+
ANTHROPIC_API_KEY=
16+
17+
# Optional: As an alternative to Anthropic, you can use AWS Bedrock
18+
AWS_ACCESS_KEY_ID=
19+
AWS_SECRET_ACCESS_KEY=
20+
AWS_REGION=
21+
AWS_ARN=
22+
23+
# Optional: Dokku credentials for deployments
24+
DOKKU_HOST=
25+
DOKKU_USERNAME=
26+
DOKKU_KEY=
27+

README.md

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A quick overview of the tech before we start: The deployment uses a **NextJS** a
1717
- [Anthropic](https://anthropic.com/) or AWS Bedrock: API keys for code generation.
1818
- [OpenAI](https://openai.com/): API keys for applying AI-generated code diffs.
1919

20-
### 1. Initial setup
20+
### 1. Clone the repository
2121

2222
No surprise in the first step:
2323

@@ -26,30 +26,21 @@ git clone https://github.com/jamesmurdza/sandbox
2626
cd sandbox
2727
```
2828

29-
Install dependencies:
29+
Copy .env files:
3030

3131
```bash
32-
npm install
33-
```
34-
35-
### 2. Add Clerk
36-
37-
Get the API keys from Clerk.
38-
39-
Update `/web/.env`:
40-
41-
```
42-
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY='🔑'
43-
CLERK_SECRET_KEY='🔑'
32+
cp .env.example .env
33+
cp web/.env.example web/.env
34+
cp server/.env.example server/.env
4435
```
4536

46-
Then, update `server/.env`:
37+
Install dependencies:
4738

48-
```
49-
CLERK_SECRET_KEY='🔑'
39+
```bash
40+
npm install
5041
```
5142

52-
### 3. Add the database
43+
### 2. Create a database
5344

5445
Create a database:
5546

@@ -58,52 +49,32 @@ psql postgres -c "CREATE DATABASE sandbox;"
5849
# psql postgres -U postgres -c "CREATE DATABASE sandbox;"
5950
```
6051

61-
Update `web/.env` and `server/.env` with the database connection string.
52+
Delete the `/db/drizzle/meta` directory.
6253

63-
```sh
64-
DATABASE_URL=postgresql://localhost:5432/sandbox
65-
# DATABASE_URL=postgresql://<username>:password@localhost:5432/sandbox
66-
```
67-
68-
### 4. Apply the database schema
69-
70-
Delete the `/web/drizzle/meta` directory.
71-
72-
In the `/web/` directory run:
54+
In the `/db/` directory run:
7355

7456
```
7557
npm run generate
7658
npm run migrate
7759
```
7860

79-
### 5. Add E2B
61+
### 3. Configure environment variables
8062

81-
Setup the E2B account.
63+
Get API keys for E2B, Clerk, OpenAI, and Anthropic.
8264

83-
Update `/web/.env` and `/server/.env`:
65+
Add them to the `.env` file along with the database connection string.
8466

8567
```
68+
DATABASE_URL='🔑'
8669
E2B_API_KEY='🔑'
87-
```
88-
89-
### 6. Configure the frontend
90-
91-
Update `/web/.env`:
92-
93-
```
94-
NEXT_PUBLIC_SERVER_URL='http://localhost:4000'
95-
```
96-
97-
Then add Anthropic and OpenAI API keys:
98-
99-
```
100-
ANTHROPIC_API_KEY='🔑'
70+
CLERK_SECRET_KEY='🔑'
10171
OPENAI_API_KEY='🔑'
72+
ANTHROPIC_API_KEY='🔑'
10273
```
10374

10475
As an alternative to the Anthropic API, you can use AWS Bedrock as described in [this section](#add-inference-on-aws-bedrock).
10576

106-
### 7. Run the IDE
77+
### 4. Run the IDE
10778

10879
Start the web app and server in development mode:
10980

@@ -120,7 +91,7 @@ npm run dev
12091

12192
Setup GitHub OAuth for authentication.
12293

123-
Update `/web/.env`:
94+
Update `.env`:
12495

12596
```
12697
GITHUB_CLIENT_ID=your_github_client_id
@@ -231,7 +202,7 @@ sudo make install
231202
systemctl start dokku-daemon
232203
```
233204
234-
The Sandbox platform connects to the Dokku server via SSH, using SSH keys specifically generated for this connection. The SSH key is stored on the Sandbox server, and the following environment variables are set in /server/.env:
205+
The Sandbox platform connects to the Dokku server via SSH, using SSH keys specifically generated for this connection. The SSH key is stored on the Sandbox server, and the following environment variables are set in `.env`:
235206
236207
```bash
237208
DOKKU_HOST=

server/.env.example

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1 @@
1-
# The variables below are required.
2-
3-
# PORT is the port used by NodeJS
4-
# SERVER_URL points to this server
5-
6-
PORT=4000
7-
SERVER_URL=http://localhost:4000
8-
9-
# The variables are required.
10-
# They should be the same as in frontend/.env.example
11-
12-
DATABASE_URL=
13-
E2B_API_KEY=
14-
CLERK_SECRET_KEY=
15-
16-
# The variables below are required to use deployments.
17-
18-
# DOKKU_HOST and DOKKU_USERNAME are used to authenticate via SSH with the Dokku server
19-
# DOKKU_KEY is the path to an SSH (.pem) key on the local machine
20-
21-
DOKKU_HOST=
22-
DOKKU_USERNAME=
23-
DOKKU_KEY=
24-
25-
# These should be the same as in /backend/server/.env
26-
27-
DATABASE_URL=
28-
29-
# CLERK_SECRET_KEY needed for making authenticated requests
30-
CLERK_SECRET_KEY=
1+
PORT=4000

server/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import cors from "cors"
21
import dotenv from "dotenv"
2+
import path from "path"
3+
4+
// Load parent .env first
5+
// Then load local .env to override
6+
dotenv.config({ path: path.resolve(__dirname, "../../.env") })
7+
dotenv.config({ path: path.resolve(__dirname, "../.env") })
8+
9+
import cors from "cors"
310
import express, { Express } from "express"
411
import fs from "fs"
512
import { createServer } from "http"
@@ -34,9 +41,6 @@ process.on("unhandledRejection", (reason, promise) => {
3441
// Initialize containers and managers
3542
const connections = new ConnectionManager()
3643

37-
// Load environment variables
38-
dotenv.config()
39-
4044
// Initialize Express app and create HTTP server
4145
const app: Express = express()
4246
const port = process.env.PORT || 4000

web/.env.example

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,7 @@
1-
# The variables below are for NextJS.
2-
31
NEXT_PUBLIC_APP_URL=http://localhost:3000
42
NEXT_PUBLIC_SERVER_URL=http://localhost:4000
53

64
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
75
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
86
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
9-
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
10-
11-
# The variables below are required.
12-
13-
# E2B_API_KEY can be obtained at https://e2b.dev/
14-
# DATABASE_URL is the connection string for the database
15-
# Clerk credentials can be obtained at https://clerk.com/
16-
17-
E2B_API_KEY=
18-
DATABASE_URL=
19-
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
20-
CLERK_SECRET_KEY=
21-
22-
# The variables below are required to use the AI assistant.
23-
# You need:
24-
# 1. OPENAI_API_KEY (required for applying AI-generated code diffs)
25-
# 2. EITHER Anthropic direct API OR AWS Bedrock configuration (for code generation)
26-
27-
# Option 1: Direct Anthropic API
28-
ANTHROPIC_API_KEY=
29-
30-
# Option 2: AWS Bedrock Configuration (all four required if using this option)
31-
AWS_ACCESS_KEY_ID=
32-
AWS_SECRET_ACCESS_KEY=
33-
AWS_REGION=
34-
AWS_ARN=
35-
36-
# Required for code diffs
37-
OPENAI_API_KEY=
7+
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard

web/next.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import dotenv from "dotenv"
2+
import path from "path"
3+
import { fileURLToPath } from "url"
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
6+
7+
// Load parent .env first
8+
// Then load local .env to override
9+
dotenv.config({ path: path.resolve(__dirname, "../.env") })
10+
dotenv.config({ path: path.resolve(__dirname, ".env") })
11+
112
/** @type {import('next').NextConfig} */
213
const nextConfig = {
314
async headers() {

0 commit comments

Comments
 (0)