Compare commits

...

4 Commits

3 changed files with 423 additions and 2 deletions

View File

@@ -50,7 +50,7 @@ export default async function DashboardPage() {
supabase
.from("plesk_domains")
.select(
"id, plesk_instance_id, subscription_id, domain_name, status, hosting_type, source_created_at, aliases_count, updated_at",
"id, plesk_instance_id, subscription_id, status, domain_name, hosting_type, source_created_at, aliases_count, updated_at, subscription:plesk_subscriptions(status)",
)
.eq("agency_id", context.agencyId)
.order("updated_at", { ascending: false })
@@ -107,6 +107,9 @@ export default async function DashboardPage() {
source_created_at: string | null;
aliases_count: number | null;
updated_at: string;
subscription: {
status: string | null;
} | null;
}> | null;
},
{ data: BillingSummary | null },
@@ -167,7 +170,16 @@ export default async function DashboardPage() {
<DashboardControls
instances={instances ?? []}
subscriptions={subscriptions ?? []}
domains={domains ?? []}
domains={(domains ?? []).map((domain) => {
const joinedStatus = Array.isArray(domain.subscription)
? domain.subscription[0]?.status
: domain.subscription?.status;
return {
...domain,
status: joinedStatus ?? "unknown",
};
})}
autoSyncByInstance={Object.fromEntries(autoSyncByInstance.entries())}
/>
</main>

230
docs/ai-project-context.md Normal file
View File

@@ -0,0 +1,230 @@
# Project: Plesk Agency Portal
This project is a multi-tenant SaaS platform that allows agencies to manage multiple Plesk servers from a single dashboard.
The application synchronizes subscriptions and domains from Plesk instances and allows administrators to manage hosting accounts.
---
# Technology Stack
Frontend
- Next.js (App Router)
- React
- TypeScript
Backend
- Next.js API routes
- Node runtime
Database
- Supabase Postgres
Authentication
- Supabase Auth (magic link)
External Integrations
- Plesk REST API
- Plesk CLI
- Stripe (future billing integration)
Development Tools
- Git
- Docker (for some services)
- Jenkins (future CI/CD)
---
# Core Database Tables
agencies
agency_members
plesk_instances
plesk_subscriptions
plesk_domains
actions_log
billing_accounts
---
# Multi-Tenant Model
Each user belongs to an agency.
Agency relationships:
user
→ agency_members
→ agencies
→ plesk_instances
→ plesk_subscriptions
→ plesk_domains
Row Level Security in Supabase ensures users can only access rows belonging to their agency.
Never bypass or remove RLS policies.
---
# Plesk Integration
The system integrates with Plesk using both:
Plesk REST API
Plesk CLI
Common CLI commands used:
subscription --info
subscription --suspend
subscription --unsuspend
CLI output must always be parsed defensively because formatting can vary between Plesk versions.
---
# Sync System
The platform supports manual synchronization of Plesk instances.
During sync the system:
1. Connects to a Plesk instance
2. Retrieves subscriptions and domains
3. Updates records in Supabase
4. Updates the dashboard
Future development will include background sync workers.
---
# Dashboard Features
Current features include:
Connecting Plesk instances
Testing connections
Manual sync
Listing domains and subscriptions
Suspending subscriptions
Unsuspending subscriptions
---
# Logging
Operational actions are written to:
actions_log
Examples include:
instance_connected
sync_started
sync_completed
subscription_suspended
subscription_unsuspended
Logging should never block primary workflows.
---
# Development Rules
When implementing features:
Search the repository before modifying code.
Extend existing architecture rather than rewriting systems.
Avoid introducing breaking database schema changes.
Prefer small modular functions.
Keep API routes thin.
Place integration logic inside lib folders.
---
# Git Workflow
Default branch:
master
All work must be done on feature branches.
Example:
git checkout master
git pull
git checkout -b feature/<feature-name>
Never commit directly to master.
---
# Error Handling
External integrations must always fail gracefully.
If a single subscription fails during sync, the rest of the sync must continue.
All failures should be logged.
---
# UI Safety
Dashboard components must:
Handle null values safely
Avoid crashing if API responses change
Use status badges instead of raw text for statuses
---
# Future Roadmap
Upcoming development milestones include:
CL4 Subscription status ingestion via CLI
CL5 Action logging and retry queue
CL6 Automatic sync worker
CL7 Stripe billing enforcement
CL8 Instance health monitoring
CL9 Observability and audit improvements
---
# AI Agent Instructions
Before modifying code:
Search the repository for related implementations.
Avoid rewriting working systems.
Implement minimal safe modifications.
Always verify that existing features continue working.
If unsure about a change, prefer logging rather than failing.

179
docs/system-architecture.md Normal file
View File

@@ -0,0 +1,179 @@
# System Architecture
This document describes the architecture of the Plesk Agency Portal SaaS platform.
The platform allows agencies to connect multiple Plesk servers and manage hosting subscriptions from a single dashboard.
---
# High Level Components
The system consists of the following components:
Frontend Dashboard
Backend API
Supabase Database
Plesk Servers
Future Worker Services
Future Billing Integration
At a high level, users interact with the Frontend Dashboard, which sends authenticated requests to the Backend API (Next.js API routes). The backend reads and writes persistent state in Supabase, and executes remote operations against connected Plesk servers via API/CLI integrations. Future worker services will run asynchronous sync and retry workflows, while future billing integration will enforce plan limits and subscription state.
---
# Frontend
The frontend is a Next.js application using the App Router.
Responsibilities include:
User authentication
Dashboard interface
Displaying domains and subscriptions
Triggering sync operations
Sending management actions (suspend / unsuspend)
The frontend communicates with backend API routes.
---
# Backend
The backend uses Next.js API routes.
Responsibilities include:
Handling authenticated requests
Connecting to Supabase
Executing Plesk API and CLI commands
Processing sync operations
Writing operational logs
Business logic should be implemented in reusable modules inside the lib directory.
---
# Database
Supabase Postgres is used for persistent storage.
Key tables include:
agencies
agency_members
plesk_instances
plesk_subscriptions
plesk_domains
actions_log
billing_accounts
Relationship overview:
- `agencies` is the tenant root.
- `agency_members` associates users to agencies and roles.
- `plesk_instances` stores connected remote Plesk endpoints per agency.
- `plesk_subscriptions` stores subscription-level records linked to instances.
- `plesk_domains` stores domain-level records linked to subscriptions/instances.
- `actions_log` stores operational/audit events.
- `billing_accounts` stores plan/subscription billing state per agency.
The multi-tenant model is enforced using Supabase Row Level Security policies so users can only read/write rows that belong to their agency.
---
# Plesk Integration
The platform communicates with remote Plesk servers.
Integration methods:
Plesk REST API
Plesk CLI commands
Typical operations include:
Listing subscriptions
Retrieving domain data
Suspending subscriptions
Unsuspending subscriptions
CLI parsing must be defensive due to formatting differences between Plesk versions.
---
# Sync System
The system supports synchronization of Plesk servers.
Manual sync is triggered from the dashboard.
During sync:
The backend connects to a Plesk instance
Subscription and domain data are retrieved
Records are updated in Supabase
The dashboard displays updated data
Future development will add automated background sync workers.
---
# Logging System
Operational actions are recorded in the actions_log table.
Examples:
instance_connected
sync_started
sync_completed
subscription_suspended
subscription_unsuspended
Logging supports debugging and auditability.
---
# Future Worker Architecture
Future versions of the system will include background workers for:
Automatic instance synchronization
Retry queues
Monitoring tasks
Workers may run as:
Cron jobs
Queue processors
Dedicated worker services
---
# Billing Architecture (Future)
Stripe will be integrated for SaaS billing.
Billing responsibilities will include:
Agency subscription plans
Usage limits
Payment handling
Billing enforcement will eventually control:
Number of connected Plesk instances
Number of managed domains
---
# Development Philosophy
The system prioritizes:
Stability
Security
Multi-tenant isolation
Safe integrations with external systems
Developers should extend existing systems rather than rewriting them.