Architecture¶
Layering¶
The package is organized in layers from lowest-level mechanics to highest-level consumer API.
- encoding and crypto primitives
- transport and CRUD adapter abstractions
- repository behavior for encrypted entity persistence
- schema and model builders
- top-level client factory and app-facing service composition
That dependency direction matters. Higher-level layers should compose lower-level layers rather than leaking implementation details back down.
Source Layout¶
The source tree is organized by responsibility:
src/adapters: GraphQL and REST transport plus CRUD adapter abstractionssrc/auth: password-based client auth helperssrc/cache: LokiJS cache implementationsrc/client-factory.ts: one-shot client assembly from amodelsobjectsrc/compat: compatibility helpers for legacy encrypted blobssrc/crypto: encryption strategies, key derivation, and crypto typessrc/encoding: byte and base64 helperssrc/external-e2ee: generic interfaces for external encrypted API clientssrc/repositories: the encrypted entity repository layersrc/schema-builder.ts: Prisma-like model definitions compiled into repository schemassrc/schemas: reusable entity schemas
Preferred Public API¶
The intended public stack is:
defineEntityModel(...)defineClientModel(...)createEntityClient(...)
That stack generates:
createEntityandcreateRemotemappings- encrypted field policies for the repository
- runtime validation for entity input and remote payloads
- repository or service instances for each model from a single
modelsobject
Direct EntitySchema and EntityRepository usage still exists, but should be treated as advanced functionality rather than the primary consumer story.