Resurva
Modular monolith FastAPI backend across 18 domain modules, featuring FEFO batch inventory deduction, escrow wallet transactions, real-time SSE streaming, and a 12-tool MCP AI orchestrator.
System Overview
Indonesia produces an estimated 23–48 million tons of food waste annually, resulting in immense economic losses while contributing significantly to greenhouse gas emissions. In Solo Raya, local culinary MSMEs face constant inventory imbalances due to manual tracking and lack of structured restocking protocols.
Resurva bridges merchant inventory management and consumer demand. I designed and implemented the core backend services that coordinate merchant POS transactions, consumer surplus purchases, inventory lifecycle tracking, automated store summaries, and environmental carbon savings calculations.
Architectural & Technical Challenges
Building a dual-sided marketplace with an intelligent assistant required managing complex concurrency: inventory quantities needed instantaneous locking during reservation checkout, order status changes had to reach merchant dashboards in real-time, and AI-assisted queries had to access transactional databases safely without risky unconstrained queries.
The engineering objective was designing a modular monolith backend that kept database access cleanly separated, supported typed AI tool executions via MCP, and scaled reliably on lightweight cloud infrastructure without microservice orchestration overhead.
Key Architectural Decisions
Route-Service-Repository separation
Decoupled business rules from database queries and HTTP serialization, creating isolated service layers that can be unit-tested without mocking the entire web framework.
FEFO Batch Inventory & Escrow Wallet Mechanics
Applied First-Expired-First-Out (FEFO) batch deduction on perishable goods to ensure items closest to expiration sell first, paired with escrow wallet mechanics that safeguard buyer payments until physical verification.
Pluggable MCP tool registry pattern
Encapsulated AI tool capabilities into typed base classes registered at runtime, enabling the agent orchestrator to discover schemas dynamically without hardcoded agent logic.
Server-Sent Events for order streams
Selected SSE over bidirectional WebSockets for order notifications, providing automatic browser reconnection and lower server resource consumption for one-way event streams.
Engineering Contributions
Backend Architecture & 18 Domain Modules
Engineered the entire FastAPI REST API using the Route-Service-Repository pattern across 18 isolated domain modules, including inventory, orders, escrow wallets, cart reservations, and audit logging.
FEFO Inventory Deduction & Escrow Wallet Engine
Engineered First-Expired-First-Out (FEFO) batch inventory deduction to prioritize clearance of nearest-expiry foods, combined with an Escrow Wallet mechanism holding transaction funds until in-person pickup verification.
Database Modeling & Migrations
Designed normalized PostgreSQL relational schemas using SQLAlchemy ORM, managing database evolutions through strictly audited Alembic migration scripts.
MCP AI Agent Framework & 12-Tool Suite
Architected a custom Model Context Protocol (MCP) orchestrator and implemented 12 specialized tools for sales summarization, expiry alerts, inventory audits, and carbon analytics.
Real-Time Order Streaming (SSE)
Implemented Server-Sent Events (SSE) infrastructure for low-latency, persistent status streaming from consumer checkouts directly into merchant kitchen screens.
Automated Deployment Pipeline
Authored continuous deployment automation using GitHub Actions with SSH agent forwarding to manage seamless zero-downtime VPS backend rollouts.
Technologies & Core Stack
FastAPI • Python • PostgreSQL • MCP • SQLAlchemy • SSE • AI Integration