/home/techb158/balavpn.abdallabala.com/docs
Edit: /home/techb158/balavpn.abdallabala.com/docs/31-saas-rebuild-implementation.md (2571B)
# COSMIC AI-Risk SaaS Rebuild Implementation
Date: 2026-07-05
## What was added
The commercial SaaS rebuild now starts in:
```text
saas-app/
```
The frozen academic prototype remains unchanged and acts as the reference implementation.
## SaaS foundation
The new app includes:
- Next.js application scaffold.
- PostgreSQL and Prisma schema.
- Docker Compose deployment for VPS.
- Organization and workspace tenancy.
- User, role, membership, and invitation models.
- Subscription and entitlement models for manual pilot billing and Stripe.
- COSMIC risk scoring and deployment gate domain services.
- Tenant-aware service layer for projects, risks, mitigations, gates, reports, and audit.
- API route contracts for auth, organizations, workspaces, projects, risks, mitigations, gates, reports, integrations, and billing.
- Seed importer from the current `data/database.json`.
- Domain and tenant-security tests that run without external services.
## Current implementation boundary
This is a SaaS foundation, not a finished production launch.
Completed now:
- Multi-tenant data model.
- PostgreSQL migration target.
- Domain logic port.
- First API route layer.
- First dashboard shell.
- Manual billing and Stripe boundaries.
- Invite-only auth contracts.
- Docker/VPS deployment shape.
Still required before commercial production:
- Install dependencies and generate a lockfile.
- Run Prisma migrations against PostgreSQL.
- Complete session cookie auth and password/magic-link login.
- Complete Stripe checkout, portal, and signed webhook implementation.
- Add full CRUD UI screens beyond the first dashboard shell.
- Add SAML/OIDC SSO.
- Add production monitoring, logging, and backup automation.
- Add legal pages: terms, privacy, security, data processing agreement.
## Recommended next command sequence
```bash
cd saas-app
cp .env.example .env
npm install
docker compose up -d postgres
npm run db:push
npm run db:seed
npm test
npm run dev
```
Open:
```text
http://localhost:8090
```
## Local fallback mode
If npm dependency installation times out, run the dependency-free local harness:
```bash
cd saas-app
npm run test:local
npm run local:fallback
```
Open:
```text
http://localhost:8090
```
This mode does not replace the Next.js and PostgreSQL SaaS target. It exists so the SaaS domain workflows, seeded dashboard, core API routes, reports, gate evaluation, risk CRUD, mitigation management, integrations, billing/admin placeholders, users, invitations, and audit trail can be tested locally while npm/registry access is unavailable.