npm package: @mostajs/ornetadmin
Description: Administration interface for @mostajs/orm (13 SGBD) and @mostajs/net (11+ protocols) — standalone or embedded in mosta-setup-studio
Author: Dr Hamid MADANI
Latest version: 1.0.1

# MostaOrNetAdmin

> **Administration interface for @mostajs/orm + @mostajs/net** — manage 13 databases, 11+ protocols, and API keys from a single UI.

[![npm version](https://img.shields.io/npm/v/@mostajs/ornetadmin.svg)](https://www.npmjs.com/package/@mostajs/ornetadmin)
[![license](https://img.shields.io/npm/l/@mostajs/ornetadmin.svg)](LICENSE)

---

## What is OrNetAdmin?

OrNetAdmin is the **configuration writer** for the @mostajs ecosystem. It writes `.env.local` and `.mosta/apikeys.json` files that @mostajs/orm and @mostajs/net read at runtime.

```
@mostajs/ornetadmin (WRITES config)
    │
    ├─ .env.local                    ← SGBD connections, transport toggles, admin credentials
    ├─ .mosta/apikeys.json           ← API key subscriptions with 3D permissions
    │
    ├─► @mostajs/orm (READS .env.local)     → connects to databases
    └─► @mostajs/net (READS .env.local + apikeys.json) → exposes transports

ornetadmin has ZERO peer dependencies on orm or net.
```

---

## Features

- **Dual mode** — standalone server (`npx @mostajs/ornetadmin`) or embedded in mosta-setup-studio
- **13 SGBD connections** — configure, test, remove database URIs
- **11+ transport toggles** — enable/disable REST, GraphQL, WebSocket, SSE, etc.
- **API key management** — generate, revoke, manage 3D permission matrix (key x SGBD x protocol)
- **Login with JWT** — bcrypt authentication, 8h token expiration
- **Import/Export** — download/upload configuration as JSON
- **Web UI** — inline HTML admin dashboard (no React dependency for standalone mode)

---

## Quick Start

### Standalone mode

```bash
npx @mostajs/ornetadmin
# Opens http://localhost:4489/
```

### Embedded in your app (Fastify plugin)

```typescript
import { ornetadminPlugin } from '@mostajs/ornetadmin'
import Fastify from 'fastify'

const app = Fastify()
await app.register(ornetadminPlugin, { prefix: '/admin' })
await app.listen({ port: 3000 })
// Admin UI at http://localhost:3000/admin/
```

---

## Configuration Files

### .env.local (shared contract)

```bash
# ── SGBD connections (read by @mostajs/orm) ──
DB_DIALECT=postgres
SGBD_URI=postgresql://user:pass@localhost:5432/mydb

# ── Hibernate-style properties ──
DB_SHOW_SQL=true
DB_FORMAT_SQL=true
DB_HIGHLIGHT_SQL=true
DB_SCHEMA_STRATEGY=update
DB_POOL_SIZE=20

# ── Transport toggles (read by @mostajs/net) ──
MOSTA_NET_REST_ENABLED=true
MOSTA_NET_GRAPHQL_ENABLED=true
MOSTA_NET_WS_ENABLED=true
MOSTA_NET_SSE_ENABLED=true
MOSTA_NET_MCP_ENABLED=true

# ── Admin credentials ──
MOSTA_ADMIN_PASSWORD_HASH=$2b$12$...    # bcrypt hash
MOSTA_ADMIN_JWT_SECRET=your-secret
```

### .mosta/apikeys.json

```json
{
  "subscriptions": [
    {
      "name": "My App",
      "keyHash": "$2b$12$...",
      "mode": "live",
      "status": "active",
      "permissions": {
        "postgres": { "rest": ["read", "crud"], "graphql": ["read"] },
        "mongodb": { "rest": ["read"] }
      }
    }
  ]
}
```

---

## Admin Pages

| Page | Description |
|------|-------------|
| **Login** | bcrypt + JWT authentication |
| **Dashboard** | Summary: configured SGBD, active transports, API keys |
| **Connections** | Manage 13 SGBD URIs — configure, test ping, remove |
| **Transports** | Toggle 11+ protocols — enable/disable, configure ports |
| **API Keys** | CRUD subscriptions — generate/revoke keys, 3D permission matrix |
| **Import/Export** | Download/upload .env.local + apikeys.json as JSON |

---

## Architecture

```
┌─────────────────────┐
│  @mostajs/ornetadmin │ ← Standalone admin server (port 4489)
│  (WRITES config)     │    or embedded Fastify plugin
└──────┬──────────────┘
       │ writes
       ▼
┌──────────────┐     ┌──────────────────┐
│  .env.local  │     │ .mosta/apikeys   │
└──────┬───────┘     └──────┬───────────┘
       │ reads              │ reads
       ▼                    ▼
┌──────────────┐     ┌──────────────────┐
│ @mostajs/orm │     │  @mostajs/net    │
│ (13 SGBD)    │     │ (11+ protocols)  │
└──────────────┘     └──────────────────┘
```

**Zero dependency** — ornetadmin doesn't import orm or net. It only writes configuration files.

---

## CLI Commands

| Command | Description |
|---------|-------------|
| `npx @mostajs/ornetadmin` | Start standalone admin server |
| `npx @mostajs/ornetadmin init` | Initialize .env.local with defaults |
| `npx @mostajs/ornetadmin hash-password <pw>` | Generate bcrypt hash for admin password |

---

## Ecosystem

| Package | Role | Verb |
|---------|------|------|
| **@mostajs/orm** | Store data | 13 SGBD dialects |
| **@mostajs/net** | Expose data | 11+ protocol transports |
| **@mostajs/ornetadmin** | Manage config | Admin UI + config writer |
| @mostajs/setup | Install apps | Setup wizard + seeds |
| @mostajs/auth | Secure access | NextAuth integration |
| @mostajs/audit | Trace actions | Audit logging |
| @mostajs/init | Generate code | Scaffolding CLI |
| @mostajs/ui | Display UI | 80+ React components |

---

## License

MIT — © 2025-2026 Dr Hamid MADANI <drmdh@msn.com>

## Contributing

Issues and PRs welcome at [github.com/apolocine/mosta-ornetadmin](https://github.com/apolocine/mosta-ornetadmin).