How accordproject/apap works
APAP is an agreement server protocol and reference implementation, with a generated TypeScript client for agreement tools. The main REST workflow deploys or retrieves a template, creates and manages an agreement, then converts it to a requested format; capability discovery describes supported features. The server also exposes MCP, A2A, and Legal Context Protocol surfaces. Edges reflect README statements, excerpted wiring, or SOURCE INDEX references; unsampled route and subsystem internals are represented without speculative call chains.
Main entry points: index.ts HTTP server · agreementService.ts Agreement service · templateService.ts Template service · agreements.ts Agreement REST
Components 21
Protocol clients
- TypeScript SDK
client/typescript/apap.ts
Server interfaces
- HTTP server
server/index.ts - Template REST
server/handlers/templates.ts - Agreement REST
server/handlers/agreements.ts - Capabilities
server/handlers/capabilities.ts - MCP interface
server/handlers/mcp.ts - A2A interface
server/handlers/a2a.ts - A2A executor
server/a2a/executor.ts - LCP interface
server/handlers/lcp.ts - Error mapping
server/middleware/errorHandler.ts
Agreement domain
- Template service
server/services/templateService.ts - Agreement service
server/services/agreementService.ts - Template processing
server/handlers/templatebuilder.ts - Legal context
server/services/lcpService.ts
Identity and policy
- Auth adapters
server/auth/registry.ts - Authorization policy
server/services/policy.ts
Persistence and retrieval
- PostgreSQL
server/db/schema.ts - Template retriever
server/handlers/retrievers/HttpTemplateRetriever.ts - Model retriever
server/handlers/retrievers/HttpModelRetriever.ts - URL allowlist
server/handlers/retrievers/allowlist.ts
Other components
- Agreement tool
Connections 30
- Agreement tool → TypeScript SDK: uses
README.md - TypeScript SDK → HTTP server: calls REST
README.md - Agreement tool → HTTP server: communicates REST
README.md - HTTP server → Template REST: mounts
server/index.ts - HTTP server → Agreement REST: mounts
server/index.ts - HTTP server → Capabilities: mounts
server/index.ts - HTTP server → MCP interface: mounts
server/index.ts - HTTP server → LCP interface: mounts
server/index.ts - HTTP server → A2A interface: mounts
server/index.ts - HTTP server → Error mapping: registers
server/index.ts - Template REST → Template service: delegates
- Agreement REST → Agreement service: delegates
server/handlers/agreements.ts - Agreement REST → Template processing: uses
server/handlers/agreements.ts - Agreement service → Template processing: builds template
server/services/agreementService.ts - Agreement service → PostgreSQL: reads and writes
server/services/agreementService.ts - Template service → PostgreSQL: reads and writes
server/services/templateService.ts - Template service → Template processing: extracts archives
server/services/templateService.ts - Template retriever → URL allowlist: checks URLs
server/handlers/retrievers/HttpTemplateRetriever.ts - Model retriever → URL allowlist: checks URLs
server/handlers/retrievers/HttpModelRetriever.ts - MCP interface → Template service: invokes
server/handlers/mcp.ts - MCP interface → Agreement service: invokes
server/handlers/mcp.ts - A2A interface → A2A executor: dispatches
server/handlers/a2a.ts - A2A executor → Template service: invokes
server/a2a/executor.ts - A2A executor → Agreement service: invokes
server/a2a/executor.ts - LCP interface → Legal context: delegates
server/handlers/lcp.ts - Legal context → Agreement service: converts agreement
server/services/lcpService.ts - Auth adapters → Authorization policy: supplies identity
- Template service → Authorization policy: authorizes
server/services/templateService.ts - Agreement service → Authorization policy: authorizes
server/services/agreementService.ts - Error mapping → PostgreSQL: maps DB conflicts
server/middleware/errorHandler.ts