Deployment
Relevant source files
The following files were used as context for generating this wiki page:The Greenline application is composed of a decoupled frontend and backend, requiring separate deployment processes. The frontend is a Next.js application responsible for rendering the user interface and interacting with various external and internal APIs. The backend consists of a Python-based Machine Learning service that provides stock price forecasting.
A successful deployment requires building and running the Next.js application, running the Python backend service, and correctly configuring all necessary environment variables for both components to communicate with each other and with third-party data providers.
System Architecture
The overall system architecture involves the user's browser, a Next.js server, a Python ML backend, and several external APIs for financial data and AI-powered insights.
This diagram illustrates the high-level interaction between the different components of the Greenline platform.
Frontend Deployment (Next.js)
The client-side application is built with Next.js. Its deployment involves building the static assets and running the Node.js server.
Sources: client/package.json
Build & Run Scripts
The package.json file defines the necessary scripts for building and running the application in a production environment.
| Script | Command | Description |
|---|---|---|
build | next build | Compiles the Next.js application for production. |
start | next start | Starts the Next.js production server after a build has been completed. |
dev | next dev | Starts the Next.js development server with hot-reloading. |
lint | next lint | Runs the Next.js linter to check for code quality issues. |
Sources: client/package.json:5-8
The standard deployment flow is to first run npm run build (or an equivalent command for your package manager) followed by npm run start.
Environment Variables
The application relies on several environment variables to connect to external services. These must be configured in the deployment environment (e.g., as .env.local file or through the hosting provider's interface).
| Variable Name | Purpose | Used In - client/src/components/Hero/index.tsx
- client/src/components/StockSummary/index.tsx
- client/src/components/StockRating/index.tsx |
|NEXT_PUBLIC_POLYGON_API_KEY| API key for Polygon.io service. Used for fetching market data, news, and company info. |
|NEXT_PUBLIC_OPENAI_API_KEY| API key for OpenAI. Used for generating AI-powered stock summaries and chat functionality. |
|(unnamed)| A hardcoded API key forfinancialmodelingprep.comis used for stock ratings. |
Sources: client/src/components/Hero/index.tsx:22, client/src/components/StockSummary/index.tsx:75, client/src/components/StockRating/index.tsx:50, client/src/app/portal/page.tsx:44
Backend Deployment (Python ML Service)
The backend is a Python service responsible for generating stock price forecasts. It is expected to be running and accessible to the Next.js frontend.
Service Endpoint
The frontend application makes a POST request to a hardcoded endpoint to get forecast data.
- URL:
http://localhost:8000/forecast/ - Method:
POST - Description: Takes historical stock data and returns a forecast.
This is the code snippet from the StockChart component that calls the backend:
// client/src/components/StockChart/index.tsx
const response = await fetch('http://localhost:8000/forecast/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ historical_data: historicalData, forecast_days: 5 }),
});
Sources: client/src/components/StockChart/index.tsx:121-125
Deployment Considerations
- The service must be running on
localhost:8000relative to the Next.js server environment, or the URL inStockChart/index.tsxmust be updated to point to the correct production location of the ML service. - The Python service will have its own dependencies (e.g., from a
requirements.txtfile) that need to be installed. - A process manager (like Gunicorn or Uvicorn, often used with frameworks like FastAPI or Flask) is required to run the Python web application in a production setting.
The following sequence diagram shows the flow for generating a stock forecast.
External Service Dependencies
The application is heavily reliant on third-party APIs for its core functionality. Access to these services must be available from the deployment environment.
| Service | API Endpoint Domain | Function - client/src/components/Hero/index.tsx
- client/src/app/portal/page.tsx
- client/src/app/quote/[ticker]/page.tsx |
| Polygon.io |api.polygon.io| Provides live market data, historical aggregates, company details, and news. |
| OpenAI |api.openai.com(via SDK) | Powers AI-driven features like the stock summary timeline and the ticker-specific chat. |
| Financial Modeling Prep |financialmodelingprep.com| Provides detailed stock rating analysis and metrics. |
Sources: client/src/components/StockRating/index.tsx:49, client/src/components/StockSummary/index.tsx:74, client/src/components/Navbar/index.tsx:50