Skip to content

GOOD-Code-ApS/goodie

Repository files navigation

goodie

License: MIT

Alpha software. APIs may change between minor versions until 1.0. Pin your versions and check the changelog before upgrading.

Compile-time dependency injection for TypeScript. No reflect-metadata, no runtime scanning — just decorators and code generation.

How It Works

Decorators (your code) → Transformer (compile-time) → Generated code → Runtime (ApplicationContext)
  1. You annotate classes with Stage 3 decorators (@Singleton, @Injectable, @Inject, etc.)
  2. At build time, a ts-morph transformer scans your code and generates a typed wiring file
  3. At runtime, ApplicationContext resolves the dependency graph from the generated definitions

The result: full DI with zero runtime reflection, type-safe tokens, and instant startup.

Requirements

  • Node.js >= 22
  • TypeScript >= 5.7
  • pnpm >= 10 (for workspace consumers)

Quick Start

Install

pnpm add @goodie-ts/core @goodie-ts/decorators
pnpm add -D @goodie-ts/transformer @goodie-ts/vite-plugin

Decorate

import { Singleton, Inject } from '@goodie-ts/decorators';

@Singleton()
class UserRepository {
  findAll() { return [{ id: '1', name: 'Alice' }]; }
}

@Singleton()
class UserService {
  @Inject() accessor userRepo!: UserRepository;

  getUsers() { return this.userRepo.findAll(); }
}

Configure Vite

// vite.config.ts
import { defineConfig } from 'vite';
import { diPlugin } from '@goodie-ts/vite-plugin';

export default defineConfig({
  plugins: [diPlugin()],
});

Use

import { Goodie } from '@goodie-ts/core';
import { definitions } from './AppContext.generated.js';

const app = await Goodie.build(definitions).start();
const userService = app.context.get(UserService);

Packages

Core

Package Description
@goodie-ts/core Runtime container, ApplicationContext, InjectionToken, topological sort
@goodie-ts/decorators @Singleton, @Injectable, @Inject, @Value, @Module, @Provides, and more
@goodie-ts/transformer ts-morph scanner and code generator (build-time only)
@goodie-ts/cli CLI tool — goodie generate with watch mode
@goodie-ts/vite-plugin Vite integration — runs transformer on build and HMR
@goodie-ts/testing TestContext with bean overrides and @MockDefinition

Framework

Package Description
@goodie-ts/aop AOP foundation — createAopDecorator, @Before, @Around, @After, interceptor chain
@goodie-ts/cache In-memory caching — @Cacheable, @CacheEvict, @CachePut
@goodie-ts/config Configuration binding — @ConfigurationProperties
@goodie-ts/hono HTTP routing — @Controller, @Get, @Post, @Put, @Delete, @Patch
@goodie-ts/kysely Kysely integration — @Transactional, @Migration, CrudRepository
@goodie-ts/logging Method logging — @Log, LoggerFactory, MDC
@goodie-ts/health Health checks — HealthIndicator, HealthAggregator, UptimeHealthIndicator
@goodie-ts/resilience Resilience patterns — @Retryable, @CircuitBreaker, @Timeout

Development

pnpm build          # Build all packages
pnpm test           # Run all tests (vitest)
pnpm test:watch     # Watch mode
pnpm lint           # Check with Biome
pnpm lint:fix       # Auto-fix lint issues
pnpm clean          # Clean all dist/

License

MIT

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors