Share code between projects

You will create a shared library, export a service from it, and use it from an app via dependency injection.

Steps

1) Create a shared package

putnami projects create @workspace/shared --template typescript-library

This scaffolds a TypeScript library at packages/workspace/shared/ with exports and a test suite.

2) Export a shared service

Replace packages/workspace/shared/src/index.ts:

export class GreetingService {
  message() {
    return 'Hello from shared code';
  }
}

No decorators or runtime imports needed — services are plain classes.

3) Use it in an app

Add the shared package as a dependency of your app, named by its project name:

putnami deps add @workspace/shared --projects <app>

For a TypeScript project this writes "@workspace/shared": "workspace:*" in the app's package.json (with npm or Yarn 1, a version range) and installs.

Register the service in your application entry point (src/main.ts):

import { application, api, http } from '@putnami/application';
import { GreetingService } from '@workspace/shared';

export const app = () =>
  application()
    .use(http())
    .provide(GreetingService)
    .use(api());

Then inject it in a route, for example src/api/hello/get.ts:

import { endpoint } from '@putnami/application';
import { GreetingService } from '@workspace/shared';

export const GET = endpoint()
  .inject({ greeting: GreetingService })
  .handle((ctx) => ({ message: ctx.deps.greeting.message() }));

Go workspace modules

For a Go consumer, use the module path declared by the shared library:

putnami deps add example.com/shared --projects api

A bare module path that uniquely matches a member of the consumer's go.work is resolved from that tree, including an unpublished library. The command adds a requirement and a relative local replacement while preserving an existing replacement. A spec with an explicit version, such as example.com/shared@v1.2.3, uses the published-version lookup.

Result

You now have shared code used by more than one project. The library is built, tested, and linked through workspace dependencies.

Companion sample: typescript/samples/05-dependency-injection — a runnable project with explicit provider registration, endpoint().inject(), and scoped services. Run putnami serve @example/dependency-injection from the workspace root.