StockLens AI
Comparing two stocks usually means bouncing between a dozen tabs—charts on one site, financial ratios on another, recent news somewhere else, and a generic AI tool to make sense of it all. Gathering the data takes longer than analyzing it, and it's hard to tell which differences actually matter or what risks you missed.
I built StockLens AI to fix that. It’s a full-stack research assistant that brings financial metrics, price history, recent news, and AI-driven analysis into a single view for any two public companies.
Crucially, it isn't a financial advisor or a price predictor. It's an educational tool designed to speed up research while keeping humans in the loop. The generated analysis must explicitly cite data points already stored in the backend, making every AI claim easy to trace and verify.
This project was also a practical experiment in AI-assisted engineering: using ChatGPT as a high-level architect and debugger, and Codex as an in-repo developer to implement milestones, write tests, and run validations.
What It Does
StockLens AI gives users a side-by-side dashboard to compare two tickers:
- Profiles & Market Data: Real-time snapshots and basic company info.
- Price & Return Charts: Toggle between raw historical prices and normalized percentage returns over identical timeframes.
- Financial Health: Metrics grouped by valuation, profitability, growth, and leverage.
- Curated News: Recent coverage linked directly back to original publishers.
- Grounded AI Briefs: On-demand analysis covering relative strengths, weaknesses, and key risks.
- Strict Source References: Every insight cites backend-verified data sources.
- Control: Manual data refreshes without forcing expensive or unnecessary AI regenerations.
Instead of throwing an open-ended prompt at an LLM, StockLens builds a deterministic context using normalized data already present in PostgreSQL. The AI brief is only generated when a user asks for it, keeping API costs under control and outputs consistent.
Architecture & Tech Stack
[ React + TS ] <---> [ Spring Boot 3 / Java 21 ] <---> [ PostgreSQL ]
| | ^
| +--> [ Redis Cache ] -+
|
+--> [ External APIs ]
| - Financial Modeling Prep
| - Yahoo Finance
|
+--> [ OpenAI API via Spring AI ]
- Backend: Built with Java 21 and Spring Boot. Spring Data JPA handles object mapping, and PostgreSQL serves as the durable source of truth.
- Caching: Redis acts as a fast, best-effort cache layer. If Redis drops, the system falls back seamlessly to PostgreSQL without breaking.
- Frontend: Built with React and TypeScript, focusing on a responsive, dense visual layout with clear state indicators (cached vs. live data).
- Data Pipelines: Company stats and fundamentals come from Financial Modeling Prep. News is pulled through a customized Yahoo Finance adapter, then cleaned and normalized before saving.
- AI Engine: Structured prompts are passed to OpenAI via Spring AI. The output uses typed responses mapping directly to internal data IDs.
Securing the AI Pipeline
To prevent hallucinated data and bad citations, the backend runs model responses through a multi-step validation pipeline:
- Map cited IDs back to data known to the system.
- Reject any citation that can't be mapped or resolved to backend records.
- Cap total cited sources to keep the brief focused.
- Run a single auto-repair loop with targeted error feedback if validation fails.
- Reject and log any response that still fails validation (preventing invalid data from touching Redis or Postgres).
The AI-Assisted Workflow
Rather than trying to generate the whole codebase with a single massive prompt, I split responsibilities between two AI tools:
- ChatGPT (System Architect & Peer): Used to refine product requirements, map out the technical stack, break the project into testable milestones, review logs, and debug tricky edge cases.
- Codex (Software Engineer): Operated inside the repository to implement isolated tasks, update backend/frontend components, write tests, and run local validation scripts.
My role was product owner and lead developer—directing the scope, reviewing PRs, catching design flaws, and running local verification steps.
This approach paid off. The repository currently maintains over 150 backend tests (JUnit, Mockito, Testcontainers for Postgres and Redis) and 28 frontend tests (Vitest, React Testing Library), running clean without hitting external APIs during automated builds.
Technical Challenges & Hard Lessons
1. Data Provider Limits & Normalization
Early iterations relied heavily on Financial Modeling Prep, but strict rate limits made development frustrating. I abstracted our data provider interfaces, routing news fetching to Yahoo Finance while keeping FMP for balance sheets and ratios. Normalizing these distinct payloads into a clean internal format proved critical for maintaining stable chart renderers and metrics tables.
2. Guardrails for LLM Citation Drift
Getting an LLM to return valid JSON is easy; getting it to reliably cite internal database IDs without hallucinating non-existent sources is hard. Early versions often returned dozens of low-quality citations. Solving this required tightening the prompt context, normalizing incoming source IDs on the server, and building an automated repair loop for invalid payloads.
3. Debugging JPA Pagination Errors
A live query on PostgreSQL exposed a SQL aliasing error during a paginated fetch that unit tests missed. Using ChatGPT to analyze the Hibernate logs, I tracked the issue to an improper collection join, re-architected it into a two-step query, and wrote an integration test using Testcontainers to catch similar regression risks going forward.
What’s Next
Now that the local stack, test suite, and core features are stable, the next steps focus on production readiness:
- Deployment Pipeline: Containerize services for cloud deployment with continuous integration checks.
- User Accounts: Save favorite comparisons and watchlists.
- Smarter News Quality: Add deduplication algorithms and relevancy scoring for market news.
- Provider Flexibility: Support multiple LLM backends (e.g., Anthropic, local Ollama models) via Spring AI's unified abstraction layer.
- Deeper Fundamentals: Expand metrics coverage to include multi-year cash flow and balance sheet trendlines.
Built With
- codex
- docker
- java
- openai
- postgresql
- react
- springboot
- typescript
Log in or sign up for Devpost to join the conversation.