Skip to content
cDurhamPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

111 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dharma

Full-stack NX monorepo with NestJS GraphQL API backend and React frontend.

πŸš€ Quick Start

Prerequisites

  • Node.js >= 20.0.0 (includes npm automatically)
  • Docker & Docker Compose (for containerized setup)

Installing Prerequisites

macOS

Option 1: Using Homebrew (Recommended)

# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Node.js (includes npm)
brew install node@20

# Add to PATH (node@20 is keg-only and won't be linked automatically)
echo 'export PATH="/opt/homebrew/opt/node@20/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# Verify installation
node --version   # Should be >= 20.0.0
npm --version    # Should be >= 10.0.0

# Install Docker Desktop
brew install --cask docker

# Start Docker Desktop from Applications folder
# Or from command line:
open -a Docker

Option 2: Using Official Installers

  1. Node.js:

  2. Docker Desktop:

Linux (Ubuntu/Debian)
# Update package index
sudo apt update

# Install Node.js 20.x via NodeSource
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# Verify installation
node --version   # Should be >= 20.0.0
npm --version    # Should be >= 10.0.0

# Install Docker
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Add your user to docker group (to run docker without sudo)
sudo usermod -aG docker $USER
newgrp docker

# Verify Docker installation
docker --version
docker compose version
Linux (Fedora/RHEL/CentOS)
# Install Node.js 20.x
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo dnf install -y nodejs

# Verify installation
node --version
npm --version

# Install Docker
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start Docker
sudo systemctl start docker
sudo systemctl enable docker

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

# Verify Docker installation
docker --version
docker compose version
Windows

Option 1: Using Winget (Windows Package Manager)

# Install Node.js
winget install OpenJS.NodeJS.LTS

# Install Docker Desktop
winget install Docker.DockerDesktop

# Restart your terminal and verify
node --version
npm --version
docker --version
docker compose version

Option 2: Using Chocolatey

# Install Chocolatey first if you don't have it
# Run PowerShell as Administrator:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

# Install Node.js and Docker
choco install nodejs-lts
choco install docker-desktop

# Restart your terminal and verify
node --version
npm --version
docker --version

Option 3: Manual Installation

  1. Node.js:

  2. Docker Desktop:

Verify All Prerequisites

# Check versions
node --version    # Should show v20.x.x or higher
npm --version     # Should show 10.x.x or higher
docker --version  # Should show Docker version info
docker compose version  # Should show Docker Compose version info

# Test Docker is running
docker run hello-world

1. Clone & Install

# Clone the repository
git clone <your-repo-url>
cd dharma

# Install dependencies
npm install

2. Environment Setup

# Copy the example environment file
cp env.example .env

### 3. Build the Dharma CLI

```bash
# Build the custom CLI tool (one-time setup)
npm run cli:build

# Make it globally accessible (optional but recommended)
npm link

4. Run with Docker (Recommended)

# Start all services in development mode
dharma dev up

# This starts:
# - PostgreSQL (port 5432)
# - Kafka + Zookeeper (port 9092)
# - API server (port 3000)
# - Web frontend (port 4200)

Access the application:

5. Initialize Database

# Reset database schema and seed data
dharma db reset

# Or run individually:
dharma db push    # Push schema
dharma db seed    # Seed data

πŸ› οΈ Development

Dharma CLI Commands (Recommended)

The project includes a custom CLI tool for streamlined development:

# Development Environment
dharma dev up           # Start development environment
dharma dev down         # Stop development environment
dharma dev restart      # Restart development environment
dharma dev rebuild api  # Rebuild API service
dharma dev rebuild web  # Rebuild web service
dharma dev rebuild all  # Rebuild everything
dharma dev reset        # Full teardown and fresh rebuild
dharma dev nuke         # Complete cleanup (removes volumes)

# Service Status & Logs
dharma status           # Show status of all services (alias: dharma ps)
dharma logs api         # View API logs
dharma logs web         # View web logs
dharma logs api web     # View multiple service logs

# Execute Commands in Containers
dharma exec api sh      # Open shell in API container
dharma exec web sh      # Open shell in web container

# Database Operations
dharma db push          # Push database schema
dharma db seed          # Seed database
dharma db reset         # Reset database (push + seed)

Service Aliases: You can use short names (api, web) or full names (api-dev, web-dev) - they're equivalent in dev mode.

Alternative: Local Development (without Docker)

If you prefer running services locally outside Docker:

1. Start Infrastructure Services

# Start only PostgreSQL and Kafka (using Docker for infrastructure)
docker compose up db kafka zookeeper -d

2. Run API

# Terminal 1: Run API server locally
npm run api:serve

# The API will be available at http://localhost:3000
# GraphQL Playground: http://localhost:3000/graphql

3. Run Web Frontend

# Terminal 2: Run web dev server locally
npm run web:serve

# The frontend will be available at http://localhost:4200

Code Generation

# Generate TypeScript types from GraphQL schema (both apps)
npm run codegen

# Generate for specific app
npm run web:codegen    # Frontend GraphQL client types
npm run api:codegen    # API (currently not configured)

πŸ§ͺ Testing

# Run all tests
nx run-many --target=test

# Test specific app
npm run api:test
npm run web:test

# Run tests in watch mode
nx test api --watch
nx test web --watch

πŸ—„οΈ Database Management

# Using Dharma CLI (Recommended)
dharma db reset    # Reset database (push schema + seed)
dharma db push     # Push schema changes
dharma db seed     # Seed data only

# Alternative: Using npm scripts (if not using Docker)
npm run api:db:reset
npm run api:db:sync
npm run api:db:seed

Connect to PostgreSQL:

# Via Dharma CLI
dharma exec db psql -U postgres -d dharma_db

# Or via Docker directly
docker compose exec db psql -U postgres -d dharma_db

# Or locally (if psql is installed)
psql -h localhost -p 5432 -U postgres -d dharma_db

πŸ—οΈ Project Structure

dharma/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                    # NestJS GraphQL API
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ Auth/           # Authentication module
β”‚   β”‚   β”‚   β”œβ”€β”€ User/           # User management (CQRS)
β”‚   β”‚   β”‚   β”œβ”€β”€ Member/         # Member module (CQRS)
β”‚   β”‚   β”‚   β”œβ”€β”€ Retreat/        # Retreat module (CQRS)
β”‚   β”‚   β”‚   β”œβ”€β”€ Email/          # Email service
β”‚   β”‚   β”‚   β”œβ”€β”€ kafka/          # Kafka integration
β”‚   β”‚   β”‚   β”œβ”€β”€ db/             # Database config & seeds
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   └── project.json        # NX project config
β”‚   β”‚
β”‚   └── web/                    # React + Vite frontend
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ component/      # React components
β”‚       β”‚   β”œβ”€β”€ graphql/        # GraphQL queries & generated types
β”‚       β”‚   └── ...
β”‚       └── project.json        # NX project config
β”‚
β”œβ”€β”€ docker-compose.yml          # Docker orchestration
β”œβ”€β”€ Dockerfile                  # Multi-stage build
β”œβ”€β”€ nx.json                     # NX workspace config
└── package.json                # Dependencies & scripts

πŸ“¦ Available Scripts

Workspace Commands

npm run clean              # Clean dist folder
npm run codegen            # Run code generation for all apps

API Commands

npm run api:serve          # Start API dev server
npm run api:build          # Build API for production
npm run api:lint           # Lint API code
npm run api:test           # Run API tests
npm run api:db:reset       # Reset & seed database
npm run api:db:sync        # Sync database schema
npm run api:db:seed        # Seed database

Web Commands

npm run web:serve          # Start web dev server
npm run web:build          # Build web for production
npm run web:lint           # Lint web code
npm run web:test           # Run web tests
npm run web:codegen        # Generate GraphQL types

Docker/CLI Commands

# Using Dharma CLI (Recommended)
dharma dev up              # Start dev environment
dharma dev down            # Stop dev environment
dharma dev restart         # Restart dev environment
dharma dev rebuild all     # Rebuild dev environment
dharma dev rebuild api     # Rebuild only API service
dharma status              # Show service status
dharma logs api web        # View logs

# Using npm scripts (alternative)
npm run d:dev              # Start dev profile
npm run d:prod             # Start prod profile
npm run d:dev:restart      # Restart dev environment
npm run d:dev:rebuild      # Rebuild dev environment
npm run d:dev:rebuild:api  # Rebuild only API service

πŸ“Œ Dependency Currency

pnpm run deps          # drift + advisories + version-policy invariants
pnpm run deps:majors   # also list every package behind a major
pnpm run deps:ci       # invariants only β€” no network, <1s, exits 1 on violations

Renovate (renovate.json) opens the upgrade PRs, grouped by release train and automerging only patch/minor devDependencies and @types/*. It is inert until enabled on the repository.

pnpm run deps additionally checks invariants no dependency bot covers: a single root lockfile, Node major agreement across .nvmrc / engines / Dockerfile, biome.json's $schema matching the installed Biome, pnpm catalog coverage for anything shared between workspace packages, and workflow action pinning.

See docs/adr/0002-dependency-currency.md for the rationale.

🚒 Production Deployment

Build & Run with Docker

# Start production profile
npm run d:prod

# This builds and runs:
# - API server (port 3000)
# - Web frontend with Nginx (port 8080)
# - PostgreSQL
# - Kafka

Access production build:

Build Locally

# Build both apps
nx run-many --target=build

# Build specific app
npm run api:build    # Output: dist/apps/api
npm run web:build    # Output: dist/apps/web

πŸ” NX Features

Dependency Graph

# Visualize project dependencies
npx nx graph

Affected Commands

# Only build/test what changed
nx affected --target=build
nx affected --target=test

Run Multiple Targets

# Run target across all projects
nx run-many --target=lint
nx run-many --target=test
nx run-many --target=build --parallel=3

πŸ› Troubleshooting

Port Already in Use

# Check what's using a port
lsof -i :3000    # API port
lsof -i :4200    # Web port
lsof -i :5432    # PostgreSQL port

# Stop Docker containers
dharma dev down

Database Connection Issues

# Verify database is running
dharma status

# Check database logs
dharma logs db

# Reset database
dharma db reset

Kafka Connection Issues

# Check Kafka health
dharma status

# View Kafka logs
dharma logs kafka

# Restart entire environment
dharma dev restart

Node Modules Issues

# Clean install locally
rm -rf node_modules
npm install

# Rebuild Docker containers
dharma dev rebuild all

Hot Reload Not Working

Docker volumes are configured for hot-reload in dev mode. If changes aren't reflecting:

# Restart development services
dharma dev restart

# Or rebuild specific service
dharma dev rebuild api  # or web

# Or full rebuild
dharma dev rebuild all

Complete Environment Reset

If everything is broken and you want to start fresh:

# Nuclear option: complete teardown and rebuild
dharma dev nuke   # Stop everything and remove volumes
dharma dev up     # Start fresh

# Or use reset (stops, rebuilds, starts)
dharma dev reset

πŸ“š Key Technologies

  • NX - Monorepo build system
  • NestJS - Backend framework
  • GraphQL - API query language
  • Drizzle ORM - Database ORM
  • CQRS - Command Query Responsibility Segregation pattern
  • React - Frontend library
  • Vite - Frontend build tool
  • Apollo Client - GraphQL client
  • PostgreSQL - Database
  • Kafka - Event streaming
  • Docker - Containerization

πŸ“ License

[Your License Here]

🀝 Contributing

[Your Contributing Guidelines Here]

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages