Agreement and consent tracking for terms of service, privacy policies, and GDPR compliance
| Tier | domain |
| Role | unclassified (baselined) |
| Path | crates/domain/agreements |
| Edition | 2021 |
| Targets | domain_agreements, pg_agreements |
| Public items | 0 across 0 modules |
| Tests | 49 |
What it is for
# domain-agreements
Agreement and consent tracking library crates for terms of service, privacy policies, and GDPR compliance.
Layer split (sprint-3.53)
Per docs/architecture/PRIMITIVES_CRATE_TEMPLATE.md's required layer split: models.rs (domain types + Create*Request/Update*Request DTOs), repository.rs (sqlx-backed CRUD + typed helper-function wrappers), service.rs (publish/supersede/withdraw orchestration), events.rs (domain events), errors.rs (AgreementError). OQ3 (docs/userstories/sprint-3.53-forge-agreements.md) resolved that this domain crate — not the application-agreements wrapper — owns persistence.
Core Concepts
- Agreement: Named agreement type (terms, privacy policy)
- `AgreementVersion`: Versioned content with effective dates
- Consent: User acceptance records with audit trail
Example
use domain_agreements::{Agreement, AgreementType, AgreementVersion, Consent, ConsentMethod};
use chrono::Utc;
use uuid::Uuid;
// Create an agreement
let tos = Agreement::new("terms-of-service", "Terms of Service", AgreementType::TermsOfService)
.with_description("Legal terms governing use of our service")
.required();
// Create a version
let version = AgreementVersion::new(tos.id, "1.0", "Full terms text...")
.with_summary("Initial version")
.publish();
// Record user consent
let consent = Consent::new(Uuid::new_v4(), version.id)
.with_method(ConsentMethod::Checkbox)
.with_ip("192.168.1.1");
Capabilities
No public items.
How to use it
From this crate's own rustdoc:
use domain_agreements::{Agreement, AgreementType, AgreementVersion, Consent, ConsentMethod};
use chrono::Utc;
use uuid::Uuid;
// Create an agreement
let tos = Agreement::new("terms-of-service", "Terms of Service", AgreementType::TermsOfService)
.with_description("Legal terms governing use of our service")
.required();
// Create a version
let version = AgreementVersion::new(tos.id, "1.0", "Full terms text...")
.with_summary("Initial version")
.publish();
// Record user consent
let consent = Consent::new(Uuid::new_v4(), version.id)
.with_method(ConsentMethod::Checkbox)
.with_ip("192.168.1.1");
Module structure
No public modules: the crate root is its whole surface.
Public surface
No public items.
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
AgreementError | errors::AgreementError |
AgreementService | service::AgreementService |
{Agreement,AgreementType,AgreementVersion,Consent,ConsentMethod,CreateAgreementRequest,CreateAgreementVersionRequest,CreateConsentRequest,UpdateAgreementRequest,VersionStatus,MAX_CONTENT_LEN,MAX_SUMMARY_LEN,MAX_USER_AGENT_LEN,} | models::{Agreement,AgreementType,AgreementVersion,Consent,ConsentMethod,CreateAgreementRequest,CreateAgreementVersionRequest,CreateConsentRequest,UpdateAgreementRequest,VersionStatus,MAX_CONTENT_LEN,MAX_SUMMARY_LEN,MAX_USER_AGENT_LEN,} |
{AgreementCreated,AgreementVersionPublished,ConsentRecorded,ConsentWithdrawn} | events::{AgreementCreated,AgreementVersionPublished,ConsentRecorded,ConsentWithdrawn} |
{AgreementRepository,CurrentVersion,PendingAgreement} | repository::{AgreementRepository,CurrentVersion,PendingAgreement} |
{HasId,SoftDeletable,Timestamped} | foundation_basemodels::{HasId,SoftDeletable,Timestamped} |
Boundary
Reaches into foundation.
Shares tier domain with 41 other crates: domain-ai-report, domain-billing, domain-catalog, domain-classify, domain-comments, domain-competitive-intel, domain-contact, domain-conversation-engine, … (41 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | domain |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/domain/agreements |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_domain["domain"] --> n_foundation["foundation"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | no | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
tracing | ^0.1 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_agreements["application-agreements"] -->|uses| SELF SELF["domain-agreements"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | domain_agreements | `src/lib.rs` |
| test | pg_agreements | `tests/pg_agreements.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | yes |
| database access | yes |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-agreements.
Verification
| Kind | Count |
|---|---|
| Unit tests | 37 |
| Integration tests | 12 |
| Examples | 0 |
| Doctests | 1 |
What the tests establish, by name:
a_published_version_with_a_future_effective_date_is_not_yet_consentable—tests/pg_agreements.rsconcurrent_publish_of_two_drafts_leaves_exactly_one_published—tests/pg_agreements.rsmigration_creates_the_three_tables_and_helper_functions—tests/pg_agreements.rspending_required_ignores_agreements_that_are_not_required—tests/pg_agreements.rspending_required_lists_an_unconsented_required_agreement—tests/pg_agreements.rspublish_stamps_published_at_and_flips_status—tests/pg_agreements.rspublishing_a_non_draft_version_is_rejected—tests/pg_agreements.rspublishing_v2_atomically_supersedes_v1—tests/pg_agreements.rsrecording_consent_against_a_draft_version_is_rejected—tests/pg_agreements.rsrecording_consent_against_a_published_version_persists_the_audit_fields—tests/pg_agreements.rswithdraw_by_a_non_owner_is_rejected—tests/pg_agreements.rswithdraw_by_the_owner_stamps_withdrawn_at_and_has_current_consent_flips_false—tests/pg_agreements.rstest_agreement_deactivate—src/models.rstest_agreement_has_id_trait—src/models.rstest_agreement_required—src/models.rstest_agreement_slug_normalization—src/models.rstest_agreement_soft_delete—src/models.rstest_agreement_type_as_str—src/models.rstest_agreement_type_parse—src/models.rstest_agreement_type_requires_explicit_consent—src/models.rstest_agreement_with_description—src/models.rstest_consent_is_explicit—src/models.rstest_consent_is_for_version—src/models.rstest_consent_method_as_str—src/models.rstest_consent_method_is_explicit—src/models.rstest_consent_method_parse—src/models.rstest_consent_with_ip_and_user_agent—src/models.rstest_consent_with_method—src/models.rstest_consent_withdraw—src/models.rstest_consent_withdrawal_flow—src/models.rs- _… 19 more_
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 0 | 0 |
Public modules with a //! block | 0 | 0 |
Metrics
| Metric | Value |
|---|---|
| Rust source files | 6 |
| Source lines | 2048 |
| Code lines | 1421 |
| Public API items | 0 |
| Public modules | 0 |
| Tests | 49 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 9 |
| Workspace reverse dependencies | 1 |
pie showData
title Rust source composition
"Code" : 1421
"Blank or comment" : 627
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.