reybenbaq / code-samples

Rey Benjamin Baquirin
AI Systems Architect

Production code samples. Each repo shows how a real problem was approached, how it broke, and what fixed it. Stack, architecture, and the decisions worth calling out.

Browse samples ↓

5 samples

Open source. Read the code.

reybenbaq/projects-cockpit-mcp
projects-cockpit-mcp GitHub repository overview

Projects Cockpit MCP

A read-only MCP server that gives an AI host live, structured awareness of a multi-project workspace: projects, agents, plans, git state, and memory search.

Python · FastMCP · MCP SDK 1.25 · Docker · GitHub Actions · pytest

Before

An AI host working across dozens of projects and agents had no structured way to query 'which plans are in flight' or 'which repos are dirty' without a manual grep. The ASGI bearer middleware also needed to avoid Starlette's BaseHTTPMiddleware, which breaks streamed responses and swallows lifespan events.

After

103 tests at 87.44% branch coverage. The server completes an end-to-end MCP handshake against a live ClientSession and calls all five tools. CI enforces an 85% branch-coverage gate and a Trivy image scan on every push.

View source on GitHub
reybenbaq/lead-enrichment-pipeline
lead-enrichment-pipeline GitHub repository overview

Lead Enrichment Pipeline

A continuously-looping lead enrichment pipeline: skip-trace waterfall, LLM personalization, multi-signal scoring, and a human-review gate.

Python · gpt-4o-mini · OpenAI API · pytest

Before

Records stalled silently in the queue after a failed waterfall lookup. The cooldown timestamp cleared but the stage never reset, so the pickup filter never found them again. Ghost slots held a slot forever while throughput collapsed.

After

A re-admit sweep runs at the top of every driver cycle before pickup. It clears the timestamp and resets the stage in one pass. Ghost slots vanish on the next cycle. The fix is cheap, unconditional, and idempotent.

View source on GitHub
reybenbaq/multitenant-agent-arch

Demo: the campaign-manager application this architecture runs in production. The public repo is the same architecture, sanitized and written for a different use case.

Multi-Tenant Agent API

A FastAPI backend running a per-tenant AI agent with streaming output over WebSocket. Four non-obvious problems, solved correctly.

Python · FastAPI · Anthropic SDK · SQLAlchemy · JWT · WebSocket

Before

Starlette's BaseHTTPMiddleware runs on HTTP scopes only. A WebSocket upgrade arrives as scope type 'websocket' and middleware never fires. Junior implementations leave every WebSocket endpoint publicly accessible. A second race condition: the background agent loop can finish before the WebSocket client connects, leaving a queue entry that a naive pop would destroy.

After

Two separate auth paths share one decoder. The background task only writes to the queue; the WebSocket handler owns the pop in its finally block. The iterative tool-use loop caps at MAX_TURNS and persists every turn to the database.

View source on GitHub
reybenbaq/vendor-sync-engine

Demo: refactoring the production sync system this pattern came from, with Claude Code. This repo is the standalone hybrid polling and webhook layer, extracted and sanitized.

Vendor Sync Engine

Hybrid polling and webhook architecture for rate-limited vendor APIs. Pattern extracted from a production reservation-sync migration.

Python · Flask · threading · APScheduler

Before

The source system polled once daily and retried 404 custom-field lookups five times with geometric backoff: 75 seconds per miss. Pagination silently lost partial results on rate-limit hits. Detection latency was up to 24 hours. Each event cost roughly 7 vendor calls.

After

Event detection latency dropped from 24 hours to under 10 minutes. Custom-field 404s return immediately with None instead of burning 75 seconds. Vendor API calls on the hot path dropped to zero via cache hits. Partial pagination results return whatever pages succeeded instead of None.

View source on GitHub
reybenbaq/fleet-dashboard-stdlib
Fleet GPS dashboard showing device map and status table

Fleet GPS Dashboard

Self-contained fleet dashboard generator in Python standard library only. No third-party packages. No setup. Double-click to run.

Python · stdlib only · Leaflet (embedded) · CSV

Before

A challenge constraint ruled out pandas, Jinja2, and every charting library. The output had to work completely offline after generation. That combination rules out the standard toolkit and requires falling back to Python fundamentals while still handling edge cases without crashing.

After

A single script reads a CSV and outputs a fully self-contained HTML file: interactive Leaflet map with colored markers, device status table, battery indicators, and relative-time formatting. Leaflet CSS and JS are fetched once and inlined. The output opens in any browser with no server, no install, and no internet connection after generation.

View source on GitHub