I like this Ui now, add all these functionlaities to it
You are an expert full-stack engineer tasked with building an AI-Powered Rental Property Analysis Tool. The system will have a Next.js (React) frontend and a Node.js backend (with Express). Please follow these instructions and code structure requirements in your output:
============================================================
- PROJECT OVERVIEW
============================================================
-
We want a web application that allows users to input rental property details (address, price, interest rate, loan duration, estimated expenses, etc.) and receive:
- Financial insights (e.g., monthly cash flow, ROI, cap rate).
- Predictive analytics (e.g., estimated rent, property appreciation, market trends).
- Textual market insights generated by a GenAI model.
-
The application architecture includes:
- Frontend: Next.js + React, using Chart.js or D3.js for visualizations, TailwindCSS or Material-UI for styling.
- Backend: Node.js + Express, Redis for caching, and a relational database (e.g., PostgreSQL) to store data.
- Data Pipeline (ETL): Uses external APIs (Zillow, Redfin, etc.) and an Airflow-based data pipeline or simple scheduling for regular updates.
- Model Training & Inference: XGBoost or Scikit-learn for predictive models; an optional large language model (like GPT) for generating insights.
- CI/CD: Automated deployments using Docker, GitHub Actions, or AWS services.
============================================================
2. REPOSITORY STRUCTURE AND FILE ORGANIZATION
Please generate code stubs and file structures for both the frontend and backend. The structure should look like this:
my-rental-app/
├── README.md
├── .gitignore
├── frontend/
│ ├── package.json
│ ├── next.config.js
│ ├── pages/
│ │ ├── index.js
│ │ ├── analyze.js
│ │ └── api/
│ ├── components/
│ │ ├── Layout.js
│ │ ├── PropertyForm.js
│ │ └── ... (other reusable components)
│ ├── styles/
│ │ └── globals.css
│ ├── public/
│ └── ...
├── backend/
│ ├── package.json
│ ├── src/
│ │ ├── index.js
│ │ ├── config/
│ │ │ ├── db.js
│ │ │ └── redis.js
│ │ ├── routes/
│ │ │ ├── analysisRoutes.js
│ │ │ ├── insightsRoutes.js
│ │ │ └── predictionRoutes.js
│ │ ├── controllers/
│ │ │ ├── analysisController.js
│ │ │ ├── insightsController.js
│ │ │ └── predictionController.js
│ │ ├── models/
│ │ │ └── Property.js
│ │ └── ...
│ └── ...
├── docker-compose.yml
├── Dockerfile-frontend
├── Dockerfile-backend
└── ...
============================================================
3. FRONTEND REQUIREMENTS
3.1 Technology Stack
- Next.js for SSR and routing.
- React for interactive components.
- TailwindCSS or Material-UI for quick UI styling.
- Chart.js or D3.js for financial data visualizations.
3.2 Features
-
Home Page (/):
- A brief overview of the tool with a call-to-action to analyze a property.
- Possibly some marketing content about the benefits.
-
Analyze Page (/analyze):
- PropertyForm component for user input (purchase price, down payment, mortgage rate, property tax, insurance, etc.).
- Submit Button to trigger an API call to the backend.
- Results Section:
- Monthly cash flow, ROI, cap rate.
- Predicted rent and property appreciation (retrieved from backend).
- Graphs showing cash flow over time, potential long-term ROI, etc.
-
Insights (Optional Page or Modal):
- Displays text-based market insights generated by the GenAI model (e.g., “This neighborhood has a strong rental demand...”).
-
Global Components:
- Layout: Nav bar, footer, consistent styling.
- Loader/Spinner: Indicate when analysis is running.
-
Design Requirements:
- Responsive layout (mobile, tablet, desktop).
- Consistent color scheme.
- Accessible form elements (labels, placeholders, error messages).
3.3 Example Code Requirements
- In
pages/analyze.js
, create the form elements.
- In
components/PropertyForm.js
, handle form state and validations.
- Use
fetch
or Axios to call the backend (/api/analyze
) and render results.
- Include skeleton or placeholder states while fetching data.
- Provide minimal CSS examples or Tailwind class usage.
============================================================
4. BACKEND REQUIREMENTS
4.1 Technology Stack
- Node.js + Express for building RESTful APIs.
- Redis for caching frequent queries (e.g., repeated property analysis in the same region).
- PostgreSQL (or MySQL) to store property data and user inputs. Use an ORM like Sequelize or Prisma.
4.2 Core API Endpoints
-
POST /api/analyze
- Purpose: Calculate cash flow, ROI, cap rate.
- Request: JSON body with property details (price, interest rate, annual taxes, etc.).
- Response: JSON with monthly cash flow, ROI, breakdown of monthly expenses.
-
POST /api/predict
- Purpose: Predict monthly rent and property appreciation using ML model.
- Request: JSON with property features.
- Response: JSON with predicted rent, annual appreciation rate, confidence intervals.
-
GET /api/insights
- Purpose: Return AI-generated textual insights about the property or market.
- Response: JSON with a string containing the generated insight.
4.3 Database Schema (Example)
- Property Table:
- id (primary key)
- address (string)
- city (string)
- state (string)
- zip (string)
- purchasePrice (float)
- ... (other relevant columns)
4.4 Caching Logic
- For repeated queries in the same location, store results in Redis for quick retrieval.
- Implement a simple caching middleware in Express (e.g.,
cache.js
) that checks Redis before hitting the controllers.
4.5 Example Code Requirements
- index.js: Set up the Express app, connect to database, configure Redis, mount routes.
- analysisRoutes.js & analysisController.js: Business logic for computing cash flow and ROI.
- predictionRoutes.js & predictionController.js: Integrate or stub ML predictions (real or mock).
- insightsRoutes.js & insightsController.js: Return either static or GPT-generated market insights.
============================================================
5. DATA PIPELINE & MODEL INTEGRATION (STUBS)
- ETL: (Not fully coded, but provide stubs or placeholders for how we’d pull data from Zillow/Redfin).
- Model:
- Provide a placeholder function (e.g.,
predictRent(propertyDetails)
) in predictionController.js
.
- Optionally show how we’d call a Hugging Face or OpenAI API for text-based insights.
============================================================
6. CI/CD AND DEPLOYMENT
- Dockerfiles for both frontend and backend:
Dockerfile-frontend
: Next.js build steps.
Dockerfile-backend
: Node.js + Express setup, plus Redis in docker-compose if needed.
- docker-compose.yml:
- Orchestrates the containers (frontend, backend, Redis, and possibly PostgreSQL).
- GitHub Actions:
- Basic YAML config for continuous integration (e.g., run linter, run tests, build Docker images).
- Provide minimal or commented placeholders if a full pipeline is out of scope.
============================================================
7. OTHER REQUIREMENTS
- Testing: Basic unit tests for both frontend (React Testing Library/Jest) and backend (Jest/Supertest).
- Documentation: Provide a short README for each major folder (frontend and backend) explaining setup and running instructions.
============================================================
8. OUTPUT FORMAT
- Please return your answer in the form of a well-organized code base outline, including (where possible) sample code snippets or placeholders.
- Use triple backticks ``` to separate code blocks for clarity.
- Write any additional notes, setup steps, or environment variable instructions (e.g., .env usage).
============================================================
9. FINAL REQUEST
Generate all necessary files for a working minimal MVP of the AI-Powered Rental Property Analysis Tool, including:
- Sample Next.js pages
- Minimal Express APIs
- A mocked or placeholder predictive model call
- Redis-based caching logic
- Docker artifacts (Dockerfiles, docker-compose)
- Basic testing stubs
- Documentation comments
Ensure that the code is clean, follows best practices, and is ready to be extended with real ETL and ML code later.