diff --git a/.env.example b/.env.example index 85c59e3..11eb633 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,5 @@ MISTRAL_API_KEY=your_mistral_api_key_here GROQ_API_KEY=your_groq_api_key_here DATABASE_URL= + +NGROK_AUTHTOKEN=your_ngrok_authtoken_here diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c98f086 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..806baf4 --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +# Makefile for PostgreSQL, pgAdmin + +# Set your Docker Compose file name +COMPOSE_FILE := docker-compose.yml + +# Default target (runs in detached mode) +up: + docker-compose -f $(COMPOSE_FILE) up -d + +# Run in foreground (for logs) +up-foreground: + docker-compose -f $(COMPOSE_FILE) up + +# Stop containers +down: + docker-compose -f $(COMPOSE_FILE) down + +# Stop and remove containers, networks, images, and volumes (use with caution!) +down-all: + docker-compose -f $(COMPOSE_FILE) down --rmi all --volumes + +# Rebuild containers (useful after code changes in your project) +rebuild: + docker-compose -f $(COMPOSE_FILE) up -d --build + +# Execute a command inside the 'db' container +postgres-exec: + docker-compose -f $(COMPOSE_FILE) exec db bash + +# Execute a command inside the 'pgadmin' container +pgadmin-exec: + docker-compose -f $(COMPOSE_FILE) exec pgadmin /bin/sh + +# Connect to the PostgreSQL database using psql +psql: + docker-compose -f $(COMPOSE_FILE) exec db psql -U postgres -d cursorlens + +# Backup the database +backup: + docker-compose -f $(COMPOSE_FILE) exec -T db pg_dump -U postgres postgres > backup.sql + +# Restore the database +restore: + cat backup.sql | docker-compose -f $(COMPOSE_FILE) exec -T db psql -U postgres -d cursorlens + +# Get ngrok URL +ngrok-url: + @echo "Fetching ngrok URL..." + @curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url' + + +# List available targets +help: + @echo "Available targets:" + @echo " up - Start services in detached mode" + @echo " up-foreground - Start services in the foreground (for logs)" + @echo " down - Stop services" + @echo " down-all - Stop and remove everything (use with caution!)" + @echo " rebuild - Rebuild and restart containers" + @echo " postgres-exec - Execute a command inside the 'db' container" + @echo " pgadmin-exec - Execute a command inside the 'pgadmin' container" + @echo " psql - Connect to the PostgreSQL database using psql" + @echo " backup - Backup the PostgreSQL database" + @echo " restore - Restore the PostgreSQL database from backup" + @echo " ngrok-url - Get the ngrok URL" + @echo " help - Show this help message" diff --git a/README.md b/README.md index e91785a..bf7fce4 100644 --- a/README.md +++ b/README.md @@ -27,32 +27,48 @@ We are live on ProductHunt today, please upvote us if you find this useful! 🙏 ## Getting Started -For detailed installation instructions, please refer to our [Installation Guide](https://www.cursorlens.com/docs/getting-started/installation). - ### Prerequisites - Node.js (v14 or later) - pnpm -- PostgreSQL -- ngrok +- Docker and Docker Compose +- ngrok account and authtoken (sign up for free at ngrok.com) ### Quick Installation Steps 1. Clone the repository 2. Install dependencies with `pnpm install` -3. Set up environment variables +3. Set up environment variables: + - Create a `.env` file in the root directory of the project + - Sign up for a free account at if you haven't already + - Obtain your ngrok authtoken from + - Add your ngrok authtoken to the `.env` file: `NGROK_AUTHTOKEN=your_token_here` 4. Set up the database with `pnpm prisma migrate dev` -5. Build the project with `pnpm build` -6. Set up ngrok -7. Configure Cursor to use your ngrok URL as the API endpoint +5. Build and start the project with `pnpm build` and `pnpm start` +6. In a separate terminal, start the Docker services: + + ``` + make up + ``` + +7. Get your ngrok URL from `http://localhost:4040`, by running the following if you have `curl` and `jq` installed: + + ``` + make ngrok-url + ``` + + or from the ngrok dashboard at . + +8. Configure Cursor to use your ngrok URL as the API endpoint For full details on each step, please see the [Installation Guide](https://www.cursorlens.com/docs/getting-started/installation). ## Usage -1. Configure Cursor to use Cursor Lens as its API endpoint by overriding `OpenAI Base URL`. -2. Choose a `gpt-` model. Use Cursor as normal for AI-assisted coding. -3. Visit the Cursor Lens dashboard to view logs, statistics, and insights. +1. Settings > Cursor Settings > Models > OpenAI API Key +2. Configure Cursor to use Cursor Lens as its API endpoint by overriding `OpenAI Base URL`. +3. Choose a `gpt-` model. Use Cursor as normal for AI-assisted coding. +4. Visit the Cursor Lens dashboard to view logs, statistics, and insights. ![Cursor settings](public/cl-settings.png) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..980ff0c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +version: "3.8" + +services: + db: + image: postgres:15 + platform: linux/arm64/v8 + container_name: cursorlens_postgres + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: cursorlens + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + pgadmin: + image: dpage/pgadmin4:8.9 + container_name: cursorlens_pgadmin4 + restart: always + environment: + PGADMIN_DEFAULT_EMAIL: admin@admin.com + PGADMIN_DEFAULT_PASSWORD: root + PGADMIN_SERVER_JSON_FILE: /pgadmin4/servers.json + ports: + - "5050:80" + volumes: + - ./servers.json:/pgadmin4/servers.json + depends_on: + - db + + ngrok: + image: ngrok/ngrok:latest + container_name: cursorlens_ngrok + restart: unless-stopped + command: + - "start" + - "--all" + - "--config" + - "/etc/ngrok.yml" + volumes: + - ./ngrok.yml:/etc/ngrok.yml + ports: + - 4040:4040 + environment: + - NGROK_AUTHTOKEN=${NGROK_AUTHTOKEN} + +volumes: + postgres_data: + +networks: + default: + name: postgres_network + external: true diff --git a/ngrok.yml b/ngrok.yml new file mode 100644 index 0000000..cc6f357 --- /dev/null +++ b/ngrok.yml @@ -0,0 +1,5 @@ +version: "2" +tunnels: + web: + proto: http + addr: host.docker.internal:3000 diff --git a/package.json b/package.json index 8e0b734..8a9acd1 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,11 @@ "dev": "next dev", "build": "next build", "start": "next start", + "db:generate": "prisma migrate dev", + "db:migrate": "prisma migrate deploy", + "db:push": "prisma db push", + "db:studio": "prisma studio", + "postinstall": "prisma generate", "lint": "next lint", "seed": "tsx prisma/seed.ts" }, diff --git a/servers.json b/servers.json new file mode 100644 index 0000000..845fa7a --- /dev/null +++ b/servers.json @@ -0,0 +1,13 @@ +{ + "Servers": { + "1": { + "Name": "Local Postgres", + "Group": "Servers", + "Host": "db", + "Port": 5432, + "MaintenanceDB": "postgres", + "Username": "postgres", + "Password": "postgres" + } + } +} diff --git a/src/env.ts b/src/env.ts index aea06e3..abae538 100644 --- a/src/env.ts +++ b/src/env.ts @@ -16,6 +16,7 @@ export const env = createEnv({ COHERE_API_KEY: z.string().optional(), MISTRAL_API_KEY: z.string().optional(), GROQ_API_KEY: z.string().optional(), + NGROK_AUTHTOKEN: z.string(), }, /** @@ -39,6 +40,7 @@ export const env = createEnv({ COHERE_API_KEY: process.env.COHERE_API_KEY, MISTRAL_API_KEY: process.env.MISTRAL_API_KEY, GROQ_API_KEY: process.env.GROQ_API_KEY, + NGROK_AUTHTOKEN: process.env.NGROK_AUTHTOKEN, // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, }, /**