This guide will help you set up the Carrots application for local development.
Before you begin, ensure you have the following installed:
- Node.js 18 or higher (Download)
- PostgreSQL 14 or higher (Download)
- npm 9 or higher (comes with Node.js)
- Git (Download)
- (Optional) Docker for containerized development (Download)
The fastest way to get started is using Docker Compose:
# Clone the repository
git clone https://github.com/pik-gane/carrots.git
cd carrots
# Set up environment variables
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env
# Edit backend/.env and add your OpenAI API key (for NLP features)
# OPENAI_API_KEY=sk-your-key-here
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Access the application
# Frontend: http://localhost:3000
# Backend: http://localhost:3001
# Health check: http://localhost:3001/healthTo stop the services:
docker-compose downIf you prefer to run services individually:
# Create a new database
createdb carrots_dev
# Or using psql
psql -U postgres
CREATE DATABASE carrots_dev;
\qcd backend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env file with your configuration:
# - DATABASE_URL: Your PostgreSQL connection string
# - JWT_SECRET: A secure random string
# - OPENAI_API_KEY: Your OpenAI API key (optional for now)
# Generate Prisma client
npm run prisma:generate
# Run database migrations
npm run prisma:migrate:dev
# (Optional) Seed the database with sample data
npm run prisma:seed
# Start the development server
npm run devThe backend should now be running at http://localhost:3001
Open a new terminal:
cd frontend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env if needed (default API URL is http://localhost:3001)
# Start the development server
npm startThe frontend should now be running at http://localhost:3000
-
Check Backend Health:
curl http://localhost:3001/health
Should return:
{"status":"ok","timestamp":"..."} -
Check Frontend: Open http://localhost:3000 in your browser
# Backend tests
cd backend
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage
# Frontend tests
cd frontend
npm test# Backend
cd backend
npm run lint
npm run format
# Frontend
cd frontend
npm run lint
npm run formatWhen you modify the Prisma schema:
cd backend
# Create a new migration
npm run prisma:migrate:dev
# Apply migrations
npm run prisma:migrate
# Reset database (⚠️ Deletes all data!)
npm run prisma:resetTo visually explore and edit your database:
cd backend
npx prisma studioOpens at http://localhost:5555
carrots/
├── backend/ # Node.js/Express backend
│ ├── prisma/ # Database schema and migrations
│ │ └── schema.prisma # Database models
│ ├── src/
│ │ ├── middleware/ # Express middleware
│ │ ├── models/ # Data models (if not using Prisma)
│ │ ├── routes/ # API routes
│ │ ├── services/ # Business logic
│ │ │ └── liabilityCalculator.ts # Core algorithm
│ │ ├── types/ # TypeScript type definitions
│ │ ├── utils/ # Utility functions
│ │ └── server.ts # Application entry point
│ ├── package.json
│ └── tsconfig.json
├── frontend/ # React frontend
│ ├── public/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── pages/ # Page components
│ │ ├── services/ # API services
│ │ ├── types/ # TypeScript type definitions
│ │ ├── utils/ # Utility functions
│ │ ├── App.tsx # Main App component
│ │ └── index.tsx # Entry point
│ ├── package.json
│ └── tsconfig.json
├── docs/ # Documentation
│ └── API.md # API documentation
├── docker/ # Docker configurations
├── ARCHITECTURE.md # Architecture documentation
├── IMPLEMENTATION_STRATEGY.md # Development roadmap
└── docker-compose.yml # Docker Compose configuration
- Create a route file in
backend/src/routes/ - Implement the route handler
- Add validation schemas
- Write tests
- Update API documentation in
docs/API.md
- Create a component in
frontend/src/pages/ - Add the route in
frontend/src/App.tsx - Create any necessary child components
- Add API service calls if needed
- Write tests
- Modify
backend/prisma/schema.prisma - Run
npm run prisma:migrate:dev - Update TypeScript types if needed
- Update seed data if applicable
If you see an error about ports already being in use:
# Find and kill the process using the port
# On macOS/Linux:
lsof -ti:3001 | xargs kill -9
# On Windows:
netstat -ano | findstr :3001
taskkill /PID <PID> /F-
Verify PostgreSQL is running:
pg_isready
-
Check your DATABASE_URL in
.env -
Ensure the database exists:
psql -l | grep carrots
If you get Prisma client errors, regenerate it:
cd backend
npm run prisma:generateClear caches and reinstall:
# Backend
cd backend
rm -rf node_modules package-lock.json
npm install
# Frontend
cd frontend
rm -rf node_modules package-lock.json
npm install# Database connection
DATABASE_URL="postgresql://user:password@localhost:5432/carrots_dev"
# JWT secret for authentication (generate a secure random string)
JWT_SECRET="your-super-secret-jwt-key"
# OpenAI API key (for natural language processing)
OPENAI_API_KEY="sk-your-openai-api-key"
# Server port
PORT=3001
# Node environment
NODE_ENV=development
# CORS origin (frontend URL)
CORS_ORIGIN="http://localhost:3000"# Backend API URL
REACT_APP_API_URL=http://localhost:3001- Review the Architecture Documentation
- Read the Implementation Strategy
- Check out the API Documentation
- Start implementing features according to the roadmap
- Check existing documentation in the
/docsfolder - Review the implementation strategy for guidance
- Check the issue tracker on GitHub
- Create a feature branch from
main - Make your changes
- Write/update tests
- Run linters and tests
- Submit a pull request
Happy coding! 🥕