@company-manager/docs
Development

Development Environment Setup

Complete guide to setting up the Company Manager development environment with all required tools and services.

Development Environment Setup

This guide walks you through setting up a complete development environment for the Company Manager monorepo.

🔧 Prerequisites

Required Software

Node.js & Bun

# Install Node.js 18.17.0+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Install Bun (recommended package manager)
curl -fsSL https://bun.sh/install | bash

Docker & Docker Compose

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Install Docker Compose
sudo apt-get install docker-compose-plugin

# Add user to docker group
sudo usermod -aG docker $USER

Go (for microservices)

# Install Go 1.21+
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc

PostgreSQL

# Install PostgreSQL
sudo apt-get install postgresql postgresql-contrib

# Start PostgreSQL service
sudo systemctl start postgresql
sudo systemctl enable postgresql

Redis

# Install Redis
sudo apt-get install redis-server

# Start Redis service
sudo systemctl start redis-server
sudo systemctl enable redis-server

📁 Repository Setup

Clone and Install

# Clone the repository
git clone <repository-url>
cd company-manager-new

# Install dependencies
bun install

# Verify installation
bun run --version

Environment Configuration

Main Application (.env.local)

# Copy environment template
cp apps/app/.env.example apps/app/.env.local

# Edit with your configuration
nano apps/app/.env.local

Required Environment Variables:

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/company_manager"
DIRECT_URL="postgresql://username:password@localhost:5432/company_manager"

# Authentication
NEXTAUTH_SECRET="your-super-secret-key"
NEXTAUTH_URL="http://localhost:3000"

# Redis
REDIS_URL="redis://localhost:6379"

# External Services (optional for development)
STRIPE_SECRET_KEY="sk_test_..."
RESEND_API_KEY="re_..."

Database Setup

# Create database
sudo -u postgres createdb company_manager

# Create user (optional)
sudo -u postgres psql -c "CREATE USER cm_user WITH PASSWORD 'password';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE company_manager TO cm_user;"

# Run migrations
cd packages/db
bunx prisma migrate dev
bunx prisma generate

# Seed database with sample data
bunx prisma db seed

🐳 Infrastructure Services

Start Infrastructure

# Start all infrastructure services
bun run infra:start

# This starts:
# - PostgreSQL (if using Docker)
# - Redis
# - Queue services
# - Monitoring services

Manual Service Setup

PostgreSQL with Docker

docker run --name postgres-cm \
  -e POSTGRES_DB=company_manager \
  -e POSTGRES_USER=cm_user \
  -e POSTGRES_PASSWORD=password \
  -p 5432:5432 \
  -d postgres:14

Redis with Docker

docker run --name redis-cm \
  -p 6379:6379 \
  -d redis:7-alpine

🚀 Development Workflow

Start Development Servers

Main Application

# Start the main web application
bun run dev:app

# Application will be available at:
# http://localhost:3000

Documentation

# Start documentation site
bun run dev:docs

# Documentation will be available at:
# http://localhost:3001

Infrastructure Dashboard

# Start Go-based infrastructure dashboard
cd apps/infra-dashboard-go
go run .

# Dashboard will be available at:
# http://localhost:8080

Verify Setup

# Check if all services are running
bun run infra:status

# Expected output:
# ✅ PostgreSQL: Connected
# ✅ Redis: Connected
# ✅ Queue Manager: Running
# ✅ Web App: http://localhost:3000
# ✅ Docs: http://localhost:3001

🔧 Development Tools

Code Quality Tools

ESLint & Prettier

# Install globally (optional)
bun add -g eslint prettier

# Run linting
bun run lint

# Fix linting issues
bun run lint:fix

# Format code
bun run format

TypeScript

# Type checking
bun run type-check

# Type check specific file
bunx tsc --noEmit src/components/Button.tsx

Database Tools

Prisma Studio

# Open database browser
cd packages/db
bunx prisma studio

# Available at: http://localhost:5555

Database CLI Commands

# Reset database (development only)
bunx prisma migrate reset

# Generate Prisma client
bunx prisma generate

# View database schema
bunx prisma db pull

Testing Tools

# Run all tests
bun run test

# Run tests in watch mode
bun run test:watch

# Run tests with coverage
bun run test:coverage

# Run E2E tests
bun run test:e2e

🌐 Browser Extensions Development

Chrome Extension

# Build development version
cd apps/chrome-extension-dev
bun run build

# Load extension in Chrome:
# 1. Open chrome://extensions/
# 2. Enable "Developer mode"
# 3. Click "Load unpacked"
# 4. Select apps/chrome-extension-dev/dist

VSCode Extension

# Install development dependencies
cd apps/vscode-extension
bun install

# Build extension
bun run build

# Test extension:
# 1. Open VSCode
# 2. Press F5 to launch Extension Development Host

📱 Mobile Development

React Native Setup

# Install React Native CLI
bun add -g @react-native-community/cli

# iOS development (macOS only)
sudo gem install cocoapods

# Android development
# Install Android Studio and set ANDROID_HOME

Mobile App Development

cd apps/app-mobile

# Install dependencies
bun install

# Start Metro bundler
bun run start

# Run on iOS simulator
bun run ios

# Run on Android emulator
bun run android

🖥️ Desktop Development

Electron Setup

cd apps/desktop-app-dev

# Install dependencies
bun install

# Start development server
bun run dev

# Build desktop app
./build.sh

🔍 Troubleshooting

Common Issues

Port Conflicts

# Check what's running on ports
lsof -i :3000
lsof -i :5432
lsof -i :6379

# Kill processes if needed
sudo kill -9 <PID>

Database Connection Issues

# Check PostgreSQL status
sudo systemctl status postgresql

# Reset PostgreSQL password
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'newpassword';"

# Test connection
psql -h localhost -U postgres -d company_manager

Permission Issues

# Fix npm/bun permissions
sudo chown -R $(whoami) ~/.bun
sudo chown -R $(whoami) ~/.npm

# Fix Docker permissions
sudo usermod -aG docker $USER
# Log out and back in

Memory Issues

# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=4096"

# Or add to ~/.bashrc
echo 'export NODE_OPTIONS="--max-old-space-size=4096"' >> ~/.bashrc

Health Checks

# System health check
bun run health:check

# Comprehensive system info
bun run system:info

# Performance monitoring
bun run monitor:performance

📊 Performance Optimization

Development Optimizations

# Enable development optimizations
bun run optimize:dev

# Clear development caches
bun run clean:cache

# Warm up development environment
bun run warm:dev

Build Optimizations

# Analyze bundle size
bun run analyze:bundle

# Check for unused dependencies
bun run analyze:deps

# Performance analysis
bun run analyze:performance

🔒 Security Setup

Development Security

# Generate secure keys
openssl rand -base64 32

# Set up local HTTPS (optional)
mkcert localhost 127.0.0.1 ::1

# Environment variable validation
bun run validate:env

📚 Next Steps

After completing the setup:

  1. Explore the Application: Visit http://localhost:3000
  2. Review Documentation: Visit http://localhost:3001
  3. Check System Status: Run bun run infra:status
  4. Run Tests: Execute bun run test
  5. Start Development: Create your first feature

Additional Resources


If you encounter any issues during setup, check the Troubleshooting Guide or create an issue in the project repository.