logoAffluent docs

Packages

Shared packages and utilities in the Affluent monorepo

Packages

The Affluent monorepo includes several shared packages that provide reusable functionality across applications and services. These packages are designed to promote code reuse, maintain consistency, and enable independent development workflows.

Package overview

Architecture

Shared typeScript packages

The main application uses several TypeScript packages that provide:

  • UI Components (@affluent/ui): Radix UI primitives with TailwindCSS design system
  • Financial Calculators (@affluent/calculators): Reusable financial calculation tools shared between app and website
  • Utility Library (@affluent/lib): Common utilities for date, currency, and number formatting

Independent packages

Some packages are designed to operate independently from the main application:

  • Financial Data Service: FastAPI service for fetching financial market data via REST API

Package management

All packages are managed through the Turborepo monorepo structure:

# Install dependencies for all packages
pnpm install

# Build all packages
turbo build

# Build specific package
turbo build --filter=@affluent/ui

Development workflow

TypeScript packages

TypeScript packages follow the standard monorepo workflow:

  1. Develop packages in isolation
  2. Use workspace dependencies (workspace:*) for internal packages
  3. Build and test through Turborepo pipeline
  4. Import packages using @affluent/package-name

Independent packages

Independent packages like the Financial Data Service have their own development workflow:

  1. Separate dependency management (Python virtual environments)
  2. REST API integration with HTTP endpoints
  3. Integration through npm scripts in the root package.json
  4. Independent versioning and deployment

Integration

Monorepo integration

Packages are integrated into the monorepo through:

  • Turborepo Configuration: Defined in turbo.json for TypeScript packages
  • Package Scripts: Convenient npm scripts in root package.json for all packages
  • Shared Configuration: ESLint, TypeScript, and Biome configurations

Cross-package Dependencies

  • TypeScript packages can depend on each other using workspace references
  • Independent packages interact through database and external APIs
  • Shared environment variables and configuration through the monorepo structure

Best Practices

Package development

  • Single Responsibility: Each package should have a clear, focused purpose
  • Minimal Dependencies: Keep external dependencies to a minimum
  • TypeScript First: Use strict TypeScript for type safety (TypeScript packages)
  • Documentation: Comprehensive documentation for all public APIs
  • Testing: Unit tests and integration tests where appropriate

Monorepo considerations

  • Build Order: Ensure packages build in the correct dependency order
  • Version Management: Coordinate versions between dependent packages
  • Breaking Changes: Consider impact on consuming packages and applications
  • Performance: Optimize build times through efficient dependency graphs

Contributing

When adding new packages:

  1. Follow the established directory structure
  2. Add appropriate build and test scripts
  3. Update Turborepo configuration if needed
  4. Document the package purpose and API
  5. Consider integration points with existing packages

For package-specific contribution guidelines, see the individual package documentation.