Domain
Entities, value objects, invariants and business exceptions. Pure Java, with no framework dependencies.
Hexagonal architecture isolates the domain from frameworks; one binary runs from a developer's workstation to production; and an ownership model underpins access control. The three decisions that shape the platform — and why.
The platform uses hexagonal architecture (ports and adapters). The domain knows nothing about Spring, JPA or OpenAI: it defines business rules and expected contracts, and nothing more. Infrastructure connects through explicit ports. This initial investment shapes almost everything else: testability, LLM portability, development/cloud parity and gradual evolution without a rewrite.
Entities, value objects, invariants and business exceptions. Pure Java, with no framework dependencies.
Use cases, transactions and technical ports (LLM, JWT, clock). Depends on the domain, not infrastructure.
REST, JPA, Spring AI, PostgreSQL and SSE adapters. Implements the ports and isolates frameworks.
Hexagonal architecture shapes nearly every other platform decision: LLM abstraction (a new provider requires only a new adapter), development/cloud parity (the domain depends on no AWS service), testability (use cases can be tested without Spring or a database) and gradual evolution (add an ownership type, tool or MCP server without changing the application core).
The domain ← application ← infrastructure rule is enforced rather than merely documented: ArchUnit tests fail CI if it is violated. Architecture becomes a verifiable property, not a recommendation.
The same binary runs on a development workstation and a production EC2 instance. Only the configuration file and a few environment variables change — an intentional simplification for the current target.
Development/cloud parity comes from discipline, not a tool: no AWS SDK call enters the domain. Cloud-specific concerns remain in adapters. The same code runs locally with a local database and without AWS.
Every resource — agent, conversation or RAG document — has one owner: an authenticated user or a system API key. The two workspaces are separate, and every request passes a strict ownership-equivalence check at the service boundary.
UserOwner(userId) or SystemOwner(clientId). The database uses two mutually exclusive columns, enforced by a CHECK constraint.Access to a resource you do not own returns 404 Not Found, not 403 Forbidden. This avoids disclosing identifiers owned by someone else — a defence-in-depth measure against enumeration.
An administrator can link an API key to a user. The user then gains read-only visibility into resources created by that key, without transferring ownership or sharing credentials. Write actions still require strict owner equality.