@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:- 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
Log Service
Log Service
Provides logging functionality with different log levels (debug, info, warning, error).
Environment Service
Environment Service
Manages environment-specific URLs and configuration for different deployment environments.
State Service
State Service
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 theDomain base class which provides encryption/decryption utilities:
Service Structure
Services in the common library follow a consistent pattern:Service Organization
Example: Cipher Service
Abstraction: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 foldersCollectionService- Organization collectionsSearchService- 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
Related Libraries
State Library
@bitwarden/state - Advanced state management with RxJS observablesStorage Core
@bitwarden/storage-core - Core storage abstractions and implementationsKey Management
@bitwarden/key-management - Cryptographic key operationsPlatform Library
@bitwarden/platform - Platform-specific implementations