This document is intended for AI coding assistants, open-source contributors, maintainers, and developers to rapidly understand the core architecture, design patterns, and context of the Supabase Manager project.
This project is a monolithic Next.js 15 (App Router) application that serves both the aesthetically pleasing Frontend Dashboard and the intensive Backend API routes executing host system-level operations.
- Frontend: Next.js (React Server & Client Components), Tailwind CSS v4, shadcn/ui components, Radix/Lucide icons, Recharts for monitoring gauges.
- Backend: Next.js API Routes (Node.js runtime environment).
- Database: SQLite3 (
management.db) for storing admin credentials, project configurations (Web Hosting), and user settings. - Real-time Server: Custom Node.js HTTP Server running Socket.io alongside Next.js to broadcast real-time events (handling the Web Terminal emulator sessions).
- Process Manager: PM2 for daemonizing the production application and ensuring uptime.
supabase_manager/
├── server.js # Custom Next.js Bootstrapper (Attaches Socket.IO to HTTP server)
├── package.json # Core dependencies (Auto-updated via CI/CD Github tags)
├── management.db # SQLite database file (auto-generated on spin-up)
├── src/
│ ├── components/ # Reusable React UI Components (shadcn/ui, Layouts, etc.)
│ ├── lib/ # Shared backend library helpers
│ │ ├── auth.ts # JWT, Session handling, hashed password logic (SHA-256)
│ │ ├── db.ts # SQLite wrapper (`dbGet`, `dbRun`, `getSetting`, DB migrations)
│ │ └── docker.ts # dockerode instance initiator mapping to /var/run/docker.sock
│ │
│ ├── middleware.ts # 🛡️ GLOBAL SECURITY: JWT & API Key Validator protecting API & UI
│ │
│ ├── app/
│ │ ├── api/ # 🟢 BACKEND: Node.js API Endpoints (Middleware protected)
│ │ │ ├── auth/ # Login/Logout controller. Checks SQLite credentials.
│ │ │ ├── backup/ # Scripts to execute pg_dump locally and tar zip volumes
│ │ │ ├── docker/ # Interacts with local Docker Daemon (List, Logs, Volumes parsing)
│ │ │ ├── files/ # Host OS File Manager API (CRUD file ops securely mapping to a ROOT path)
│ │ │ ├── hosting/ # 🌐 Web Hosting Deployer (GitHub release fetcher & tarball extractor)
│ │ │ ├── network/ # Port scanning utilizing `ss -tuln` output.
│ │ │ ├── settings/ # GET/POST configs to SQLite `settings` table.
│ │ │ └── system/ # Cron jobs setup(`crontab -l`), PM2 status(`pm2 jlist`), Update module, NGINX control.
│ │ │
│ │ ├── dashboard/ # 🔵 FRONTEND: UI Components & Next.js Pages
│ │ │ ├── layout.tsx # Global Sidebar Navigation Frame
│ │ │ ├── page.tsx # Main Live Dashboard (Gauges & Stats for OS + Docker status)
│ │ │ ├── backup/ # Backup Tables & Restore Actions UI
│ │ │ ├── containers/ # Docker Containers Live Monitor UI
│ │ │ ├── cron/ # UI to add/remove Cron Jobs directly into OS
│ │ │ ├── files/ # The Web File Explorer component (@cubone UI)
│ │ │ ├── hosting/ # Project manager + Deployment panel for Web Hosting integration
│ │ │ ├── settings/ # Admin config UI (Reset password, root path toggles)
│ │ │ ├── shell/ # Xterm.js Browser Terminal emulator connected to socket.io
│ │ │ └── update/ # Software updater UI interfacing with GitHub Releases
│ │ │
│ │ └── login/ # Unauthenticated Landing Page form
The security of this application centers around preventing unauthorized access to the massive system-level APIs it controls.
- Pre-Seeded Database: When the server boots and loads
src/lib/db.ts, it automatically attempts to create.sqlitetables (users,settings,hosting_projects). If empty, an admin user (admin/admin) is generated and hashed via SHA-256. - Login Attempt: User logs in via
/login-> hits/api/auth/login. Verified against the SQLiteuserstable. - Session Cookie: If valid, an HTTP-only, Lax JWT Cookie (
session) is crafted usingjosewithHS256lasting 7 days. - Middleware Protection:
src/middleware.tsintercepts EVERY request going to/dashboard/*and/api/*(excluding/api/auth). - API Bypass keys (Cron Jobs): Background daemons or
curlcalls can bypass JWT protection by sending anx-api-keyheader mapped strictly to the.env'sCRON_SECRET.
- Database: Tracks project names, domains, and GitHub repository links in SQLite.
- Deploy Trigger:
/api/hosting/deployconnects to GitHub's raw API (with Optional Auth for Private Repos), downloads.tar.gzpayload of a tagged release, extracts it natively usingtar --strip-components=1, and plops it directly into the mapped destination web folder root. - NGINX Symlink Generator: Creates standard SPA routing configurations and saves them temporarily to
/tmp/project.conf. The generator embeds a globalinclude snippets/supabase-proxy.conf;directive explicitly mapping Supabase APIs (Auth, Rest, Realtime, Storage, Functions, Vector) silently under standard ports (80/443). - Execution: For strict security, the Host OS does NOT execute
sudo mvautonomously anymore. Instead, it returns the generated commands arrays back to the Next.js Frontend UI (/dashboard/hosting), instructing the user to paste them in the terminal manually.
- Continuous Integration: When a developer tags a commit on GitHub,
release.ymlnaturally creates an application bundlebuild.tar.gz. - System Action:
/api/system/updateallows the dashboard UI to pull down its own latest build, unpack it entirely over the operating tree, runsnpm install --omit=devto bind fresh native drivers likesqlite3natively to the host OS C++ libraries, and systematically signalspm2 reloadto restart itself.
Located in /api/docker. Relies strictly on the UNIX socket /var/run/docker.sock to interface with the host daemon. It bypasses bash CLI entirely to provide real JSON responses for Container lifecycle states, memory usage, and precise Volumes mapping.
- Container Inspector: Exposes
container.inspect()natively to allow fetching Environment Variables, Network configurations, and mapped Bind Mounts accurately mapping into the Frontend UI without manual bash querying.
- Backend Component:
server.jsoverrides Next's native server initiation, instantiatingSocket.IO. It spawns a raw bash binary locally via thenode-ptynative extension (pseudo-terminal). This ties the bash's raw output strictly to the websocket room. - Frontend Component:
/dashboard/shellusesxterm.jsto render GUI interactive bash sessions natively.
The goal of the File manager is to visually represent areas of the Host OS, constrained to a predefined environment for security.
- Path Traversal Protection: To mitigate directory traversal (
..payload escapes),/api/files/route.tsruns a rigorousresolveSafePath()helper mapping back toFILE_MANAGER_ROOTin SQLite. Failure throws a hard 403.
Consolidates Supabase administration into a unified interface, tracking the base SUPABASE_PROJECT_PATH.
- Component Controller: Automates updating the
docker-compose.ymlimage tags natively via regex replacements and executes standard pull/up operations seamlessly. Includes a web-based Monaco editor to safely rewrite.envwithout nano/vim. - Edge Functions Releases: A dedicated sub-module acting as a CD (Continuous Deployment) listener. It utilizes a
SUPABASE_FUNCTIONS_PATstored securely in the database to ingestfunctions.zipassets remotely compiled on GitHub Private Repositories. It automatically unzips the binaries straight into the volume host mounts and orchestrates instantaneousedge-runtimecontainer restarts.
Provides a graphical and systematic approach to managing Supabase PostgreSQL schema migrations and seeds.
- Artifact-Based Migrations: Strictly fetches
database.zipartifacts from GitHub Releases (explicitly filtering outfunctions.zipto prevent user error). This ties Database Schema safely to Function CI releases. - Native State Synchronization: Replicates the native
supabase db pushorchestration by injecting the original Go implementation's SQL to instantiate and insert records intosupabase_migrations.schema_migrations, maintaining 100% interoperability with the official Supabase CLI. It automatically compares these states to visually flag "Pending" or "Applied" updates. - Secure Encoding Execution: Mitigates Windows Docker Pipe encoding bugs (e.g., Thai character corruption) by relying on
docker cpto transit SQL artifacts. Includes robust "Drop Public Schema" actions that safely wipe the tracking schema alongside the public environment to prevent devastating state desynchronization.
- Role Based Access Control (RBAC): Currently, only a single "Admin" tier exists via
id=1. There is no concept of viewers vs. editors. - Localization (i18n): Expanding structural hooks for multiple language supports like Thai, Spanish, etc.