Files · Databricks Code Sandbox for NetSuite SMB Financial Modeling
68 (1 binary, 609.4 kB total)attempt 1
README.md·3636 B·markdown
markdown
# Databricks Code Sandbox for NetSuite SMB Financial Modeling
> Run safe, budget-aware financial models on NetSuite data using natural language queries, eliminating spreadsheet errors and manual data pulls.
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build production-grade AI systems with the `@reaatech/*` package family.
## Prerequisites
The following environment variables must be set:
| Variable | Description |
|---|---|---|
| `NODE_ENV` | Environment (`development`, `production`) |
| `DATABRICKS_HOST` | Databricks workspace URL |
| `DATABRICKS_TOKEN` | Databricks personal access token |
| `E2B_API_KEY` | E2B code interpreter API key |
| `NETSUITE_ACCOUNT_ID` | NetSuite account ID |
| `NETSUITE_CONSUMER_KEY` | NetSuite OAuth consumer key |
| `NETSUITE_CONSUMER_SECRET` | NetSuite OAuth consumer secret |
| `NETSUITE_TOKEN_ID` | NetSuite OAuth token ID |
| `NETSUITE_TOKEN_SECRET` | NetSuite OAuth token secret |
| `NETSUITE_BASE_URL` | NetSuite REST API base URL |
| `PORT` | HTTP server port (default `3001`) |
Copy `.env.example` to `.env` and fill in the values.
## API
### `POST /api/analyze`
Submit a financial query.
**Request:**
```json
{
"query": "show me Q3 revenue by region",
"tenantId": "acme-corp"
}
```
**Success response (200):**
```json
{
"success": true,
"result": "Q3 Revenue by Region:\nWest: $1,200,000\nEast: $980,000\nCentral: $750,000",
"script": "import pandas as pd\n...",
"executionId": "a1b2c3d4-...",
"cost": 0.0045
}
```
**Error response (400):**
```json
{
"success": false,
"error": "Daily budget exceeded"
}
```
### `GET /api/health`
Health check endpoint.
## Architecture
```
Client → Next.js API Route → Databricks SDK → Databricks Code Sandbox
↓
E2B Code Interpreter (Python)
↓
NetSuite REST API
↓
LLM Cost Telemetry + Budget Engine
```
The pipeline:
1. User submits a natural language query via `POST /api/analyze`.
2. Budget pre-flight check via `@reaatech/agent-budget-engine` — halts execution if daily budget is exceeded.
3. Fetches NetSuite data via a REST client (OAuth 1.0, saved searches, record types).
4. An LLM generates Python code using Databricks Code Sandbox.
5. Code passes through `@reaatech/structured-repair-core` to fix syntax issues in the generated output.
6. The repaired script is classified by `@reaatech/confidence-router` — blocked if unsafe.
7. Approved code runs in an E2B sandbox, querying the fetched NetSuite data.
8. Spend is recorded through `@reaatech/agent-budget-engine` and cost-telemetry via `@reaatech/llm-cost-telemetry`.
9. The response includes the result, the generated script, and execution cost.
## Running locally
```bash
pnpm install
pnpm test # vitest run with coverage
pnpm dev # next dev on port 3001
```
## Example
```bash
curl -X POST http://localhost:3001/api/analyze \
-H "Content-Type: application/json" \
-d '{"query": "show me Q3 revenue by region", "tenantId": "acme-corp"}'
```
## Project layout
```
app/ Next.js App Router pages + API routes
src/ services, lib, adapters
src/types/ TypeScript type definitions and Zod schemas
tests/ vitest suite (mirrors src/)
packages/ API references for every dependency (read these first)
DEV_PLAN.md build plan for this recipe
```
## License
MIT — see [LICENSE](./LICENSE).