Skip to main content
What you’ll get out of this: Get up and running with DeelRx CRM development, including environment setup, project structure, development workflow, and contribution guidelines.

Prerequisites

Required Software

Node.js

  • Node.js 20+ (LTS recommended)
  • npm or pnpm package manager
  • TypeScript 5.0+

Database

  • PostgreSQL 16+ (local or cloud)
  • Redis 7+ (for caching)
  • Database connection string

Development Tools

  • Code Editor: VS Code with recommended extensions
  • Git: Version control system
  • Docker: For containerized development (optional)
  • API Testing: Postman or Insomnia for API testing

Quick Start

1. Clone the Repository

git clone https://github.com/deelrxcrm/crm-main-3.git
cd crm-main-3

2. Install Dependencies

# Install pnpm globally if not already installed
npm install -g pnpm

# Install all dependencies
pnpm install

3. Environment Setup

1

Copy Environment File

Copy the example environment file and configure your settings.
2

Database Setup

Set up PostgreSQL database and run migrations.
3

Redis Setup

Configure Redis for caching and session storage.
4

Authentication Setup

Configure Clerk authentication with your keys.
# Copy environment template
cp .env.example .env.local

# Edit environment variables
nano .env.local

4. Start Development

# Start all services in development mode
pnpm dev

# Or start specific services
pnpm dev --filter=deelrxcrm-app
pnpm dev --filter=@repo/api
pnpm dev --filter=@repo/docs

Project Structure

Monorepo Architecture

crm-main-3/
├── apps/                    # Applications
│   ├── app/                 # Main CRM application
│   ├── api/                 # API service
│   ├── docs/                # Documentation site
│   ├── email/               # Email service
│   ├── studio/               # Database studio
│   ├── storybook/           # Component library
│   └── web/                 # Marketing website
├── packages/                # Shared packages
│   ├── ai/                  # AI intelligence features
│   ├── analytics/           # Analytics and reporting
│   ├── auth/                # Authentication
│   ├── cache/               # Caching layer
│   ├── cms/                 # Content management
│   ├── collaboration/       # Real-time collaboration
│   ├── database/            # Database layer
│   ├── design-system/       # UI components
│   ├── email/               # Email functionality
│   ├── feature-flags/       # Feature flag system
│   ├── next-config/         # Next.js configuration
│   ├── notifications/       # Notifications
│   ├── observability/       # Monitoring and logging
│   ├── payments/            # Payment processing
│   ├── rate-limit/          # Rate limiting
│   ├── security/            # Security utilities
│   ├── seo/                 # SEO optimization
│   ├── storage/             # File storage
│   ├── testing/             # Testing utilities
│   ├── typescript-config/   # TypeScript configuration
│   └── webhooks/            # Webhook handling
├── docs/                    # Documentation
├── scripts/                 # Build and deployment scripts
└── tools/                   # Development tools

Package Dependencies

  • Next.js 15+: React framework with App Router
  • React 19+: UI library with latest features
  • TypeScript 5+: Type-safe JavaScript
  • Tailwind CSS: Utility-first CSS framework
  • Prisma: Database ORM and migrations
  • Clerk: User authentication and management
  • NextAuth.js: Alternative authentication
  • bcrypt: Password hashing
  • JWT: JSON Web Tokens
  • PostgreSQL: Primary database
  • Redis: Caching and session storage
  • Prisma: Database ORM
  • Upstash: Redis cloud service
  • OpenAI: AI model integration
  • Vercel AI SDK: AI utilities
  • PostHog: Analytics and feature flags
  • Sentry: Error monitoring

Development Workflow

Git Workflow

Branch Strategy

1

Create Feature Branch

Create a new branch from main for your feature.
2

Develop Feature

Implement your feature with tests and documentation.
3

Test Changes

Run tests and ensure code quality standards.
4

Create Pull Request

Submit a pull request for code review.
5

Code Review

Address feedback and make necessary changes.
6

Merge to Main

Merge approved changes to main branch.

Commit Convention

# Use conventional commits
feat: add customer search functionality
fix: resolve inventory sync issue
docs: update API documentation
test: add unit tests for payment processing
refactor: improve database query performance

Code Quality

Linting and Formatting

# Run linting
pnpm lint

# Fix linting issues
pnpm lint:fix

# Format code
pnpm format

# Type checking
pnpm type-check

Testing

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test:coverage

# Run specific test suites
pnpm test --filter=@repo/database

Environment Configuration

Environment Variables

Required Variables

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/deelrxcrm"
DIRECT_URL="postgresql://user:password@localhost:5432/deelrxcrm"

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

# Authentication
NEXTAUTH_SECRET="your-secret-key"
NEXTAUTH_URL="http://localhost:3000"
CLERK_SECRET_KEY="your-clerk-secret-key"
CLERK_PUBLISHABLE_KEY="your-clerk-publishable-key"

# AI Services
OPENAI_API_KEY="your-openai-api-key"

# Analytics
POSTHOG_KEY="your-posthog-key"
POSTHOG_HOST="https://app.posthog.com"

# Monitoring
SENTRY_DSN="your-sentry-dsn"

Optional Variables

# Email
RESEND_API_KEY="your-resend-api-key"
SMTP_HOST="smtp.gmail.com"
SMTP_PORT="587"
SMTP_USER="[email protected]"
SMTP_PASS="your-app-password"

# Storage
AWS_ACCESS_KEY_ID="your-aws-access-key"
AWS_SECRET_ACCESS_KEY="your-aws-secret-key"
AWS_REGION="us-east-1"
AWS_S3_BUCKET="your-s3-bucket"

# Payments
STRIPE_SECRET_KEY="your-stripe-secret-key"
STRIPE_PUBLISHABLE_KEY="your-stripe-publishable-key"
STRIPE_WEBHOOK_SECRET="your-stripe-webhook-secret"

Database Setup

Local Development

# Start PostgreSQL (using Docker)
docker run --name deelrxcrm-postgres \
  -e POSTGRES_DB=deelrxcrm \
  -e POSTGRES_USER=deelrxcrm \
  -e POSTGRES_PASSWORD=deelrxcrm_password \
  -p 5432:5432 \
  -d postgres:16-alpine

# Start Redis
docker run --name deelrxcrm-redis \
  -p 6379:6379 \
  -d redis:7-alpine

# Run database migrations
pnpm migrate

# Seed development data
pnpm seed

Cloud Development

# Using Neon (PostgreSQL cloud)
# Set DATABASE_URL to your Neon connection string

# Using Upstash (Redis cloud)
# Set REDIS_URL to your Upstash connection string

Development Tools

VS Code Setup

Essential Extensions

  • TypeScript and JavaScript Language Features
  • Tailwind CSS IntelliSense
  • Prisma
  • GitLens
  • ESLint
  • Prettier

Productivity Extensions

  • Auto Rename Tag
  • Bracket Pair Colorizer
  • Git Graph
  • REST Client
  • Thunder Client

Workspace Settings

{
  "typescript.preferences.importModuleSpecifier": "relative",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "tailwindCSS.includeLanguages": {
    "typescript": "javascript",
    "typescriptreact": "javascript"
  }
}

Debugging

VS Code Debug Configuration

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node",
      "request": "attach",
      "port": 9229,
      "skipFiles": ["<node_internals>/**"]
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000"
    }
  ]
}

Database Debugging

# Connect to database
pnpm db:studio

# View database schema
pnpm db:generate

# Reset database
pnpm db:reset

API Development

API Structure

RESTful Endpoints

// API routes follow RESTful conventions
GET    /api/customers          // List customers
POST   /api/customers          // Create customer
GET    /api/customers/[id]     // Get customer
PUT    /api/customers/[id]     // Update customer
DELETE /api/customers/[id]     // Delete customer

API Documentation

  • OpenAPI Specification: Auto-generated API docs
  • Postman Collection: Importable API collection
  • TypeScript Types: Generated from API schema
  • Testing Examples: Request/response examples

Database Development

Prisma Schema

// Example model definition
model Customer {
  id        String   @id @default(cuid())
  email     String   @unique
  firstName String
  lastName  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  
  orders Order[]
  
  @@map("customers")
}

Database Migrations

# Create migration
pnpm db:migrate:dev

# Apply migrations
pnpm db:migrate:deploy

# Reset database
pnpm db:migrate:reset

# Generate Prisma client
pnpm db:generate

Testing Strategy

Testing Pyramid

Unit Tests

  • Component testing
  • Utility function testing
  • Business logic testing
  • Fast execution

Integration Tests

  • API endpoint testing
  • Database integration
  • External service testing
  • Medium execution time

E2E Tests

  • User workflow testing
  • Cross-browser testing
  • Performance testing
  • Slower execution

Testing Tools

Unit Testing

# Run unit tests
pnpm test:unit

# Run with coverage
pnpm test:unit:coverage

# Watch mode
pnpm test:unit:watch

Integration Testing

# Run integration tests
pnpm test:integration

# Test specific modules
pnpm test:integration --grep "payments"

E2E Testing

# Run E2E tests
pnpm test:e2e

# Run in headless mode
pnpm test:e2e:headless

# Generate test reports
pnpm test:e2e:report

Performance Optimization

Development Performance

Build Optimization

# Analyze bundle size
pnpm analyze

# Check for unused dependencies
pnpm depcheck

# Optimize images
pnpm optimize:images

Runtime Performance

  • Code Splitting: Automatic route-based splitting
  • Image Optimization: Next.js Image component
  • Caching: Redis caching layer
  • Database Optimization: Query optimization

Monitoring

Development Monitoring

# Start monitoring
pnpm monitor:dev

# View performance metrics
pnpm metrics

# Check error rates
pnpm errors

Deployment

Local Deployment

# Build for production
pnpm build

# Start production server
pnpm start

# Run in Docker
docker-compose up

Cloud Deployment

Vercel Deployment

# Deploy to Vercel
vercel --prod

# Set environment variables
vercel env add DATABASE_URL
vercel env add REDIS_URL

Docker Deployment

# Build Docker image
docker build -t deelrxcrm .

# Run container
docker run -p 3000:3000 deelrxcrm

Contributing

Contribution Guidelines

  • Follow the coding standards and style guide
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Use conventional commit messages
  • Ensure all CI checks pass
  • Request code review from team members

Pull Request Process

1

Fork Repository

Fork the repository to your GitHub account.
2

Create Branch

Create a feature branch from main.
3

Make Changes

Implement your changes with tests and documentation.
4

Test Changes

Run all tests and ensure they pass.
5

Submit PR

Create a pull request with a clear description.
6

Address Feedback

Respond to code review feedback and make changes.

Troubleshooting

Common Issues

Verify your DATABASE_URL is correct and the database is running. Check firewall settings and network connectivity.
Ensure Redis is running and the REDIS_URL is properly configured. Check Redis server logs for errors.
Clear node_modules and reinstall dependencies. Check for TypeScript errors and missing dependencies.

Getting Help

  • Documentation: Check the comprehensive documentation
  • GitHub Issues: Report bugs and request features
  • Discord Community: Join our developer community
  • Email Support: Contact [email protected]

Next Steps