npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cdklib/argo-synth

v0.2.0

Published

Manage ArgoCD structure with cdk8s

Downloads

47

Readme

@cdklib/argo-synth

A directory structure management library for cdk8s projects that enables GitOps-friendly output organization for ArgoCD.

Why This Exists

cdk8s is a great way to build Kubernetes applications. However, cdk8s's default synthesis behaviors are not argo-friendly.

ArgoCD works best with a directory structure that organizes Kubernetes resources by environment and application.

@cdklib/argo-synth provides a simple way to organize your cdk8s synthesized resources into a clean directory structure that's optimal for ArgoCD's path-based applications.

Key Features

  • Simple - Offers a clear path-based organization approach for cdk8s projects
  • ArgoCD-Optimized - Creates a directory structure that maps perfectly to ArgoCD application paths
  • Path Inheritance - Supports path building for complex directory structures
  • Multi-Environment - Easily manage multiple environments in a single GitOps repository

Table of Contents

Installation

# Using npm
npm install @cdklib/argo-synth

# Using yarn
yarn add @cdklib/argo-synth

# Using pnpm
pnpm add @cdklib/argo-synth

Key Features

  • 🗂️ Structured Output: Organize Kubernetes manifests in a directory structure that mirrors your environments and applications
  • 🚀 GitOps Ready: Generate files in a format optimal for ArgoCD and GitOps workflows
  • 🔄 Multi-Environment Support: Easily manage multiple environments in a single repository
  • 🔄 App Synthesis: Synthesize multiple cdk8s apps seamlessly
  • 👀 Visibility: Clearly understand what changed by keeping generated kube manifests in a separate directory

Basic Usage

import { App, Chart } from 'cdk8s'
import { ArgoSynth } from '@cdklib/argo-synth'

// Create an app for each environment
const stagingApp = new App()
const prodApp = new App()

// Create charts for your services
const stagingWebChart = new Chart(stagingApp, 'web')
const prodWebChart = new Chart(prodApp, 'web')

// Set paths for ArgoCD directory structure
ArgoSynth.addPath(stagingWebChart, 'staging', 'web')
ArgoSynth.addPath(prodWebChart, 'prod', 'web')

// Synthesize to output directory
await ArgoSynth.synth('gitops', [stagingApp, prodApp])

This creates a directory structure like:

gitops/
├── staging/
│   └── web/
│       └── ... (manifests)
└── prod/
    └── web/
        └── ... (manifests)

Which maps cleanly to ArgoCD applications targeting paths like:

  • staging/web
  • prod/web

Integrated Usage

A recommended approach is to create base classes that automatically handle path management:

import { App, Chart } from 'cdk8s'
import { Construct } from 'constructs'
import { CdkArgo } from '@cdklib/argo-synth'

// Create a base App class that handles environment path setup
class BaseApp extends App {
  constructor(envId: EnvId, props?: AppProps) {
    super(props)
    // The environment ID becomes the first path segment
    ArgoSynth.addPath(this, envId)
  }
}

// Create a base Chart class that automatically adds service paths
class BaseChart extends Chart {
  constructor(scope: Construct, id: string) {
    super(scope, id)
    // The chart ID becomes the service name in the path
    ArgoSynth.addPath(this, id)
  }
}

// Usage:
const stagingApp = new BaseApp('staging')
const prodApp = new BaseApp('prod')

// Service charts automatically get the correct paths
const stagingWebChart = new BaseChart(stagingApp, 'web')
const prodWebChart = new BaseChart(prodApp, 'web')

// Synthesize to output directory
await ArgoSynth.synth('gitops', [stagingApp, prodApp])

Integration with @cdklib/config

The library works seamlessly with @cdklib/config for type-safe environment management:

import { App, Chart, ApiObject } from 'cdk8s'
import { ArgoSynth } from '@cdklib/argo-synth'
import { CdkConfig, setEnvContext, EnvId } from '@cdklib/config'
import { z } from 'zod'

const webConfig = new CdkConfig(k8sSchema)
  .set('staging', {
    replicas: 2,
    namespace: 'staging',
    image: 'web-app:latest',
  })
  .set('prod', {
    replicas: 5,
    namespace: 'production',
    image: 'web-app:stable',
  })

// Create a base App class that uses environment IDs from config
class EnvApp extends App {
  constructor(
    readonly envId: EnvId,
    props?: AppProps,
  ) {
    super(props)
    // Set the environment context for @cdklib/config integration
    setEnvContext(this, envId)
    // Set the path for ArgoCD structure
    ArgoSynth.addPath(this, envId)
  }
}

// Usage
const stagingApp = new EnvApp('staging')
const prodApp = new EnvApp('prod')

// Create charts for specific services with built-in config handling
class WebChart extends Chart {
  constructor(scope: Construct) {
    super(scope, 'web')
    // Set the path for ArgoCD structure
    ArgoSynth.addPath(this, 'web')

    // Access config directly using this construct
    const { replicas, image } = webConfig.get(this)

    // Create resources using the environment-specific config
    new ApiObject(this, 'deployment', {
      apiVersion: 'apps/v1',
      kind: 'Deployment',
      metadata: { name: 'web' },
      spec: {
        replicas: replicas,
        template: {
          spec: {
            containers: [
              {
                name: 'web',
                image: image,
              },
            ],
          },
        },
        // ... other properties
      },
    })
  }
}

// Usage
const stagingApp = new EnvApp('staging')
const prodApp = new EnvApp('prod')

// Create service charts - configuration is handled internally
const stagingWebChart = new WebChart(stagingApp)
const prodWebChart = new WebChart(prodApp)

// Synthesize
await ArgoSynth.synth('gitops', [stagingApp, prodApp])

Best Practices

  1. Environment Base Classes: Create a base App class that handles environment paths:

    class EnvApp extends App {
      constructor(envId: EnvId, props?: AppProps) {
        super(props)
        // Set up both ArgoCD paths and @cdklib/config context
        setEnvContext(this, envId)
        ArgoSynth.addPath(this, envId)
      }
    }
  2. Service Base Classes: Create a base Chart class for services:

    class ServiceChart extends Chart {
      constructor(scope: Construct, id: string) {
        super(scope, id)
        ArgoSynth.addPath(this, id)
      }
    }
  3. ArgoCD Application Structure: Design your ArgoCD applications to match your path structure:

    # staging-web.yaml
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: staging-web
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: https://github.com/your-org/your-gitops-repo.git
        targetRevision: main
        path: gitops/staging/web
      destination:
        server: https://kubernetes.default.svc
        namespace: staging
  4. Integration with Config: Leverage @cdklib/config for type-safe environment configuration management:

    // In your construct code
    const { replicas, image } = webConfig.get(scope)

License

MIT