Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.sagozen.digital/llms.txt

Use this file to discover all available pages before exploring further.

Installation Guide

This guide walks you through setting up the Pet Service Management System on your local development environment.
Prerequisites: Node.js 18+, PostgreSQL 12+, Git

Quick Start

1. Clone the Repository

git clone <repository-url>
cd pet-service

2. Install Dependencies

cd backend
npm install

Backend Setup

Step 1: Environment Configuration

Create a .env file in the backend/ directory:
.env
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/petservice

# Application
NODE_ENV=development
PORT=3001

# Better Auth Configuration
BETTER_AUTH_URL=http://localhost:3001/api/auth
BETTER_AUTH_SECRET=your-better-auth-secret-here-min-32-chars
SESSION_SECRET=your-session-secret-here-min-32-chars
JWT_SECRET=your-jwt-secret-here-min-32-chars

# CORS
FRONTEND_URL=http://localhost:3000

# Email (Optional for development)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=noreply@example.com
SMTP_PASS=your-email-password
Security: Use strong, unique secrets for production. Generate with:
openssl rand -base64 32

Step 2: Database Setup

1

Create PostgreSQL Database

# Using psql
psql -U postgres
CREATE DATABASE petservice;
\q
2

Generate Prisma Client

cd backend
npm run prisma:generate
3

Apply Database Schema

npm run prisma:db:push
This creates all tables, indexes, and constraints defined in prisma/schema.prisma.
4

Verify Database

npm run prisma:studio
Opens Prisma Studio at http://localhost:5555 to inspect your database.

Step 3: Seed Database (Optional)

Seeding creates sample data for development and testing.
cd backend
npm run prisma:db:seed
Seed Data Includes:
  • Admin user (email: admin@example.com, password: admin123)
  • Manager user (email: manager@example.com, password: manager123)
  • Staff user (email: staff@example.com, password: staff123)
  • Customer users
  • 6 service categories (Boarding, Grooming, Veterinary, Training, Daycare, Transport)
  • Sample pets
  • Sample bookings

Step 4: Start Backend Server

cd backend
npm run start:dev
Backend running at http://localhost:3001
Verify Backend:
curl http://localhost:3001/health
# Expected: {"status":"ok","timestamp":"..."}

Frontend Setup

Step 1: Environment Configuration

Create a .env.local file in the frontend/ directory:
.env.local
# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:3001

# Application URL
NEXT_PUBLIC_APP_URL=http://localhost:3000

# Better Auth (if using OAuth)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

Step 2: Start Frontend Server

cd frontend
npm run dev
Frontend running at http://localhost:3000
Test the Application:
  1. Open http://localhost:3000 in your browser
  2. Navigate to /en or /vi for localized content
  3. Try logging in with seeded credentials

Database Management

Common Commands

cd backend
npm run prisma:generate

Database Schema

The database includes the following main entities:
  • User: Core user accounts with roles (ADMIN, MANAGER, STAFF, CUSTOMER)
  • Session: Active user sessions
  • Account: OAuth provider accounts
  • Verification: Email verification tokens
  • Booking: Main booking records with status tracking
  • BookingPet: Junction table linking bookings to pets
  • BookingService: Junction table linking bookings to services with pricing
  • Pet: Pet profiles with medical history, vaccinations, allergies
  • Supports multiple images
  • JSON-based vaccination records
  • Service: Service catalog with JSONB multi-language fields
  • Staff: Employee profiles with working hours and specializations
  • StaffService: Junction table with proficiency levels
  • Setting: Key-value configuration store with JSONB values
  • AuditLog: Complete audit trail of user actions

Environment Variables Reference

Backend Environment Variables

VariableRequiredDescriptionExample
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@localhost:5432/db
NODE_ENVEnvironment modedevelopment, production
PORTBackend server port3001
BETTER_AUTH_URLBetter Auth endpointhttp://localhost:3001/api/auth
BETTER_AUTH_SECRETBetter Auth secret (32+ chars)Generated string
SESSION_SECRETSession encryption secretGenerated string
JWT_SECRETJWT signing secretGenerated string
FRONTEND_URLFrontend URL for CORShttp://localhost:3000
SMTP_HOSTEmail server hostsmtp.gmail.com
SMTP_PORTEmail server port587
SMTP_USEREmail usernamenoreply@example.com
SMTP_PASSEmail passwordYour password

Frontend Environment Variables

VariableRequiredDescriptionExample
NEXT_PUBLIC_API_URLBackend API URLhttp://localhost:3001
NEXT_PUBLIC_APP_URLFrontend app URLhttp://localhost:3000
GOOGLE_CLIENT_IDGoogle OAuth client IDFrom Google Console
GOOGLE_CLIENT_SECRETGoogle OAuth secretFrom Google Console
GITHUB_CLIENT_IDGitHub OAuth client IDFrom GitHub Settings
GITHUB_CLIENT_SECRETGitHub OAuth secretFrom GitHub Settings

Code Quality & Testing

Linting & Formatting

cd backend
npm run lint          # ESLint check
npm run format        # Prettier format

Type Checking

# Backend
cd backend
tsc --noEmit

# Frontend
cd frontend
tsc --noEmit

Running Tests

cd backend

# Unit tests
npm run test

# Watch mode
npm run test:watch

# Coverage report
npm run test:cov

# E2E tests
npm run test:e2e

Troubleshooting

Problem: connect ECONNREFUSED 127.0.0.1:5432Solution:
  1. Ensure PostgreSQL is running: brew services start postgresql (macOS)
  2. Check DATABASE_URL in .env
  3. Verify credentials: psql -U postgres
  4. Check PostgreSQL logs: tail -f /usr/local/var/log/postgres.log
Problem: Error: listen EADDRINUSE: address already in use :::3000Solution:
# Kill process on port (macOS/Linux)
lsof -ti:3000 | xargs kill -9

# Or use different port
PORT=3002 npm run dev
Problem: Application crashes with undefined env variablesSolution:
  1. Copy example env files to .env / .env.local
  2. Ensure all required variables are set
  3. Restart development server
Problem: PrismaClient not foundSolution:
cd backend
npm run prisma:generate
Problem: Cannot find module 'xxx'Solution:
# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

Next Steps

Architecture Overview

Understand system design and data flow

Deployment Guide

Deploy to production with Docker or Railway

API Reference

Explore REST API endpoints

Back to Home

Return to homepage

Need Help? Check Troubleshooting or reach out to support@petservice.example.com