
Your account could not be loaded.
Generate Your Self-Hosted Config
Fill in your credentials below. Every config file, database schema, Docker setup, and the complete frontend API client replacement will be generated — ready to paste and run on any server.
What gets replaced to remove Base44 dependency
Your Deployment Configuration
Generated Files (Preview & Copy)
This single file replaces the entire @base44/sdk dependency. Copy this over src/api/base44Client.js in your project. All pages continue working unchanged because the exports (base44.entities, base44.auth, base44.functions) are identical — they just point to YOUR server instead of Base44.
// ═══════════════════════════════════════════════════════════════
// LeadZ CRM — Self-Hosted API Client
// FILE: src/api/base44Client.js (overwrite this exact file)
//
// DROP-IN REPLACEMENT for @base44/sdk
// Every method signature is IDENTICAL to Base44 SDK so zero
// changes needed anywhere else in the app.
//
// Points to YOUR self-hosted backend: https://crm.yourdomain.com/api
// ═══════════════════════════════════════════════════════════════
const API_BASE = (typeof import.meta !== 'undefined' && import.meta.env?.VITE_API_URL)
? import.meta.env.VITE_API_URL
: 'https://crm.yourdomain.com/api';
const WS_BASE = API_BASE.replace(/^https/, 'wss').replace(/^http/, 'ws');
// ─── Token helpers (mirrors Base44 SDK internal storage) ──────────
const TOKEN_KEY = 'base44_access_token';
const USER_KEY = 'leadz_user_cache';
function getToken() { return localStorage.getItem(TOKEN_KEY); }
function setToken(t) { localStorage.setItem(TOKEN_KEY, t); }
function clearAuth() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
// Also clear Base44-style keys for clean migration
localStorage.removeItem('leadz_token');
localStorage.removeItem('leadz_user');
}
// ─── Core HTTP helper ─────────────────────────────────────────────
async function req(path, opts = {}) {
const token = getToken();
const isForm = opts.body instanceof FormData;
const headers = {
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(isForm ? {} : { 'Content-Type': 'application/json' }),
...(opts.headers || {}),
};
const res = await fetch(`${API_BASE}${path}`, {
method: opts.method || 'GET',
headers,
body: isForm ? opts.body : (opts.body != null ? JSON.stringify(opts.body) : undefined),
});
if (res.status === 401) {
clearAuth();
window.location.href = '/LeadZLogin';
throw new Error('Session expired — please log in again');
}
const ct = res.headers.get('content-type') || '';
const data = ct.includes('application/json') ? await res.json() : await res.text();
if (!res.ok) {
const msg = (typeof data === 'object' ? data?.error || data?.message : data) || `HTTP ${res.status}`;
throw new Error(msg);
}
return data;
}
// ─── Real-time subscriptions (WebSocket) ─────────────────────────
// Returns unsubscribe function — exactly like Base44 SDK
function makeSubscriber(entityName) {
return function subscribe(callback) {
const token = getToken();
const url = `${WS_BASE}/ws/entities/${entityName}?token=${token || ''}`;
let ws;
let closed = false;
let retryTimer = null;
function connect() {
if (closed) return;
ws = new WebSocket(url);
ws.onmessage = (e) => {
try {
const event = JSON.parse(e.data);
// Normalize to Base44 event shape: { type, id, data }
callback({
type: event.type || event.event_type || 'update',
id: event.id || event.entity_id,
data: event.data || event.record,
});
} catch(_) {}
};
ws.onclose = () => {
if (!closed) retryTimer = setTimeout(connect, 3000);
};
}
connect();
// Return unsubscribe
return () => {
closed = true;
clearTimeout(retryTimer);
ws?.close();
};
};
}
// ─── Entity factory ──────────────────────────────────────────────
// Signatures are IDENTICAL to base44.entities.EntityName.*
function makeEntity(entityName) {
const base = `/entities/${entityName}`;
return {
// base44.entities.Job.list('-updated_date', 20)
list: (sort = '-created_date', limit = 50) =>
req(`${base}?sort=${sort}&limit=${limit}`),
// base44.entities.Job.filter({ status: 'active' }, '-created_date', 10)
filter: (filters = {}, sort = '-created_date', limit = 200) => {
const params = new URLSearchParams({
sort,
limit: String(limit),
filters: JSON.stringify(filters),
});
return req(`${base}?${params}`);
},
// base44.entities.Job.get(id)
get: (id) => req(`${base}/${id}`),
// base44.entities.Job.create({ title: '...' })
create: (data) => req(base, { method: 'POST', body: data }),
// base44.entities.Job.bulkCreate([...])
bulkCreate: (items) => req(`${base}/bulk`, { method: 'POST', body: { items } }),
// base44.entities.Job.update(id, { status: 'done' })
update: (id, data) => req(`${base}/${id}`, { method: 'PATCH', body: data }),
// base44.entities.Job.delete(id)
delete: (id) => req(`${base}/${id}`, { method: 'DELETE' }),
// base44.entities.Job.schema()
schema: () => req(`${base}/schema`),
// base44.entities.Job.subscribe(callback) → returns unsubscribe()
subscribe: makeSubscriber(entityName),
};
}
// ─── Auth ─────────────────────────────────────────────────────────
let _userCache = null;
const auth = {
// base44.auth.me()
me: async () => {
if (_userCache) return _userCache;
const stored = localStorage.getItem(USER_KEY);
if (stored) {
try {
_userCache = JSON.parse(stored);
return _userCache;
} catch(_) {}
}
const user = await req('/auth/me');
_userCache = user;
localStorage.setItem(USER_KEY, JSON.stringify(user));
return user;
},
// base44.auth.isAuthenticated()
isAuthenticated: async () => {
try { await auth.me(); return true; }
catch(_) { return false; }
},
// base44.auth.updateMe(data)
updateMe: async (data) => {
const user = await req('/auth/me', { method: 'PATCH', body: data });
_userCache = user;
localStorage.setItem(USER_KEY, JSON.stringify(user));
return user;
},
// base44.auth.logout(redirectUrl?)
logout: (redirectUrl = '/LeadZLogin') => {
clearAuth();
_userCache = null;
window.location.href = redirectUrl;
},
// base44.auth.redirectToLogin(nextUrl?)
redirectToLogin: (next = '') => {
const url = `/LeadZLogin${next ? '?next=' + encodeURIComponent(next) : ''}`;
window.location.href = url;
},
// Called by LeadZLogin page after successful login
_setToken: (token, user) => {
setToken(token);
_userCache = user;
localStorage.setItem(USER_KEY, JSON.stringify(user));
},
};
// ─── Backend Functions ────────────────────────────────────────────
// base44.functions.invoke('functionName', payload)
// Returns axios-style: { data: result }
const functions = {
invoke: async (name, payload = {}) => {
const result = await req(`/functions/${name}`, { method: 'POST', body: payload });
// Wrap in { data } to match axios response shape used throughout the app
return { data: result };
},
};
// ─── Integrations (Core) ──────────────────────────────────────────
// base44.integrations.Core.InvokeLLM({ prompt, ... })
const integrations = {
Core: {
InvokeLLM: (p) => req('/integrations/llm', { method: 'POST', body: p }),
SendEmail: (p) => req('/integrations/email', { method: 'POST', body: p }),
GenerateImage: (p) => req('/integrations/image', { method: 'POST', body: p }),
ExtractDataFromUploadedFile: (p) => req('/integrations/extract', { method: 'POST', body: p }),
CreateFileSignedUrl: (p) => req('/integrations/signed-url', { method: 'POST', body: p }),
// base44.integrations.Core.UploadFile({ file: File })
UploadFile: async ({ file }) => {
const form = new FormData();
form.append('file', file);
return req('/upload', { method: 'POST', body: form });
},
UploadPrivateFile: async ({ file }) => {
const form = new FormData();
form.append('file', file);
return req('/upload/private', { method: 'POST', body: form });
},
},
};
// ─── Users ────────────────────────────────────────────────────────
const users = {
// base44.users.inviteUser(email, role)
inviteUser: (email, role) =>
req('/auth/invite', { method: 'POST', body: { email, role } }),
};
// ─── Analytics ────────────────────────────────────────────────────
const analytics = {
track: ({ eventName, properties = {} }) =>
req('/analytics/track', { method: 'POST', body: { event: eventName, properties } }).catch(() => {}),
};
// ─── Agents ───────────────────────────────────────────────────────
const agents = {
createConversation: (p) => req('/agents/conversations', { method: 'POST', body: p }),
listConversations: (p) => req(`/agents/conversations?agent_name=${p?.agent_name || ''}`),
getConversation: (id) => req(`/agents/conversations/${id}`),
updateConversation: (id, p) => req(`/agents/conversations/${id}`, { method: 'PATCH', body: p }),
addMessage: (conv, msg) => req(`/agents/conversations/${conv.id}/messages`, { method: 'POST', body: msg }),
subscribeToConversation: (id, cb) => makeSubscriber(`agent_conv_${id}`)(cb),
getWhatsAppConnectURL: (name) => `${API_BASE}/agents/${name}/whatsapp/connect`,
getTelegramConnectURL: (name) => `${API_BASE}/agents/${name}/telegram/connect`,
};
// ─── Connectors (app user connectors) ────────────────────────────
const connectors = {
connectAppUser: (connectorId) =>
req(`/connectors/${connectorId}/connect`, { method: 'POST' }).then(r => r.url),
disconnectAppUser: (connectorId) =>
req(`/connectors/${connectorId}/disconnect`, { method: 'POST' }),
};
// ─── Entity proxy (accessed as base44.entities.AnyEntityName) ─────
const entityProxy = new Proxy({}, {
get: (_, entityName) => {
if (typeof entityName !== 'string') return undefined;
return makeEntity(entityName);
},
});
// ─── asServiceRole (same API, no difference in self-hosted) ──────
const asServiceRole = {
entities: entityProxy,
functions,
integrations,
connectors: {
getConnection: (type) => req(`/connectors/service/${type}`),
getCurrentAppUserConnection: (id) => req(`/connectors/${id}/token`),
},
};
// ═══════════════════════════════════════════════════════════════════
// MAIN EXPORT — identical surface to @base44/sdk createClient()
// ═══════════════════════════════════════════════════════════════════
export const base44 = {
auth,
entities: entityProxy,
functions,
integrations,
users,
analytics,
agents,
connectors,
asServiceRole,
};
export const SDK_VERSION = 'self-hosted-2.0.0';
export const SDK_IMPORT_SOURCE = '@/api/base44Client';
// Expose version for health checks
if (typeof window !== 'undefined') {
window.__BASE44_SDK_VERSION__ = SDK_VERSION;
}
Launch Order — Do This Exactly
- 1
Export data
Click 'Export All Company Data' in SelfHostingGuide page → downloads leadz-export.json
- 2
Get a server
Any Ubuntu 22.04 VPS with 2+ CPU / 4GB RAM (DigitalOcean, Hetzner, AWS EC2, Azure VM)
- 3
Install Docker
curl -fsSL https://get.docker.com | sh && sudo apt install docker-compose-plugin -y
- 4
Upload files
Upload docker-compose.yml, .env, nginx/, db/, frontend/, backend/ to your server
- 5
Apply DB schema
docker compose up postgres -d && docker exec -i postgres psql -U leadz_user leadz_db < db/schema.sql
- 6
Import your data
chmod +x import-data.sh && ./import-data.sh leadz-export.json
- 7
Replace base44Client.js
In your source code: overwrite src/api/base44Client.js with the generated file above
- 8
Build & start
docker compose up -d --build → your CRM is live at https://yourdomain.com
- 9
SSL cert
docker exec nginx certbot --nginx -d yourdomain.com (free Let's Encrypt)
☁️ AWS Quick Reference — After Downloading Files
- 1
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com - 2
docker build -t leadz-crm ./backend && docker tag leadz-crm:latest <ECR_URL>:latest && docker push <ECR_URL>:latest - 3
aws secretsmanager create-secret --name leadz/production --secret-string file://env.json - 4
aws ecs update-service --cluster leadz-cluster --service leadz-api --force-new-deployment - 5
aws ecs wait services-stable --cluster leadz-cluster --services leadz-api
🔷 Azure Quick Reference — After Downloading Files
- 1
az login && az group create --name leadz-rg --location eastus - 2
az acr create --resource-group leadz-rg --name leadzregistry --sku Standard && az acr login --name leadzregistry - 3
az acr build --registry leadzregistry --image leadz-crm:latest ./backend - 4
az postgres flexible-server execute --name leadz-db --admin-user leadz_admin --admin-password "$PASS" --database-name leadz_db --file-path db/schema.sql - 5
az containerapp create --name leadz-api --resource-group leadz-rg --image leadzregistry.azurecr.io/leadz-crm:latest --target-port 8000 --ingress external
Need the Backend API Source Code?
The Deno backend API (which these configs point to) is provided as part of the LeadZ White-Label License. Contact us to get the full self-hostable backend source.
support@lead-z.ca