Skip to content

Production-grade multi-agent system for intelligent portfolio analysis and retirement planning

Notifications You must be signed in to change notification settings

CodeBy-HP/AlexAI-Financial-Advisor-SaaS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ Alex - AI Financial Planning Platform

Production-grade multi-agent system for intelligent portfolio analysis and retirement planning

Python TypeScript Next.js Terraform AWS Azure OpenAI


๐ŸŽฏ Overview

Five AI agents. One orchestrated system. Real financial analysis at scale.

Built on AWS serverless with Terraform, powered by Azure OpenAI GPT-4o, and running vector search at 90% less cost. This isn't a prototypeโ€”it's production infrastructure handling multi-tenant workloads with autonomous research, real-time insights, and zero server management.


โœจ Core Features

๐Ÿค– INTELLIGENT MULTI-AGENT ORCHESTRATION

  • 5 specialized AI agents collaborating through SQS messaging
  • Azure OpenAI GPT-4o powering intelligent analysis
  • Parallel Lambda execution for 3x faster processing
  • Autonomous research with Tavily API integration
  • Each agent focused, independent, unified insights

โšก PRODUCTION-GRADE INFRASTRUCTURE

  • 100% Terraform-managed serverless AWS architecture
  • S3 Vectors for 90% cost reduction vs traditional vector DBs
  • Aurora Serverless v2, Lambda, App Runner, SageMaker embeddings
  • CloudWatch observability + LangFuse agent tracing
  • Zero servers, automatic scaling, pay-per-use

๐Ÿ” ENTERPRISE-READY FULL-STACK

  • Next.js 15 + React 19 with TypeScript and Framer Motion
  • Clerk authentication with multi-tenant PostgreSQL isolation
  • API Gateway with key-based security
  • Real-time streaming responses and CloudFront CDN
  • EventBridge automated research scheduling (every 2 hours)

๐Ÿ›๏ธ System Architecture

AWS Services Workflow

aws diagram drawio (1)

Job Lifecycle

Mermaid Chart - Create complex, visual diagrams with text -2026-02-03-165331

AWS Infrastructure

  • Compute: AWS Lambda (6 functions), App Runner (Researcher service)
  • Database: Aurora Serverless v2 PostgreSQL
  • AI/ML: Azure OpenAI GPT-4o, SageMaker Serverless (embeddings)
  • Storage: S3 (vectors, static assets), ECR (Docker images)
  • Orchestration: SQS, EventBridge Scheduler
  • Frontend: CloudFront + S3, API Gateway
  • Monitoring: CloudWatch, LangFuse (observability)

Database Schema

Mermaid Chart - Create complex, visual diagrams with text -2026-02-03-161347

Schema Design:

  • users: Clerk authentication with retirement goals and target allocations
  • accounts: Investment accounts (401k, IRA, taxable) with cash positions
  • positions: Holdings per account with quantity and valuation date
  • instruments: Shared ETF/stock reference data with JSONB allocation metadata
  • jobs: Async analysis tracking with dedicated JSONB fields per agent output (no merging logic needed)

๐Ÿ› ๏ธ Tech Stack

Backend & AI

  • Language: Python 3.12 with uv package management
  • LLM: Azure OpenAI GPT-4o (chat completions API)
  • Agents Framework: OpenAI Agents SDK
  • Embeddings: SageMaker Serverless (sentence-transformers)
  • Web Search: Tavily API
  • Observability: LangFuse for tracing

Frontend

  • Framework: Next.js 15 (React 19, TypeScript)
  • Styling: Tailwind CSS
  • Auth: Clerk
  • Charts: Recharts
  • Animations: Framer Motion

Infrastructure & DevOps

  • IaC: Terraform (modular architecture)
  • Cloud: AWS (Lambda, Aurora, S3, CloudFront, API Gateway, SQS, EventBridge)
  • Containers: Docker, ECR
  • Database: PostgreSQL (Aurora Serverless v2)
  • Vector Storage: S3 Vectors

๐Ÿ“ Project Structure

alex/
โ”œโ”€โ”€ backend/                 # Python agents and Lambda functions
โ”‚   โ”œโ”€โ”€ planner/            # Orchestrator agent (coordinates all agents)
โ”‚   โ”œโ”€โ”€ tagger/             # Instrument classification agent
โ”‚   โ”œโ”€โ”€ reporter/           # Portfolio analysis and metrics
โ”‚   โ”œโ”€โ”€ charter/            # Data visualization and charting
โ”‚   โ”œโ”€โ”€ retirement/         # Retirement projections
โ”‚   โ”œโ”€โ”€ researcher/         # Autonomous web research (App Runner)
โ”‚   โ”œโ”€โ”€ ingest/             # Document processing and vector storage
โ”‚   โ”œโ”€โ”€ database/           # Shared database library
โ”‚   โ””โ”€โ”€ api/                # FastAPI backend for frontend
โ”‚
โ”œโ”€โ”€ frontend/               # Next.js application
โ”‚   โ”œโ”€โ”€ pages/             # Route components
โ”‚   โ”œโ”€โ”€ components/        # React components
โ”‚   โ””โ”€โ”€ lib/               # API client and utilities
โ”‚
โ”œโ”€โ”€ terraform/             # Infrastructure as Code (modular)
โ”‚   โ”œโ”€โ”€ 2_sagemaker/      # SageMaker embedding endpoint
โ”‚   โ”œโ”€โ”€ 3_ingestion/      # S3 Vectors, ingest Lambda
โ”‚   โ”œโ”€โ”€ 4_researcher/     # App Runner research service
โ”‚   โ”œโ”€โ”€ 5_database/       # Aurora Serverless v2
โ”‚   โ”œโ”€โ”€ 6_agents/         # Multi-agent Lambda deployment
โ”‚   โ”œโ”€โ”€ 7_frontend/       # CloudFront, S3, API Gateway
โ”‚   โ””โ”€โ”€ 8_enterprise/     # Monitoring and dashboards
โ”‚
โ””โ”€โ”€ scripts/               # Deployment automation

๐Ÿš€ Deployment Architecture

Infrastructure Provisioning

The entire AWS infrastructure is managed through Terraform modules, deployed in sequence:

  1. SageMaker โ†’ Serverless embedding endpoint
  2. Ingestion โ†’ S3 Vectors, document processing Lambda
  3. Researcher โ†’ App Runner service with Tavily integration
  4. Database โ†’ Aurora Serverless v2 cluster
  5. Agents โ†’ Multi-agent Lambda functions + SQS orchestration
  6. Frontend โ†’ CloudFront distribution, S3 hosting, API Gateway
  7. Enterprise โ†’ CloudWatch dashboards and monitoring

Multi-Agent System

Planner Agent (Orchestrator):

  • Receives user requests via API Gateway
  • Coordinates execution across specialized agents
  • Manages state and context flow
  • Returns unified responses

Specialized Agents:

  • Tagger: Classifies financial instruments (stocks, bonds, ETFs)
  • Reporter: Analyzes portfolio performance, risk metrics, allocations
  • Charter: Generates interactive visualizations and charts
  • Retirement: Projects retirement scenarios with Monte Carlo simulations
  • Researcher: Conducts autonomous web research using Tavily API

๐Ÿ“Š What I Built

Technical Achievements

โœ… Serverless Multi-Agent System: Deployed coordinated AI agents with sub-2s response times

โœ… Cost-Optimized Infrastructure: Reduced vector storage costs from $300/mo to $30/mo

โœ… Production-Grade Observability: Integrated LangFuse for complete agent tracing

โœ… Infrastructure as Code: 100% Terraform-managed, reproducible deployments

โœ… Real-Time Web Research: Automated market research with Tavily API integration

โœ… Full-Stack SaaS Platform: Clerk authentication, multi-tenant PostgreSQL, responsive UI

โœ… Autonomous Scheduling: EventBridge-triggered research updates every 2 hours

โœ… Enterprise Security: API Gateway authentication, user-level data isolation


๐ŸŽ“ What I Learned

AWS Serverless at Scale

  • Architecting multi-Lambda orchestration with SQS
  • Optimizing Aurora Serverless v2 for cost and performance
  • Managing serverless cold starts and connection pooling

AI Engineering in Production

  • Building reliable multi-agent systems with error handling
  • Implementing observability with LangFuse tracing
  • Prompt engineering for consistent financial analysis

Infrastructure as Code

  • Modular Terraform architecture for complex systems
  • Managing state and dependencies across 7 infrastructure layers
  • Automated deployment pipelines with uv and Docker

Vector Search & Embeddings

  • Implementing S3 Vectors for cost-effective similarity search
  • SageMaker Serverless endpoint optimization
  • Chunking strategies for financial documents

Full-Stack Development

  • Next.js 15 App Router with server components
  • Real-time streaming from Lambda via API Gateway
  • Clerk authentication with multi-tenant isolation

๐Ÿ”ฎ Future Enhancements

Technical Improvements

  • WebSocket Integration: Replace polling with real-time bidirectional communication
  • Redis Caching: Cache research results and agent responses
  • A/B Testing: Compare agent prompts and model performance
  • GraphQL API: More flexible data fetching for frontend

Feature Additions

  • Portfolio Optimization: ML-powered asset allocation recommendations
  • Risk Scoring: Real-time risk assessment dashboard
  • Document Chat: Interactive Q&A with uploaded financial documents
  • Mobile App: React Native companion app

Infrastructure Evolution

  • Multi-Region Deployment: Global availability with Route53
  • Kubernetes Migration: EKS for advanced orchestration
  • Prometheus/Grafana: Enhanced monitoring stack
  • CI/CD Pipeline: GitHub Actions for automated testing and deployment

๐Ÿ‘ค Author

Harsh Patel
๐Ÿ“ง code.by.hp@gmail.com
๐Ÿ”— GitHub โ€ข LinkedIn


๐ŸŽ“ Special Thanks

A big thank you to Ed Donner for his excellent MLOps Track, which played a key role in shaping this project and my understanding of building production-grade, agentic AI systems.

๐Ÿ“˜ Course: Generative and Agentic AI in Production
๐Ÿ”— https://www.udemy.com/course/generative-and-agentic-ai-in-production/


โญ Star this repo if you found it insightful

About

Production-grade multi-agent system for intelligent portfolio analysis and retirement planning

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published