Skip to content
← All projects

Investment Advisor

I built it solo, and it is where I started combining infrastructure with AI.

  • Python
  • FastAPI
  • AWS Bedrock
  • MongoDB Atlas
  • Terraform
  • GitHub Actions
Architecture diagram for Investment Advisor
Tap or click to open full size

Demo

A real run of the app on my laptop, with an in-memory database, a sample portfolio and live market prices. The AI strategist panel is collapsed, because it needs a language model that this local run does not include.

The problem

Many retail investors track their holdings in a spreadsheet. A spreadsheet cannot show live prices, show how concentrated a portfolio is by sector, alert on a large daily move, or answer "am I over-exposed to tech right now?" in plain English.

I wanted to replace the spreadsheet with a browser terminal that prices positions live, and an AI strategist that answers questions using both the user's own portfolio and fresh web search results.

Architecture

The app is a FastAPI backend that also serves a plain JavaScript frontend, packaged as one Docker image with nginx in front of uvicorn. Data lives in MongoDB Atlas. Prices come from Yahoo Finance, so every position shows live P&L and daily change.

A chat request goes to a single endpoint. The backend builds a prompt from the user's holdings at live prices plus up to five web search results, then sends it to the configured model: Amazon Bedrock through the Converse API, or any OpenAI-compatible endpoint. At startup the app loads its secrets from SSM Parameter Store, ships logs to CloudWatch, and can send email alerts through SES.

The AWS side is defined in Terraform: a VPC with one public subnet, a single EC2 instance that runs the container with Docker Compose under systemd, an Elastic IP, a scoped IAM role, the SSM parameters, a CloudWatch log group and a status-check alarm to SNS, and an EventBridge schedule that triggers a Lambda for a daily close summary on weekdays. Terraform state lives in S3 with DynamoDB locking.

What I built

  • An AI strategist on AWS Bedrock that reasons over the user's live holdings and real-time web search, with Bedrock Guardrails keeping responses inside policy. When a Guardrail steps in, the UI shows a clear message instead of a raw error.
  • One chat endpoint and response shape over Bedrock and OpenAI-compatible backends (Ollama, LM Studio, Groq), so the model can be swapped with one setting and without touching the UI.
  • JWT auth with bcrypt, role-based access (user and admin, plus per-portfolio ownership checks) and token versioning, so changing a password or username invalidates every older token.
  • 30 REST endpoints for portfolios, trades, Excel import and export, market data and chat, with a per-user rate limit on chat.
  • Terraform-defined AWS infrastructure: 39 resources in the main stack plus a 5-resource bootstrap stack for remote state.
  • A GitHub Actions CI pipeline (lint, tests and a Docker build-and-boot check) and a tag-gated GitHub Actions deploy pipeline that runs Terraform and then redeploys the instance through SSM Run Command.
  • CloudWatch logging and SES alerts: an email when a portfolio moves past a daily threshold, and a daily close summary.

Decisions and trade-offs

One small EC2 instance instead of ECS or Fargate. I chose one t3.micro for cost: it fits the AWS free tier for the first year. Later I moved from running Python directly on the host to Docker Compose under systemd, which meant raising the instance metadata hop limit so the container could still use the instance role.

No secrets on disk. In production the app reads its secrets from SSM Parameter Store and calls AWS through its IAM role, so there is no .env file on the server and no hardcoded keys.

Token versioning instead of a blocklist. Each user carries a version number that is also inside their JWT. Bumping it revokes old tokens without adding Redis or a token blocklist.

Deploys are opt-in. The deploy pipeline only runs on version tags, so a push to main never touches AWS. Redeploys go through SSM Run Command instead of SSH, because instance user data only runs once.

Remote state even for a solo project. I set up an S3 state bucket with DynamoDB locking from the start, so state is versioned and two applies can never run at once.

What went wrong and how I fixed it

Guardrails blocked normal questions. I had placed the system prompt inside the user message to work around a model compatibility issue. The Guardrail's misconduct and prompt-attack filters then flagged legitimate requests. Moving the system prompt into the Converse API's system parameter fixed the false positives.

Only some secrets loaded. The SSM loader stopped at the API's default page size of 10 parameters, so later secrets were missing. I added pagination. Logging was not configured yet at import time, so the loader's own messages were invisible until I switched them to plain prints.

Models were retired under me. Amazon Titan reached end of life mid-project, so I moved to Amazon Nova Micro. Later Claude 3.5 Haiku was retired as well, and I moved to Claude Haiku 4.5.

The test suite was quietly broken. 24 of 28 smoke tests were returning 401 because the auth module bound the database at import time and the tests never patched it. The chat tests mocked the HTTP client while the Bedrock path used boto3, so they were silently calling real AWS. I fixed both in one pass.

A blocking call in an async route. The boto3 Bedrock call blocked the event loop. I moved it to a thread executor and raised the nginx and uvicorn timeouts to cover long model responses.

Results

  • 30 REST endpoints behind JWT auth with roles.
  • 28 smoke tests, run in CI together with lint and a Docker boot check.
  • 44 Terraform resources in total: 39 in the main stack and 5 in the state bootstrap.
  • Chat that works the same way over Bedrock and OpenAI-compatible backends, with optional Bedrock Guardrails.