Overview
GrowthPilot AI is an enterprise-grade AI-powered business growth platform built for multi-tenant SaaS delivery. It features a 60+ table PostgreSQL schema managed through Supabase, with Row Level Security enforcing strict data isolation between tenants. The platform integrates Python ML pipelines for predictive analytics and growth recommendations, serving real-time dashboards to users across 11 distinct RBAC roles.
Problem Statement
Growing businesses need data-driven insights but lack the engineering resources to build custom analytics platforms. Existing solutions either lack multi-tenancy support or require significant configuration. The challenge was building a platform that provides enterprise-grade data isolation while remaining accessible to teams of varying technical expertise, all while serving AI-powered recommendations in real time.
Architecture Overview
The system follows a layered architecture: Next.js App Router for the frontend with server components for initial data fetching, Supabase as the backend-as-a-service layer providing authentication, real-time subscriptions, and PostgreSQL with RLS policies. Python microservices handle ML model training and inference, communicating via a message queue. Docker containers ensure consistent deployment across environments.
Tech Stack
Key Features
Multi-Tenant Architecture
Complete data isolation using Supabase Row Level Security with tenant-scoped policies across all 60+ tables
11-Role RBAC System
Granular permission system supporting roles from platform admin to read-only viewer with hierarchical inheritance
AI-Powered Analytics
Python ML pipelines generating growth predictions, churn risk scores, and revenue forecasting
Real-Time Dashboards
Live-updating metrics using Supabase real-time subscriptions with optimistic UI updates
Screenshots
Engineering Challenges
Row Level Security at scale with 60+ tables
Developed a policy generation script that creates consistent RLS policies across all tables, with automated tests verifying tenant isolation using cross-tenant query attempts
Multi-tenant data isolation during ML training
Implemented a tenant-aware data pipeline that trains shared models on anonymized aggregate data while generating tenant-specific predictions using isolated feature stores
Real-time dashboard performance with complex queries
Introduced materialized views refreshed on a schedule for aggregate metrics, with real-time subscriptions only for delta updates to minimize database load
-- Row Level Security policy for tenant isolation
CREATE POLICY "tenant_isolation" ON analytics_events
FOR ALL USING (
tenant_id = (
SELECT tenant_id FROM profiles
WHERE id = auth.uid()
)
);export function withRole(allowedRoles: Role[]) {
return async (req: NextRequest) => {
const session = await getSession(req);
const userRole = await getUserRole(session.user.id);
if (!allowedRoles.includes(userRole)) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
};
}Testing Strategy
The testing strategy includes a 42-test API smoke suite covering all critical endpoints, integration tests for the complete auth flow including multi-tenant isolation verification, and end-to-end tests for the ML pipeline from data ingestion through prediction delivery. RLS policies are tested by attempting cross-tenant access patterns.
Deployment
The application is deployed using Docker containers with Supabase Cloud for the database and auth layer, and a separate Python service deployed via Docker. GitHub Actions handles CI/CD with automated testing gates, database migration verification, and staged rollouts.
Lessons Learned
- RLS policies should be designed and tested before building features — retrofitting is exponentially harder
- Materialized views are essential for multi-tenant analytics performance but require careful refresh scheduling
- Type-safe database queries with generated types from Supabase catch schema drift early in development
- ML model serving latency matters more than accuracy improvements beyond a threshold for user experience