Skip to content

Integration Project Structure

Separate repository (marchay-integration) for all Integration Architecture services. This document defines the repo layout, tech stack, and conventions.


Repository Layout

marchay-integration/
├── gateway/                      # Main API Gateway service — Fastify
│   ├── src/
│   │   ├── app.ts                # Fastify app factory, plugins, lifecycle
│   │   ├── config.ts             # Settings via @fastify/env or envalid
│   │   ├── server.ts             # Server entry point
│   │   ├── plugins/
│   │   │   ├── auth.ts           # Authentication plugin (inbound + outbound)
│   │   │   ├── rate-limit.ts     # Rate limiting plugin
│   │   │   ├── circuit-breaker.ts
│   │   │   ├── error-handling.ts
│   │   │   ├── logging.ts        # Structured JSON logging
│   │   │   ├── tracing.ts        # OpenTelemetry tracing
│   │   │   └── cors.ts
│   │   ├── connectors/
│   │   │   ├── index.ts          # Connector registry
│   │   │   ├── types.ts          # Connector interface contract
│   │   │   ├── salesforce/
│   │   │   │   ├── index.ts
│   │   │   │   ├── auth.ts       # OAuth 2.0 JWT Bearer
│   │   │   │   ├── mapper.ts     # API translation
│   │   │   │   └── errors.ts     # Error mapping
│   │   │   ├── atlantes/
│   │   │   └── partner/          # Partner API connectors (stubs)
│   │   ├── routes/
│   │   │   ├── index.ts          # Route registration
│   │   │   ├── health.ts         # /healthz, /statusz
│   │   │   ├── members.ts        # /v1/members
│   │   │   ├── quotes.ts         # /v1/quotes
│   │   │   ├── bookings.ts       # /v1/bookings
│   │   │   └── webhooks/
│   │   │       ├── salesforce.ts # POST /v1/webhooks/salesforce/*
│   │   │       └── outbound.ts   # Outbound webhook delivery
│   │   ├── pipeline/
│   │   │   ├── index.ts          # Request pipeline orchestrator
│   │   │   ├── types.ts          # Pipeline step interface
│   │   │   └── steps/            # Individual pipeline steps
│   │   ├── webhooks/
│   │   │   ├── inbound.ts        # Webhook termination, verification
│   │   │   ├── outbound.ts       # Subscription model, delivery
│   │   │   └── dedup.ts          # Event deduplication
│   │   ├── errors/
│   │   │   ├── index.ts          # Error categories and types
│   │   │   ├── response.ts       # Uniform error response shape
│   │   │   └── circuit.ts        # Circuit breaker state machine
│   │   └── metrics/
│   │       ├── index.ts
│   │       └── gateway-metrics.ts
│   ├── tests/
│   │   ├── helpers/
│   │   │   └── fixtures.ts
│   │   ├── plugins/
│   │   ├── routes/
│   │   ├── connectors/
│   │   └── integration/
│   ├── migrations/
│   ├── package.json
│   ├── tsconfig.json
│   ├── Dockerfile
│   └── README.md

├── shared/                      # Common types and utilities
│   ├── src/
│   │   ├── types/
│   │   │   ├── consumer.ts      # Consumer, Credential types
│   │   │   ├── member.ts        # Member, Trip types
│   │   │   ├── quote.ts         # Quote types
│   │   │   └── booking.ts       # Booking types
│   │   ├── schemas/
│   │   │   ├── request.ts       # Request validation schemas (Zod)
│   │   │   └── response.ts      # Response schemas
│   │   └── utils/
│   │       ├── idempotency.ts
│   │       └── cursor.ts        # Cursor pagination utilities
│   ├── package.json
│   └── tsconfig.json

├── docker-compose.yml           # Local dev: Redis, Postgres
├── Makefile                     # Common commands
├── .gitlab-ci.yml               # CI/CD pipeline
└── README.md

Tech Stack

ComponentChoiceRationale
LanguageTypeScript 5.4+Type safety, IDE support, ecosystem
FrameworkFastify 5High performance, plugin architecture, schema-based validation
ValidationJSON Schema (Fastify built-in)Native integration, reject unknown fields
Auth@fastify/jwt, @fastify/corsProven Fastify ecosystem
Rate Limiting@fastify/rate-limitNative Fastify plugin
Tracing@fastify/helmet, OpenTelemetryIndustry standard
Loggingpino (Fastify default)Structured JSON, high performance
QueueRedis (Valkey fork)Already provisioned, LPUSH/BRPOP
TestingVitestFast, native TypeScript support
LintingBiomeFast, comprehensive
Type CheckingTypeScript (strict)Catch errors early
BuildtsupFast TypeScript bundler

Naming Conventions

  • TypeScript: camelCase for functions, variables. PascalCase for classes, interfaces, types.
  • Files: camelCase.ts for source, kebab-case.test.ts for tests
  • Routes: /v1/{resource} (REST), /v1/webhooks/{vendor}/{event} (webhooks)
  • Redis keys: session:{id}, dedup:{event_id}, circuit:{resource}
  • Metrics: gateway_calls_total, gateway_errors_total, gateway_latency_p95
  • Git branches: feat/gateway-foundation, fix/auth-timeout, chore/update-deps

Repo Relationship

This repo (marchay-integration) is separate from the architecture docs repo (marchay-docs) and the agent repo (marchay-agent).

RepoPurposeContents
marchay-docsArchitecture planningDesign docs, build briefs, roadmaps
marchay-agentAgent servicesOrchestrator, research agents
marchay-integrationIntegration servicesAPI Gateway, connectors, webhooks

The build brief in marchay-docs serves as the spec. Implementation lives in marchay-integration.


Makefile

makefile
.PHONY: dev test lint typecheck build

dev:
	docker compose up -d
	cd gateway && pnpm dev

test:
	cd gateway && pnpm test

lint:
	pnpm biome check gateway/ shared/

typecheck:
	cd gateway && pnpm typecheck

build:
	cd gateway && pnpm build

docker:
	docker compose build

prod:
	docker compose -f docker-compose.prod.yml up -d

Marchay Platform Documentation