A standalone React.js conversion of the Generic AI Estimator WordPress plugin. It keeps the same visual design, fields, loader animation, result panel, validation rules, OpenAI structured JSON response flow, rate limiting, and cost/workforce calculations.
Security note: API keys are never placed in React frontend code. The OpenAI key is stored only in the backend
.envfile, which is ignored by Git.
+------------------------------------------------------+--------------------------------------+
| AI Project Estimator | What you'll get |
| Describe your project and get an instant AI-based... | AI-generated estimation based... |
| | |
| + How estimation works ----------------------------+ | + Loader / Result Panel -----------+ |
| | AI analyzes your description, estimates effort... | | Analysing your project request | |
| +--------------------------------------------------+ | | 1 Reading project description | |
| | | 2 Breaking down scope | |
| Project Description | | 3 Estimating effort | |
| [textarea] | | 4 Calculating cost range | |
| | | 5 Preparing estimate | |
| Hourly Charge USD Workforce | +----------------------------------+ |
| [30] [1] | |
| | + AI Estimate ---------------------+ |
| [Generate Estimate] | | Project Type | |
| | | Complexity | |
| | | Total AI Estimated Effort | |
| | | Workforce | |
| | | Completion Hours | |
| | | Estimated Cost | |
| | +----------------------------------+ |
+------------------------------------------------------+--------------------------------------+
flowchart LR
User["User"] --> React["React UI"]
React --> Express["Express API /api/estimate"]
Express --> Validate["Validate input with Zod"]
Validate --> RateLimit["15 requests/hour/IP"]
RateLimit --> OpenAI["OpenAI Responses API"]
OpenAI --> JSON["Strict JSON estimate"]
JSON --> Calculate["Calculate workforce hours and cost"]
Calculate --> React
| WordPress Plugin Area | React Project Equivalent |
|---|---|
[ai_estimator] shortcode HTML |
src/components/AiEstimator.jsx |
Inline CSS from get_inline_css() |
src/styles.css |
Inline JavaScript from get_inline_js() |
React state/hooks in AiEstimator.jsx |
WordPress REST route /wp-json/ai-estimator/v1/estimate |
Express route /api/estimate |
OPENAI_API_KEY WordPress constant |
.env backend variable OPENAI_API_KEY |
| WordPress transient rate limiting | express-rate-limit |
| WordPress sanitization/validation | zod request validation |
- React.js frontend with the same layout and styling as the WordPress plugin.
- Secure Express backend proxy for OpenAI API calls.
- No confidential keys committed to the repository.
.env.exampleincluded for local setup.- Same validation limits:
- Minimum description length: 20 characters
- Maximum description length: 4000 characters
- Hourly charge:
1to10000 - Workforce:
1to100
- Same loader steps and progress animation.
- Same estimate result fields:
- Project Type
- Complexity
- Total AI Estimated Effort
- Workforce
- Estimated Completion Hours
- Hourly Charge
- Estimated Cost
- Summary
- Assumptions
- React
- Vite
- Express
- OpenAI Responses API
- Zod
- Helmet
- CORS
- Express Rate Limit
ai-estimator-react/
├── server/
│ └── index.js # Secure backend API proxy
├── src/
│ ├── components/
│ │ └── AiEstimator.jsx # Main estimator UI and logic
│ ├── services/
│ │ └── estimateApi.js # Frontend API client
│ ├── App.jsx
│ ├── main.jsx
│ └── styles.css # Converted plugin CSS
├── .env.example # Safe environment template
├── .gitignore # Keeps .env and build files out of Git
├── index.html
├── package.json
└── README.md
git clone <your-repository-url>
cd ai-estimator-reactnpm installcp .env.example .envEdit .env:
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-4o-min
PORT=5174
CLIENT_ORIGIN=http://localhost:5173Do not commit .env. It is already ignored by .gitignore.
npm run devFrontend:
http://localhost:5173
Backend:
http://localhost:5174
Health check:
http://localhost:5174/api/health
npm run build
npm run previewFor production hosting, deploy the React build output from dist/ and deploy the Express server separately, or place both behind the same domain using a reverse proxy.
| Variable | Required | Example | Description |
|---|---|---|---|
OPENAI_API_KEY |
Yes | sk-... |
Server-side OpenAI API key. Never expose in React. |
OPENAI_MODEL |
No | gpt-4o-min |
Model used for estimates. Defaults to gpt-4o-min. |
PORT |
No | 5174 |
Backend server port. |
CLIENT_ORIGIN |
No | http://localhost:5173 |
Allowed frontend origin for CORS. |
POST /api/estimate
Content-Type: application/json{
"description": "Build a marketplace app with customer, vendor, and admin panels.",
"hourly_rate": 30,
"workforce": 1
}{
"success": true,
"project_type": "Marketplace Web and Mobile App",
"complexity": "High",
"min_total_hours": 240,
"max_total_hours": 420,
"min_completion_hours": 240,
"max_completion_hours": 420,
"hourly_rate": 30,
"workforce": 1,
"min_cost": 7200,
"max_cost": 12600,
"summary": "Estimated effort for a professional marketplace implementation.",
"assumptions": [
"Includes frontend and backend implementation",
"Includes standard authentication and dashboards"
]
}- Never put
OPENAI_API_KEYinsrc/,public/, or any frontend file. - Never commit
.env. - Use
.env.exampleto show required variables without real secrets. - Keep API calls to OpenAI on the Express server only.
- Restrict
CLIENT_ORIGINin production. - Add server-side authentication if you expose the app publicly.
- Adjust rate limits for your production usage pattern.
sequenceDiagram
participant User
participant React
participant API as Express API
participant OpenAI
User->>React: Enters project description, hourly rate, workforce
React->>React: Validates basic input
React->>API: POST /api/estimate
API->>API: Validates description/rate/workforce
API->>API: Applies rate limit
API->>OpenAI: Sends description with strict JSON schema
OpenAI-->>API: Returns estimate JSON
API->>API: Calculates completion hours and cost
API-->>React: Returns final estimate
React-->>User: Shows result panel
Deploy the React app to Netlify, Vercel, Cloudflare Pages, or any static host.
Set this environment variable if the backend is on a different domain:
VITE_API_URL=https://your-api-domain.com/api/estimateDeploy the Express server to Railway, Render, Fly.io, AWS, or any Node.js server.
Set production variables on the server dashboard:
OPENAI_API_KEY=your_real_key
OPENAI_MODEL=gpt-4o-min
PORT=5174
CLIENT_ORIGIN=https://your-frontend-domain.comAfter creating an empty GitHub repository:
git init
git add .
git commit -m "Convert WordPress AI estimator plugin to React"
git branch -M main
git remote add origin https://github.com/<owner>/<repo>.git
git push -u origin main- The UI intentionally keeps the original
nx-ai-*class names to preserve the WordPress plugin design exactly. - The frontend no longer depends on jQuery. Mobile auto-scroll is handled with
scrollIntoView. - The backend mirrors the original WordPress REST behavior and OpenAI structured JSON schema.
- Confidential values must be supplied by each user locally through
.env.