Skip to content

Local Development Guide ๐Ÿ’ป โ€‹

This guide covers everything you need to know for developing Shelf.nu locally after completing the Supabase Setup.

Prerequisites โœ… โ€‹

  • โœ… Node.js (v20 or higher)
  • โœ… npm or yarn
  • โœ… Git
  • โœ… Supabase project configured (Setup Guide)
  • โœ… .env file with Supabase credentials

Development Setup ๐Ÿš€ โ€‹

1. Clone & Install Dependencies โ€‹

bash
# Clone the repository
git clone https://github.com/Shelf-nu/shelf.nu.git
cd shelf.nu

# Install dependencies
npm install

Shelf is configured to use HTTPS locally for a better development experience. You can set this up using mkcert:

Install mkcert โ€‹

bash
# macOS
brew install mkcert

# Ubuntu/Debian
sudo apt install libnss3-tools
wget -O mkcert https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64
chmod +x mkcert
sudo mv mkcert /usr/local/bin/

# Windows (using Chocolatey)
choco install mkcert

Generate SSL Certificates โ€‹

bash
# Install local CA
mkcert -install

# Create certificate directory
mkdir .cert

# Generate certificates for localhost
mkcert -key-file .cert/key.pem -cert-file .cert/cert.pem localhost 127.0.0.1 ::1

Alternative: Disable SSL โ€‹

If you prefer to run without SSL, edit vite.config.ts and remove these lines:

ts
// Remove or comment out these lines in vite.config.ts
https: {
  key: "./.cert/key.pem",
  cert: "./.cert/cert.pem",
},

3. Initialize Database โ€‹

This command sets up your database schema and runs initial migrations:

bash
npm run setup

4. Start Development Server โ€‹

bash
npm run dev

With SSL enabled: Your app will be available at: https://localhost:3000 ๐Ÿ”’
Without SSL: Your app will be available at: http://localhost:3000 ๐ŸŽ‰


Technology Stack ๐Ÿ› ๏ธ โ€‹

Understanding Shelf's tech stack will help you develop effectively:

Core Framework โ€‹

Database & Backend โ€‹

Styling & UI โ€‹

  • Tailwind CSS - Utility-first CSS
  • Custom Components - Built for asset management

Development Tools โ€‹


Available Scripts ๐Ÿ“œ โ€‹

Development โ€‹

bash
npm run dev          # Start development server
npm run build        # Build for production
npm run start        # Start production server
npm run typecheck    # Run TypeScript checks

Database โ€‹

bash
npm run setup                    # Initial database setup
npm run db:prepare-migration     # Create new migration
npm run db:deploy-migration      # Apply migrations
npm run db:migrate               # Run migrations in dev
npm run db:reset                 # Reset database (careful!)
npm run db:seed                  # Seed database with sample data

Code Quality โ€‹

bash
npm run lint         # Run ESLint
npm run format       # Format code with Prettier
npm run validate     # Run all checks (lint, typecheck, format)

Testing โ€‹

bash
npm run test                # Run unit tests
npm run test:e2e           # Run end-to-end tests
npm run test:e2e:dev       # Run E2E tests in dev mode
npm run test:e2e:install   # Install Playwright browsers

Development Workflow ๐Ÿ”„ โ€‹

Making Database Changes โ€‹

  1. Update Prisma Schema

    bash
    # Edit app/database/schema.prisma
  2. Create Migration

    bash
    npm run db:prepare-migration
  3. Apply Migration

    bash
    npm run db:deploy-migration

Adding New Features โ€‹

  1. Create your feature files in appropriate directories:

    • app/routes/ - New pages/routes
    • app/components/ - Reusable components
    • app/utils/ - Utility functions
    • app/modules/ - Business logic modules
  2. Follow the established patterns:

    • Use TypeScript for type safety
    • Follow Remix conventions for data loading
    • Use Tailwind for styling
    • Add tests for new functionality
  3. Test your changes:

    bash
    npm run validate  # Check code quality
    npm run test      # Run tests

Project Structure ๐Ÿ“ โ€‹

shelf.nu/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ components/          # Reusable UI components
โ”‚   โ”œโ”€โ”€ database/           # Prisma schema and migrations
โ”‚   โ”œโ”€โ”€ modules/            # Business logic modules
โ”‚   โ”œโ”€โ”€ routes/             # Remix routes (pages)
โ”‚   โ”œโ”€โ”€ styles/             # CSS and styling
โ”‚   โ”œโ”€โ”€ utils/              # Utility functions
โ”‚   โ””โ”€โ”€ root.tsx           # App root component
โ”œโ”€โ”€ docs/                   # Documentation
โ”œโ”€โ”€ public/                 # Static assets
โ”œโ”€โ”€ tests/                  # Test files
โ”œโ”€โ”€ .env.example           # Environment variables template
โ””โ”€โ”€ package.json           # Dependencies and scripts

Key Directories โ€‹

app/routes/ - Each file becomes a route in your app:

  • _index.tsx โ†’ /
  • assets._index.tsx โ†’ /assets
  • assets.new.tsx โ†’ /assets/new

app/components/ - Reusable React components:

  • Follow atomic design principles
  • Include TypeScript props interfaces
  • Use Tailwind for styling

app/modules/ - Business logic organized by domain:

  • auth/ - Authentication logic
  • asset/ - Asset management
  • booking/ - Booking system

Environment Configuration ๐Ÿ”ง โ€‹

Your .env file should include all necessary variables. Here are the development-specific ones:

bash
# Development server (adjust based on SSL setup)
SERVER_URL="https://localhost:3000"  # With SSL
# SERVER_URL="http://localhost:3000"  # Without SSL

# Database (from Supabase)
DATABASE_URL="your-supabase-connection-string"
DIRECT_URL="your-supabase-direct-connection"

# Disable premium features for local development
ENABLE_PREMIUM_FEATURES="false"

# Session security
SESSION_SECRET="your-local-session-secret"

Database Development ๐Ÿ—„๏ธ โ€‹

Working with Prisma โ€‹

View your data:

bash
npx prisma studio

This opens a web interface to browse your database.

Reset database (destructive!):

bash
npm run db:reset

Seed with sample data:

bash
npm run db:seed

Creating Migrations โ€‹

When you modify schema.prisma:

  1. Prepare migration:

    bash
    npm run db:prepare-migration
  2. Review the generated SQL in app/database/migrations/

  3. Apply migration:

    bash
    npm run db:deploy-migration

Testing ๐Ÿงช โ€‹

Unit Testing with Vitest โ€‹

bash
npm run test        # Run all unit tests
npm run test:watch  # Run tests in watch mode

Create test files alongside your components:

components/
โ”œโ”€โ”€ Button.tsx
โ””โ”€โ”€ Button.test.tsx

End-to-End Testing with Playwright โ€‹

bash
npm run test:e2e:install  # Install browsers (first time)
npm run test:e2e:dev      # Run tests in development

E2E tests are in the tests/e2e/ directory.


Debugging ๐Ÿ› โ€‹

Common Issues โ€‹

Port already in use:

bash
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9

SSL Certificate errors:

  • Make sure you ran mkcert -install to install the local CA
  • Regenerate certificates: mkcert -key-file .cert/key.pem -cert-file .cert/cert.pem localhost
  • Or disable SSL by removing the https section from vite.config.ts

Database connection errors:

  • Check your .env database URLs
  • Verify Supabase project is running
  • Ensure you have the correct password

Build errors:

bash
# Clear node modules and reinstall
rm -rf node_modules package-lock.json
npm install

Development Tools โ€‹

Database inspection:

bash
npx prisma studio  # Visual database browser

Type checking:

bash
npm run typecheck  # Check for TypeScript errors

Code formatting:

bash
npm run format     # Auto-format all code

Hot Reloading ๐Ÿ”ฅ โ€‹

The development server includes hot reloading:

  • React components - Changes update instantly
  • Routes - New routes appear automatically
  • Styles - CSS changes apply immediately
  • Server code - Remix restarts the server

VS Code Setup ๐Ÿ’ก โ€‹

Recommended extensions:

  • Prisma - Syntax highlighting for .prisma files
  • Tailwind CSS IntelliSense - Auto-complete for CSS classes
  • TypeScript and JavaScript - Enhanced TS support
  • Prettier - Code formatting
  • ESLint - Code linting

Workspace Settings โ€‹

Create .vscode/settings.json:

json
{
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Performance Tips ๐Ÿš€ โ€‹

Development Performance โ€‹

  • Use TypeScript strict mode for better error catching
  • Run tests frequently to catch issues early
  • Use Prisma Studio for database inspection instead of raw SQL
  • Leverage Remix's built-in optimizations (no need for extra bundlers)

Database Performance โ€‹

  • Use database indexes for frequently queried fields
  • Limit data in development - Use .take() to limit results
  • Use Prisma's include and select to fetch only needed data

Next Steps ๐ŸŽฏ โ€‹

Once you're comfortable with local development:

  1. Explore the codebase - Look at existing routes and components
  2. Read the other docs - Check out hooks, error handling, etc.
  3. Join the community - Discord for questions
  4. Contribute - See CONTRIBUTING.md
  5. Deploy - Check out Deployment Guide when ready

Getting Help ๐Ÿ’ฌ โ€‹

Happy coding! ๐ŸŽ‰

Released under the AGPL-3.0 License.