Standards & Reference

Architecture

Status: [ ] Not Started | [ ] In Progress | [ ] Complete | [ ] Approved

This document defines the technical architecture, technology stack, and engineering decisions. Complete this document during the Global Setup phase before creating any feature specifications.


Architecture Overview

System Architecture

[TODO: Add architecture diagram or description]

Example:
┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Client    │────▶│     API     │────▶│  Database   │
│    (Web)    │     │   Server    │     │             │
└─────────────┘     └─────────────┘     └─────────────┘

Architecture Patterns

PatternUsageRationale
[TODO][TODO][TODO]
[TODO][TODO][TODO]

Technology Stack

Frontend

LayerTechnologyVersionPurpose
Framework[TODO][TODO][TODO]
UI Library[TODO][TODO][TODO]
State Management[TODO][TODO][TODO]
Styling[TODO][TODO][TODO]

Backend

LayerTechnologyVersionPurpose
Runtime[TODO][TODO][TODO]
Framework[TODO][TODO][TODO]
ORM/Database[TODO][TODO][TODO]
Authentication[TODO][TODO][TODO]

Infrastructure

ComponentTechnologyPurpose
Hosting[TODO][TODO]
Database[TODO][TODO]
Cache[TODO][TODO]
CDN[TODO][TODO]

Data Architecture

Data Models

[TODO: Define core data models]

Example:
User ──┬── owns ──▶ Workspace
       └── creates ──▶ Task ──▶ belongs to ──▶ Project

Database Strategy

AspectDecisionRationale
Primary Database[TODO][TODO]
Caching Strategy[TODO][TODO]
Data Sync[TODO][TODO]

API Design

API Style

[TODO: Define API style and conventions]

Authentication & Authorization

AspectApproachDetails
Authentication[TODO][TODO]
Authorization[TODO][TODO]
Token Management[TODO][TODO]

API Versioning

[TODO: Define API versioning strategy]

Security Considerations

Security Requirements

RequirementImplementationStatus
Data Encryption[TODO][ ]
Input Validation[TODO][ ]
OWASP Top 10[TODO][ ]
Authentication[TODO][ ]

Security Boundaries

[TODO: Define security boundaries]

Performance Requirements

Performance Targets

MetricTargetMeasurement
Page Load Time[TODO][TODO]
API Response Time[TODO][TODO]
Concurrent Users[TODO][TODO]
Availability[TODO][TODO]

Scalability Strategy

[TODO: Define scalability approach]

Integration Points

External Services

ServicePurposeIntegration Method
[TODO][TODO][TODO]
[TODO][TODO][TODO]

Internal APIs

APIPurposeConsumers
[TODO][TODO][TODO]
[TODO][TODO][TODO]

Development Environment

Required Tools

  • [ ] [TODO]
  • [ ] [TODO]
  • [ ] [TODO]

Environment Setup

# [TODO: Add setup commands]

Technical Decisions Log

DecisionDateRationaleAlternatives Considered
[TODO][TODO][TODO][TODO]
[TODO][TODO][TODO][TODO]

Approval

RoleNameDateSignature
Technical Lead
Architect
Security

Learnings & Patterns

This section captures architectural decisions and learnings from development sessions.

RxDB Schema & Migrations

PatternDetailsDate Added
Schema versioningWhen bumping RxDB schema versions, the migration plugin must be enabled (migration: true in plugins config)2026-01-30
domainId handlingdomainId is a server-only field injected by rxdb-server - do NOT add to client-side schemas. The forked rxdb-server uses serverOnlyFields: ['domainId'] to strip it from HTTP responses.2026-01-30
WebSocket replicationWebSocket replication doesn't support serverOnlyFields - clients will receive domainId via WS but should ignore it2026-01-30
Schema rebuild processAfter schema changes, use ./scripts/local-env.sh rebuild to rebuild and restart containers with new schema2026-01-30

Kong Gateway & Authentication

PatternDetailsDate Added
JWT iss claim requiredJWT tokens MUST include iss claim - Kong uses key_claim_name: iss to look up the consumer2026-01-30
Lua sandbox limitationsKong's post-function Lua sandbox blocks require('cjson.safe') - use pattern matching instead for JSON parsing2026-01-30
Multi-tenant isolationKong extracts domainId from JWT and sets x-domain-id header for downstream services to enforce tenant isolation2026-01-30
Container port exposureServices behind Kong gateway should NOT expose ports directly - all access should go through Kong2026-01-30

Ollama & Embedding Services

PatternDetailsDate Added
Batch concurrencyBatch embedding requests can overwhelm Ollama - implement concurrency limiting with a queue (e.g., max 3 concurrent)2026-01-30
Extended timeoutsDefault 30s timeout insufficient for embeddings - use minimum 120s via AbortSignal.timeout(120000)2026-01-30
Custom fetchEmbedding service should use custom fetch wrapper with configurable timeout and retry logic2026-01-30

SurrealDB

PatternDetailsDate Added
UPSERT syntaxSurrealDB 2.x UPSERT syntax is UPSERT INTO table:$id CONTENT {...} NOT UPSERT table:$id CONTENT {...}2026-01-30

Docker & Container Management

PatternDetailsDate Added
Use local-env.shAlways use ./scripts/local-env.sh for container management - it handles 1Password secret loading2026-01-30
Git clone buildsDocker images built from git clone won't have uncommitted changes - push changes before building2026-01-30
Base image patternCreate a slim base image (Dockerfile.base) that pre-builds core library packages using nx run-many --parallel=3. Service Dockerfiles extend from this base.2026-01-30
Nx parallel buildsUse --parallel=3 with nx run-many to limit concurrent builds and avoid memory issues while still parallelizing2026-01-30
Slim service imagesService Dockerfiles that extend from base only need to run yarn nx build @epicdm/<service> - deps are pre-built2026-01-30

Caddy Reverse Proxy

PatternDetailsDate Added
Caddyfile global blockGlobal settings like email must be in a global block: { email foo@example.com } at top of file2026-01-30
DNS before TLSDNS must be configured and propagated BEFORE Caddy can obtain Let's Encrypt certificates2026-01-30
Proxy mode off for certsWhen using Cloudflare DNS with Caddy for TLS, keep proxy mode OFF (gray cloud) so Caddy can complete ACME challenges2026-01-30
Shortlived certs avoidedDo not use profile shortlived in ACME config - use default cert settings for production2026-01-30

Cloudflare Deployment

PatternDetailsDate Added
Environment flagDeployment requires explicit --env production flag for production environment2026-01-30
Worker environmentsWorkers have separate staging and production environments - always verify deployment target2026-01-30
Custom domain routingCustom domains may route to different workers than expected - verify routing in Cloudflare dashboard2026-01-30

RAG Sync & Content Deduplication

PatternDetailsDate Added
Document ID consistencyUse document.id (internal RxDB id) for hash lookups, not event.documentId (external id). These can differ and cause deduplication failures.2026-01-30
Volatile fields exclusionExclude volatile fields from content hash: updatedAt, createdAt, _rev, _meta, _deleted, _attachments, syncedAt, lastModified. Otherwise documents re-sync infinitely.2026-01-30
Deterministic hashingSort object keys before hashing to ensure consistent results across runs: JSON.stringify(obj, Object.keys(obj).sort())2026-01-30

Last Updated: 2026-01-30 Document Owner: [Name]

Previous
Overview