3.2 KiB
3.2 KiB
Architecture
Goals
- Production-oriented structure instead of a demo-only MVP
- Strict backend authorization for every data/schema action
- Safe SQL execution with explicit policy checks
- Clean separation between UI, API, and persistence concerns
- Deployable through Docker Compose and extensible toward Kubernetes
High-level design
Backend
Layered Node.js/Express application:
routesexpose HTTP endpointscontrollerstranslate HTTP into service callsservicescontain business logic and authorization-aware workflowsrepositoriestalk to PostgreSQL metadata/business tablesmiddlewarehandles auth, sessions, RBAC context, validation, errorsdbcontains application pool and SQL bootstrap migrations
Two PostgreSQL access modes are used:
- Application database access for auth, RBAC, audit, and metadata.
- Controlled administrative SQL access for schema/data operations against managed tables.
Frontend
SPA with modular vanilla JavaScript:
pagesassemble route-level screenscomponentsprovide reusable UI blocksapiisolates HTTP communicationstyleskeeps tokens/layout/components separated
This keeps the UI light while preserving clean boundaries. It can later be migrated to React/Vue without backend changes.
Request flow
- Session-authenticated user calls API.
- Auth middleware loads session user.
- Permission middleware resolves table group and required action.
- Service validates identifiers and allowed SQL patterns.
- Repository or admin-query utility executes parameterized SQL.
- Audit service stores action metadata and outcome.
- Structured response is returned to frontend.
RBAC model
Core entities:
usersrolespermissionsrole_permissionsuser_rolestable_groupstable_group_tables
Permission key shape:
- resource:
group,table,sql_console,logs,users,roles,audit - action:
read,write,delete,schema,execute
Built-in model:
root: unrestrictedgroup_admin: scoped by assigned table groups, can manage schema/data per granted actionsviewer/editor: least-privilege table access
Security model
express-sessionwith secure cookie settings- password hashing with
bcrypt helmet, CORS allowlist, request size limitszodvalidation for request payloads- identifier allowlisting and quoting for schema/table/column names
- parameterized queries for data paths
- SQL console denylist for dangerous statements and optional read-only mode by role
- audit log for auth, SQL, DML, DDL
- rate limiting for auth and console routes
Scalability
- Stateless API except for shared session store abstraction
- Service/repository boundaries allow splitting modules later
- Docker-ready and twelve-factor env configuration
- Easy switch from in-memory session store to Redis/Postgres-backed store
- API can be horizontally scaled behind a reverse proxy
Production improvements to add next
- Redis session store
- background jobs for heavy exports/imports
- row-level policies / policy engine
- WebSocket query progress / tailing logs
- metrics (
/metrics) with Prometheus - OpenTelemetry tracing
- optimistic UI with saved query tabs
- soft approvals for risky DDL actions