Loading data from network...
# Chat-Based AI Automation Platform (MVP)
Modern SaaS dashboard to connect apps, enable AI modules, build automations (IF -> THEN), and receive outputs directly in chat (Telegram/WhatsApp).
## Requirements
- Node.js 20+ (you have `node` installed)
- Yarn classic (`yarn`) or npm (Yarn is recommended for this repo)
- Docker Desktop (recommended for PostgreSQL + Redis)
## Why everything is inside `apps/`?
This repo is a small monorepo so it's easier to deploy and maintain:
- `apps/web` = the React dashboard (deploy to Vercel)
- `apps/api` = the Node.js API + worker (deploy to a Node host like Render/Railway/Fly)
## 1) Start PostgreSQL + Redis
From the repo root:
```bash
docker compose up -d
```
This starts:
- Postgres on `localhost:5432`
- Redis on `localhost:6379`
## 2) Configure environment variables
Create API env file:
1. Copy `apps/api/.env.example` -> `apps/api/.env`
2. Update values if needed
Create Web env file:
1. Copy `apps/web/.env.example` -> `apps/web/.env`
## 3) Install dependencies
From the repo root:
```bash
yarn install
```
If your Windows PowerShell blocks `yarn`/`npm` scripts, run via `cmd`:
```bash
cmd /c yarn install
```
## 4) Create database schema
From the repo root:
```bash
yarn db:push
```
If you prefer local installs (no Docker), install PostgreSQL + Redis yourself and update `apps/api/.env`:
- `DATABASE_URL` (Postgres connection string)
- `REDIS_URL` (Redis connection string)
## Using an online database (newbie-friendly, recommended)
You can use hosted PostgreSQL + hosted Redis so you don't have to run Docker.
### A) Hosted Postgres (example: Neon)
1. Create a Neon account and a new project.
2. Copy the connection string (it looks like `postgresql://...`).
3. Put it into `apps/api/.env` as `DATABASE_URL=...`
4. Push the schema:
```bash
yarn db:push
```
### B) Hosted Redis (example: Upstash)
1. Create an Upstash Redis database.
2. Copy the Redis URL (it looks like `rediss://...`).
3. Put it into `apps/api/.env` as `REDIS_URL=...`
### C) When deploying (GitHub + Vercel)
1. Push this repo to GitHub.
2. Import it into Vercel.
3. In Vercel Project Settings -> Environment Variables, add:
- `VITE_API_URL` (your deployed API base URL, e.g. `https://YOUR-API.onrender.com` or `https://YOUR-API.onrender.com/api`)
4. In your API host (Render/Railway/etc) Environment Variables, add:
- `DATABASE_URL` (hosted Postgres connection string)
- `REDIS_URL` (hosted Redis connection string)
## Deploy the API to Render (fix for missing `dist/index.js`)
If you deploy the API to Render and see:
`Error: Cannot find module '/opt/render/project/src/apps/api/dist/index.js'`
It means Render is trying to start a **compiled** build (`dist/index.js`) that doesn’t exist.
### Recommended Render settings (API service)
In Render → New → Web Service:
- **Root Directory**: (leave empty) → deploy from repo root
- **Build Command**: `yarn workspace @cba/api build`
- **Start Command**: `yarn start:api`
This builds Prisma client and starts the API directly from TypeScript using `tsx` (so there is no `dist/` requirement).
If you want to deploy only the API folder instead:
- **Root Directory**: `apps/api`
- **Build Command**: `yarn build`
- **Start Command**: `yarn start`
## Payments (Aspfiy bank transfer topups)
This project supports buying credits via **Aspfiy reserved account** (Nigeria bank transfer).
### 1) Server env vars (Render)
Add these to your API service environment:
- `ASPFIY_SECRET_KEY` (from your Aspfiy dashboard)
- `API_PUBLIC_URL` (your Render URL, e.g. `https://YOUR-API.onrender.com`)
- `ASPFIY_NGN_PER_CREDIT` (default `10` → ₦10 = 1 credit)
### 2) Database update (one-time)
Payments add two Prisma models (`PaymentAccount`, `PaymentEvent`), so run:
```bash
yarn db:push
```
Then redeploy the API.
### 3) Use it in the app
Go to Dashboard → Billing → **Generate bank account**.
Aspfiy will send payment webhooks to:
`/api/billing/aspfiy/webhook`
## Admin: create your first admin account
### Option A (recommended): seed the admin in the database
1. Put these into `apps/api/.env` (or just export them in your terminal):
- `ADMIN_EMAIL`
- `ADMIN_PASSWORD`
- `ADMIN_NAME` (optional)
2. Make sure `DATABASE_URL` points to the same online Postgres you deployed.
3. Run:
```bash
cmd /c yarn workspace @cba/api db:seed
```
Then login at `/admin/login`.
## Sync schemas (Prisma) to your online database
If you changed `apps/api/prisma/schema.prisma` and want the online DB to match:
1. Make sure your `apps/api/.env` has the **online** `DATABASE_URL`.
2. Run:
```bash
cmd /c yarn db:push
```
This updates tables to match your Prisma schema (MVP-friendly).
### Option B: bootstrap endpoint (dev only, or secret in production)
There is a bootstrap endpoint:
- `POST /api/admin/create`
In production it requires:
- Header `x-admin-bootstrap-secret` matching `ADMIN_BOOTSTRAP_SECRET` on the server.
## 5) Run the app
In one terminal:
```bash
yarn dev
```
API: `http://localhost:8787/api/health`
Web: `http://localhost:5173`
In another terminal (optional, for scheduled/async jobs):
```bash
yarn worker
```
## External APIs (How to get keys)
### CoinGecko (Crypto module)
This MVP uses CoinGecko's public endpoints for basic pricing (no API key required). If you move to CoinGecko Pro later, set `COINGECKO_API_KEY` in `apps/api/.env`.
### Telegram Bot API (Chat delivery)
1. In Telegram, message **@BotFather**
2. Create a new bot -> copy the bot token
3. Start a chat with your bot (or add it to a group)
4. Get your chat ID (quick method: use a bot like **@userinfobot**, or implement a "getUpdates" helper)
5. Put the values into the dashboard Connections page (stored locally in DB for MVP)
### WhatsApp delivery (MVP options)
WhatsApp Cloud API requires Meta setup (business + phone number). This repo includes a Twilio WhatsApp sender option:
1. Create a Twilio account
2. Enable WhatsApp sandbox / WhatsApp sender
3. Set `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_WHATSAPP_FROM` (like `whatsapp:+14155238886`)
4. Provide the destination number in module/automation delivery config
## Database notes
This MVP uses PostgreSQL via Prisma:
- Schema: `apps/api/prisma/schema.prisma`
- Client: `@prisma/client`
## Windows Prisma EPERM (fix)
If you see this during `yarn workspace @cba/api build` / `prisma generate`:
`EPERM: operation not permitted, rename ...query_engine-windows.dll.node.tmp... -> ...query_engine-windows.dll.node`
It usually means the Prisma engine is locked by a running Node process (API/worker) or antivirus.
Fix steps:
1. Stop any running API/worker terminals (`yarn dev`, `yarn dev:api`, `yarn worker`).
2. Close any editor extensions that run the API in the background.
3. Delete the temp engine files:
- `node_modules/.prisma/client/query_engine-windows.dll.node.tmp*`
4. Re-run:
- `cmd /c yarn workspace @cba/api prisma:generate`
- then `cmd /c yarn workspace @cba/api build`
If it still happens, restart your PC (the lock can persist) and try again.