SimpleNS LogoDocs

Local Development

Set up a complete SimpleNS development environment using VS Code Dev Containers. This guide covers the pre-configured devcontainer setup for streamlined local development.


Overview

SimpleNS includes a pre-configured Dev Container setup that provides a complete development environment with all required tools, extensions, and infrastructure services. This allows you to start contributing or customizing SimpleNS without manual environment setup.

Dev Containers work with VS Code and GitHub Codespaces. The configuration automatically sets up Node.js, Docker-in-Docker, and all required VS Code extensions.


Prerequisites

Before you begin, ensure you have the following installed:

  • Docker Desktop (Windows/Mac) or Docker Engine (Linux)
  • VS Code with the Dev Containers extension
  • Git for cloning the repository

Alternatively, you can use GitHub Codespaces which requires no local setup—just a GitHub account.


Getting Started

Clone the Repository

git clone https://github.com/SimpleNotificationSystem/simplens-core.git
cd simplens-core

Open in Dev Container

  1. Open the cloned folder in VS Code
  2. When prompted, click "Reopen in Container"

Or manually:

  1. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac)
  2. Type "Dev Containers: Reopen in Container"
  3. Press Enter

The first build may take a few minutes while Docker pulls the base image and installs dependencies.

  1. Navigate to the repository on GitHub
  2. Click the green "Code" button
  3. Select "Codespaces" tab
  4. Click "Create codespace on main"

GitHub Codespaces provides a cloud-hosted development environment with the same configuration.

Wait for Setup

The Dev Container automatically runs post-creation commands:

# Automatically executed on container creation:
npm install && cd dashboard && npm install

Once complete, infrastructure services start automatically:

# Automatically executed on container start:
docker compose -f docker-compose.infra.yaml up -d

Verify Environment

After the container is ready, verify the setup:

# Check Node.js
node --version  # Should show Node.js 18+

# Check Docker-in-Docker
docker ps  # Should list running infrastructure containers

# Verify infrastructure services
docker compose -f docker-compose.infra.yaml ps

Dev Container Configuration

The .devcontainer/devcontainer.json configures the development environment:

Base Image

{
  "name": "SimpleNS Devcontainer",
  "image": "mcr.microsoft.com/devcontainers/typescript-node"
}

Uses Microsoft's TypeScript/Node.js development container image which includes:

  • Node.js LTS
  • TypeScript
  • Common development utilities

Docker-in-Docker

{
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {
      "moby": false
    }
  }
}

Why Docker-in-Docker?

This allows you to run Docker commands inside the container to manage infrastructure services (MongoDB, Kafka, Redis) and test Docker-based deployments.

VS Code Extensions

The following extensions are automatically installed:

Prettier

Code formatting - esbenp.prettier-vscode

ESLint

Linting - dbaeumer.vscode-eslint

Tailwind CSS

IntelliSense - bradlc.vscode-tailwindcss

Docker

Container management - ms-azuretools.vscode-docker

Vitest

Test explorer - vitest.explorer

MongoDB

Database tools - mongodb.mongodb-vscode

Environment Variables

{
  "remoteEnv": {
    "NODE_ENV": "development",
    "INFRA_HOST": "localhost"
  }
}
VariableValueDescription
NODE_ENVdevelopmentEnables development mode features
INFRA_HOSTlocalhostInfrastructure services hostname

Infrastructure Services

The Dev Container automatically starts infrastructure services via docker-compose.infra.yaml:

MongoDB

Document database with replica set - Port 27017

Apache Kafka

Message broker (KRaft mode) - Port 9092

Kafka UI

Topic monitoring interface - Port 8080

Redis

In-memory cache & queues - Port 6379

Loki

Log aggregation - Port 3100

Grafana

Log visualization - Port 3001

Managing Infrastructure

# View running services
docker compose -f docker-compose.infra.yaml ps

# View logs
docker compose -f docker-compose.infra.yaml logs -f

# Stop services
docker compose -f docker-compose.infra.yaml down

# Restart services
docker compose -f docker-compose.infra.yaml restart

Running the Application

Once the Dev Container is ready, start the application services:

Configure Environment

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

# Edit the .env file with your settings

Make sure to update the required environment variables like NS_API_KEY and ADMIN_PASSWORD.

Generate Plugin Configuration

# Generate config for mock plugin (for testing)
npx @simplens/config-gen generate @simplens/mock

Start Application Services

Start in development mode with hot reload. Each service runs in a separate terminal:

# Terminal 1: API Server
npm run dev

# Terminal 2: Background Worker (status updates processing)
npm run worker:dev

# Terminal 3: Notification Processor (plugin-based delivery)
npm run processor:dev

# Terminal 4: Delayed Processor (scheduled notifications)
npm run delayed-processor:dev

# Terminal 5: Recovery Service (stuck notification detection)
npm run recovery:dev
# Terminal 6: Dashboard (in dashboard directory)
cd dashboard && npm run dev

Use VS Code's split terminal feature or terminal tabs to manage multiple processes.

Start all services with Docker Compose:

docker compose -f docker-compose.dev.yaml up -d

Verify Services


Running Tests

The Dev Container includes the Vitest extension for running tests:

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Use the Vitest Explorer extension in VS Code sidebar for an interactive test runner.


Troubleshooting

Container fails to start

Check Docker Desktop is running:

  • Ensure Docker Desktop (or Docker Engine) is running before opening VS Code

Rebuild the container:

  1. Press Ctrl+Shift+P → "Dev Containers: Rebuild Container"
  2. Wait for the rebuild to complete

Infrastructure services not running

Manually start services:

docker compose -f docker-compose.infra.yaml up -d

Check Docker-in-Docker:

docker ps
# Should show infrastructure containers

MongoDB connection issues

Wait for replica set initialization: MongoDB replica set initialization can take up to 30 seconds. Check the health status:

docker compose -f docker-compose.infra.yaml ps mongo
# Should show 'healthy' status

Extension not working

Reload VS Code:

  1. Press Ctrl+Shift+P → "Developer: Reload Window"
  2. Wait for extensions to activate

For more issues, see the Troubleshooting Guide.

On this page