akshat porwal

AI Engineering
Cloud & DevOps
Solutions Architecture
Fintech

Stonks-in-Hand / 01

System architecture.

Explore the system and follow the path from discovery to delivery.

Explore the system by selecting a component. Use the zoom controls or scroll and pinch to inspect the connections.

The problem

Stonks-in-Hand brings ASX announcements, news and public discussion into a single research workflow. The architecture is designed to collect documents, analyse them and surface results without making the user wait for the work to finish.

A core requirement is traceability: a summary should lead back to the source material it describes. PostgreSQL stores structured application data and analysis results, while raw documents are kept separately.

Presentation and API

A Next.js frontend is delivered through S3 and CloudFront. API Gateway routes requests to a FastAPI application running on Lambda, with Cognito supporting authentication.

Collection and processing

EventBridge schedules discovery. Discovery, download and analysis are separated into stages, with SQS queues buffering work and S3 events connecting document storage to analysis. Separate functions allow stages to be configured and retried independently.

The collection design covers company announcements and other approved sources, including Marketaux, Reddit, Bluesky, Mastodon and RSS or Atom feeds. Playwright and PRAW are part of the collection toolkit.

Analysis and delivery

Analysis combines rules-based classification, Amazon Bedrock summarisation and FinBERT sentiment analysis. Results and application data are stored in Supabase PostgreSQL. A separate notification queue and Lambda handle watchlist email alerts through Brevo.

Operations

GitHub Actions, AWS SAM and CloudFormation support deployment and rollback. CloudWatch and dead-letter queues help surface failures. The diagram shows the major relationships; individual retry paths and configuration details are not exhaustive.

A request, step by step

Consider an administrator requesting announcements for BHP. CloudFront sends the /api request to API Gateway, which invokes the API Lambda. FastAPI checks the request and records a scrape run before placing discovery work on SQS. The endpoint returns HTTP 202 with a run ID: the request has been accepted, but the document processing is still underway.

Mangum is the adapter between the AWS event format and FastAPI’s ASGI interface. In the project’s Lambda entry point, it removes the /api base path before FastAPI matches the route and translates the response back for API Gateway. The gateway routes the request; FastAPI implements the application’s endpoints.

An optional Idempotency-Key helps the API recognise a repeated request. This matters when a client retries after a network interruption: the first request may have succeeded even if the response never reached the client.

From discovery to analysis

A manual request and a scheduled run both create work for discovery. The scheduler starts a function that creates a run and enqueues discovery; discovery finds candidate announcements, records their metadata and sends eligible documents to the download queue. Discovery identifies what to fetch—it does not need to complete every later stage.

The download worker retrieves each document and stores its bytes in S3. A storage event initiates queued analysis, which extracts and interprets the content. The analysis design combines rules-based classification, a model-assisted summary and FinBERT sentiment, then passes results and alert work onward.

A queue message is a small description of work, such as a run ID or document reference. It is not the document itself. The queue buffers work, S3 holds the original file, and PostgreSQL holds structured records, status and links back to the source.

Retries and recovery

SQS can deliver a message more than once. A handler therefore needs to be safe to repeat: for example, recording a document or sending an alert should not create unintended duplicates after a retry. A visibility timeout temporarily hides a message while a worker handles it; it is not a guarantee of exactly-once processing.

Repeated failures can be moved to a dead-letter queue for investigation. The original file and run status make it possible to understand where processing stopped. A dead-letter queue isolates a problem; monitoring and a recovery procedure are still needed to diagnose and replay work safely.

In the reviewed infrastructure template, discovery and download use one-message batches and a 30-minute visibility timeout, with a redrive limit of five receives. The announcement schedule is configured but disabled by default. These are configuration values from the reviewed snapshot, not guarantees about every future deployment.

Interpreting results

A generated summary and sentiment label are aids to research. They can omit context or misinterpret language, so the interface should make the original document accessible for review. The separation between raw files and structured results supports that traceability.