Library Architecture
Bitwarden’s core libraries are organized in thelibs/ directory and provide shared functionality that can be consumed by any client application. This architecture follows the principle of Domain-Driven Design (DDD) and separation of concerns.
Key Libraries
Common Library
Platform abstractions, models, services, and business logic shared across all applications
Angular Library
Shared Angular components, directives, pipes, and services for Angular-based clients
Auth Library
Authentication and authorization abstractions, services, and models
Vault Library
Vault-specific models, services, and cipher management functionality
Admin Console
Organization and user management features for admin functionality
Key Management
Cryptographic key management, encryption, and security services
Platform Library
Platform-specific implementations and utilities
Components Library
Shared UI component library with design system components
Nx Workspace Structure
The monorepo uses Nx to manage dependencies, builds, and tests across libraries and applications.Path Mappings
Libraries are imported using TypeScript path mappings defined intsconfig.base.json:
Library Project Configuration
Each library has aproject.json file that defines its Nx configuration:
How Applications Consume Libraries
Import Pattern
Applications import library code using the scoped package names:Dependency Injection
Services from libraries are typically registered in the application’s dependency injection container:Build Dependencies
Nx automatically tracks dependencies between libraries and applications. When a library is modified, Nx rebuilds dependent projects:Library Organization Principles
Abstraction-First Design
Libraries define abstract interfaces (abstractions) that concrete implementations follow:Domain Models
Domain models encapsulate business logic and data transformations:Platform-Specific Implementations
Applications provide platform-specific implementations of abstractions:- Browser: Uses Chrome storage API
- Desktop: Uses Electron storage
- Web: Uses browser localStorage/sessionStorage
- CLI: Uses file system storage
Shared Code Categories
Abstractions
Abstract service interfaces that define contracts for implementations
Models
Domain models, data models, view models, request/response models
Services
Concrete service implementations and business logic
Enums & Types
Shared enumerations, type definitions, and constants
Testing Utilities
The monorepo includes dedicated testing libraries:@bitwarden/core-test-utils: Core testing utilities and helpers@bitwarden/state-test-utils: State management testing utilities@bitwarden/storage-test-utils: Storage service mocks and test helpers
Next Steps
Common Library
Explore the common library structure and key abstractions
Angular Library
Learn about shared Angular components and directives