Listing Lab AI

Back End Architecture

Listing Lab's backend connects AI models, real estate data, and our infrastructure in a loosely coupled, event driven architecture. The backend combines Next.js API routes, AWS Bedrock, and caching to deliver robust capabilities.

Event-Driven Architecture with Inngest and TRPC

Listing lab embraces an event-driven architecture to handle various backend operations asynchronously and efficiently. This approach leverages Ingest, a library for creating type-safe events and event handling, similar to AWS Step Functions but with additional features.

When a user initiates an action, such as requesting details for a new property, a request is sent to a Next.js API route. This route quickly checks if the property data exists in the cache and returns the basic information to the client, ensuring a fast initial response.

Before completing the request, an event is created and sent to the Ingest event handling server. This server matches the event to a corresponding function that handles enriching the property data with additional details an agent might need. These details include mortgage information, nearby businesses and points of interest, tax data, and real estate investment metrics like operating income, cap rate, and price-per-square-foot comparisons.

By handling this data enrichment asynchronously, Listing Lab avoids delays in the initial client response. While the user receives basic property information quickly, the backend continues to gather and store the enriched data, ensuring it's readily available when an agent needs to generate content or access detailed information.

When an agent initiates a text generation request, such as creating a listing description, the request is sent to a tRPC (Type-safe Remote Procedure Call) API route. tRPC provides a fully type-safe way to create APIs, allowing the same typed functions to be called on both the server and client sides, ensuring type safety and preventing sensitive code from reaching the client.

The tRPC route handles tasks like checking user permissions, API limits, and subscription levels before selecting the appropriate language model and running the text generation. The generated content is then returned to the client, while an event is created and sent to Ingest for analytics and metrics tracking.

OpenAI and AWS Bedrock Integration

AWS Bedrock provides easy access to large language models like GPT-3, Codex, and more through a serverless API. Listing Lab uses Bedrock to integrate these robust NLP models quickly. Bedrock handles provisioning, scaling, and load balancing of the models. Listing Lab just needs to call the API with text prompts to leverage them. Usage is efficiently billed per request.

Turso for SQLite at the edge

For storing and managing data, Listing Lab uses Turso's libSQL database, an open contribution fork of SQLite. Turso provides a highly performant, embedded SQL database that can run locally or over the network. We use Turso to store user data like account details, chat history, and saved prompts. It also caches housing data retrieved from real estate APIs for fast lookup.

Turso's SQLite foundation offers several advantages:

Best-in-class developer experience: Integrate SQLite into production applications with ease, whether building for web, mobile, or desktop. Massively scalable and replicable: Turso's native replication and multi-tenancy features allow scaling to millions of databases with low resource usage. Develop, test, and deploy with the same database: Test locally without needing to spawn containers or services, then deploy the same code to production. Data portability: SQLite databases are simple files, enabling easy data portability. Edge-optimized: Turso minimizes query latencies by replicating data close to users, achieving microsecond latencies with embedded replicas.

Turso's SQLite-based architecture provides a robust, flexible, and performant data storage solution for Listing Lab's backend.

Backend recap

In conclusion, Listing Lab's backend is a well-oiled machine that combines Next.js API routes, AWS Bedrock, caching, and an event-driven architecture with Ingest. Next.js acts as the glue, Bedrock provides the AI muscle, caching keeps things snappy, and Ingest orchestrates everything behind the scenes.

The real magic happens with Inngest handling events asynchronously. Users get a quick response upfront, while the backend hustles in the background to enrich data and crunch numbers. tRPC APIs make client-server communication secure and type-safe.

All these pieces fit together to create a high-performing, scalable conversational platform backed by Turso's powerful data storage. The event-driven approach with Ingest allows seamless third-party integrations, analytics tracking, and smooth backend operations – delivering a top-notch experience for Listing Lab's users and agents.