living-on-edge

Living on Edge

A monorepo project for AI-powered block generation with support for multiple AI providers (Mistral, Claude, OpenAI). This project includes a backend API, a user-facing frontend application, and a VS Code extension.

Project Overview

This is a Turborepo monorepo that consists of:

Applications

Packages

Prerequisites

Before you begin, ensure you have the following installed on your system:

Dependencies

Backend (http-backend)

Core Dependencies:

AI SDKs:

Development Dependencies:

Frontend (user-frontend)

Core Dependencies:

Editor & UI:

Development Dependencies:

Root

How to Clone and Run on Local Environment

1. Clone the Repository

git clone <repository-url>
cd living-on-edge

2. Install pnpm (if not already installed)

npm install -g pnpm@10.12.4

Or using other methods:

# Using Homebrew (macOS)
brew install pnpm

# Using npm
npm install -g pnpm

# Using curl
curl -fsSL https://get.pnpm.io/install.sh | sh -

3. Install Dependencies

From the root directory, install all dependencies:

pnpm install

4. Set Up Environment Variables

Backend Environment Variables

Create a .env file in apps/http-backend/ with the following variables:

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/dbname?schema=public"

# Supabase Configuration
SUPABASE_URL="your-supabase-project-url"
SUPABASE_ANON_KEY="your-supabase-anon-key"
SUPABASE_SERVICE_ROLE_KEY="your-supabase-service-role-key"

# AI API Keys (at least one required)
MISTRAL_API_KEY="your-mistral-api-key"
ANTHROPIC_API_KEY="your-anthropic-api-key"
OPENAI_API_KEY="your-openai-api-key"

# Server Configuration
PORT=3000

# AI Model Selection (optional, defaults to mistral)
aiModel=mistral

# Mock Mode (optional, for testing)
mock=false

# Stream Configuration (optional)
STREAM_CHAT_MAX_TOKENS=4096
PROMPT_ENHANCEMENT_MAX_TOKENS=2048

Frontend Environment Variables

Create a .env file in apps/user-frontend/ with the following variables:

# Backend API URL
VITE_BACKEND_URL="http://localhost:3000"

# Supabase Configuration
VITE_SUPABASE_URL="your-supabase-project-url"
VITE_SUPABASE_ANON_KEY="your-supabase-anon-key"

5. Set Up Database

  1. Create PostgreSQL Database:
    createdb your_database_name
    
  2. Run Prisma Migrations:
    cd apps/http-backend
    npx prisma migrate dev
    
  3. Generate Prisma Client:
    npx prisma generate
    

6. Run the Applications

From the root directory:

pnpm dev

This will start both the backend and frontend applications concurrently.

Option B: Run Applications Individually

Backend:

cd apps/http-backend
pnpm dev

The backend will start on http://localhost:3000 (or the port specified in your .env file).

Frontend:

cd apps/user-frontend
pnpm dev

The frontend will start on http://localhost:5173 (default Vite port).

Option C: Run with Specific AI Model

You can specify which AI model to use:

# Use Mistral AI
cd apps/http-backend
pnpm mistral

# Use Claude
cd apps/http-backend
pnpm claude

7. Verify Installation

  1. Backend: Check if the API is running by visiting http://localhost:3000 or checking the console logs
  2. Frontend: Open http://localhost:5173 in your browser
  3. Database: Verify database connection by checking Prisma logs

Development Commands

Root Level Commands

# Build all apps and packages
pnpm build

# Run development servers for all apps
pnpm dev

# Lint all packages
pnpm lint

# Format code
pnpm format

# Type check all packages
pnpm check-types

Backend Commands

cd apps/http-backend

# Development mode (default: Mistral)
pnpm dev

# Production mode
pnpm prod

# Use specific AI model
pnpm mistral
pnpm claude

Frontend Commands

cd apps/user-frontend

# Development server
pnpm dev

# Build for production
pnpm build

# Preview production build
pnpm preview

# Lint code
pnpm lint

Troubleshooting

Common Issues

  1. Port Already in Use: Change the PORT in your backend .env file or kill the process using the port
  2. Database Connection Error: Verify your DATABASE_URL is correct and PostgreSQL is running
  3. Missing API Keys: Ensure at least one AI API key is set in your backend .env file
  4. Prisma Client Not Generated: Run npx prisma generate in the apps/http-backend directory
  5. pnpm Not Found: Install pnpm globally or use npx pnpm instead

Getting Help

Project Structure

living-on-edge/
├── apps/
│   ├── http-backend/          # Express.js backend API
│   ├── user-frontend/         # React + Vite frontend
│   └── vs-code-block-generation/  # VS Code extension
├── packages/
│   ├── eslint-config/         # Shared ESLint config
│   ├── typescript-config/      # Shared TypeScript config
│   └── ui/                    # Shared UI components
├── package.json               # Root package.json
├── pnpm-workspace.yaml        # pnpm workspace configuration
├── turbo.json                 # Turborepo configuration
└── README.md                  # This file

Additional Resources