Metadata-Version: 2.4
Name: vaultkeep
Version: 0.1.0
Summary: Local-first immutable document vault engine for the Hearth ecosystem
Project-URL: Homepage, https://github.com/sarweshsoman/Vaultkeep
Project-URL: Repository, https://github.com/sarweshsoman/Vaultkeep
Project-URL: Issues, https://github.com/sarweshsoman/Vaultkeep/issues
Project-URL: Documentation, https://github.com/sarweshsoman/Vaultkeep#readme
Author-email: Sarwesh Soman <sarweshsoman@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Sarwesh Soman
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: documents,hearth,immutable,local-first,vault
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: fastapi>=0.115.0
Requires-Dist: pydantic-settings>=2.6.0
Requires-Dist: pydantic>=2.10.0
Requires-Dist: python-multipart>=0.0.17
Requires-Dist: sqlalchemy>=2.0.36
Requires-Dist: uvicorn[standard]>=0.32.0
Provides-Extra: dev
Requires-Dist: httpx>=0.28.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: ruff>=0.8.0; extra == 'dev'
Description-Content-Type: text/markdown

# Vaultkeep

Vaultkeep is a local-first immutable document vault engine for the [Hearth](https://github.com/hearth) ecosystem. It provides infrastructure for storing files, indexing metadata, verifying integrity, and versioning documents without UI, cloud storage, authentication, or business logic.

Vaultkeep integrates with **Ember** records via `linked_record_id` references. It does not depend on Ember internals.

## Philosophy

Documents are **immutable**. Vaultkeep never overwrites stored files. When content changes, a new version is created and linked to its parent. Every document carries metadata and a SHA-256 checksum. The filesystem layer is abstracted behind a pluggable backend; encryption is hook-based and optional.

Vaultkeep is infrastructure: reusable, modular, and oriented toward embedding in higher-level applications.

## Responsibilities

| Concern | Module |
|---------|--------|
| Local file storage | `storage/` |
| Metadata index (SQLite) | `metadata/` |
| SHA-256 integrity | `integrity/` |
| Immutable versioning | `versioning/` |
| Encryption hooks | `hooks/` |
| HTTP retrieval API | `api/` |

## Storage Layout

```
vault/
  documents/
    {circle_id}/
      {linked_record_id}/
        {document_id}/
          filename.ext
  metadata.db          # SQLite index (default path)
```

## Metadata Fields

Each indexed document includes:

- `document_id`, `original_filename`, `mime_type`, `file_size`
- `checksum_sha256`
- `linked_record_id`, `circle_id`
- `version`, `parent_document_id`
- `storage_path`, `created_at`

## Requirements

- Python 3.12+
- [uv](https://github.com/astral-sh/uv) (recommended)

## Installation

```bash
uv sync --all-extras
```

## Usage

### Programmatic ingestion

```python
from pathlib import Path
from vaultkeep import VaultConfig, VaultService
from vaultkeep.schemas.document import DocumentCreate

service = VaultService(VaultConfig())
result = service.ingest_file(
    Path("contract.pdf"),
    DocumentCreate(
        linked_record_id="ember-record-uuid",
        circle_id="circle-uuid",
        original_filename="contract.pdf",
    ),
)
print(result.document.document_id)
```

### HTTP API

```bash
uv run vaultkeep
# or
uv run python examples/run_api.py
```

| Method | Path | Description |
|--------|------|-------------|
| `POST` | `/api/v1/documents/upload` | Ingest file (`linked_record_id`, `circle_id` form fields) |
| `GET` | `/api/v1/documents/{document_id}` | Metadata |
| `GET` | `/api/v1/documents/{document_id}/content` | File bytes (checksum verified) |
| `GET` | `/api/v1/documents/linked/{linked_record_id}` | List by Ember record |
| `POST` | `/api/v1/documents/versions` | New immutable version |

### Configuration

Environment variables (prefix `VAULTKEEP_`):

| Variable | Default |
|----------|---------|
| `VAULTKEEP_VAULT_ROOT` | `vault` |
| `VAULTKEEP_DATABASE_URL` | `sqlite:///vault/metadata.db` |
| `VAULTKEEP_LOG_LEVEL` | `INFO` |

## Encryption Hooks

Encryption is not implemented by default. Register a custom hook:

```python
from vaultkeep.hooks.encryption import EncryptionHook, set_encryption_hook

class MyEncryption(EncryptionHook):
    def encrypt(self, source, *, document_id: str) -> bytes: ...
    def decrypt(self, data: bytes, *, document_id: str) -> bytes: ...

set_encryption_hook(MyEncryption())
```

Entry points: `encrypt_document()` and `decrypt_document()`.

## Testing

```bash
uv run pytest
```

## Project Layout

```
src/vaultkeep/
  storage/      # Filesystem backends
  metadata/     # SQLAlchemy repository
  integrity/    # Checksums, duplicates, corruption detection
  versioning/   # Version lineage
  hooks/        # Pluggable encryption
  models/       # ORM models
  schemas/      # Pydantic v2 models
  api/          # FastAPI routes
  utils/        # Logging, ID generation
tests/
examples/
docs/
vault/          # Runtime data directory
```

## Design Constraints

Vaultkeep intentionally excludes:

- User authentication and authorization
- Cloud object storage providers
- Frontend/UI components
- OCR, AI, or realtime sync
- Direct Ember package dependencies

## License

MIT
