Skip to main content
The @bitwarden/common library is the foundation of the Bitwarden Clients codebase, providing platform-agnostic abstractions, models, and services that are shared across all client applications.

Library Structure

The common library is organized into feature domains and core platform functionality:

Core Components

Platform Abstractions

Abstract service interfaces for storage, crypto, logging, and more

Domain Models

Encrypted domain objects and decryptable view models

Service Layer

Business logic implementations and API integrations

Type System

Shared types, enums, and interfaces

Platform Abstractions

The platform layer provides core abstractions that applications must implement for their specific runtime environment.

Key Abstractions

Storage Service

Provides an abstraction for key-value storage:
Platform Implementations:
  • Browser: Chrome storage API
  • Desktop: Electron secure storage
  • Web: localStorage/sessionStorage
  • CLI: File system JSON storage

Platform Utils Service

Provides platform-specific utilities and device information:

I18n Service

Handles internationalization and localization:

Messaging Service

Enables cross-component and cross-context communication:

Other Platform Services

Provides logging functionality with different log levels (debug, info, warning, error).
Manages environment-specific URLs and configuration for different deployment environments.
Provides state management and persistence across the application.

Models Architecture

The common library uses a three-layer model architecture:

1. Data Models

Represent raw data from API or storage:

2. Domain Models

Encapsulate business logic and handle encryption:

3. View Models

Decrypted, user-facing models for UI rendering:

Domain Base Class

All domain models extend the Domain base class which provides encryption/decryption utilities:

Service Structure

Services in the common library follow a consistent pattern:

Service Organization

Example: Cipher Service

Abstraction:
Implementation:

Feature Domains

Authentication

Location: libs/common/src/auth/

Vault Management

Location: libs/common/src/vault/ Key abstractions:
  • CipherService - Manage vault items (ciphers)
  • FolderService - Organize ciphers into folders
  • CollectionService - Organization collections
  • SearchService - Search and filter vault items

Key Management

Location: libs/common/src/key-management/ Handles cryptographic operations:
  • Key derivation and generation
  • Encryption and decryption
  • Key rotation and management

Admin Console

Location: libs/common/src/admin-console/ Organization and user management:
  • Organization services
  • User invitation and management
  • Policy enforcement

Enums and Types

Common Enums

Import Examples

State Library

@bitwarden/state - Advanced state management with RxJS observables

Storage Core

@bitwarden/storage-core - Core storage abstractions and implementations

Key Management

@bitwarden/key-management - Cryptographic key operations

Platform Library

@bitwarden/platform - Platform-specific implementations