diff --git a/REUSE_GUIDE.md b/REUSE_GUIDE.md new file mode 100644 index 0000000..29850ac --- /dev/null +++ b/REUSE_GUIDE.md @@ -0,0 +1,265 @@ +# admin.derez.ai — UI Reuse Guide + +Stripped-down version: **Servers page only**. No Sales, no CRM, no API Keys. + +--- + +## 1. UI Architecture (Single HTML File) + +The entire front-end is a **single-page app** in a single `index.html` with: + +| File | Role | +|---|---| +| `index.html` | Full DOM layout: sidebar, sections, modals (login, confirm) | +| `styles.css` | All styles: layout, sidebar, cards, tables, badges, modal, toast, server dashboard | +| `app.js` | State, auth, API helpers, routing, all CRUD for each section | + +The pattern is straightforward — you can keep one file per section or keep it monolithic. The CSS and JS are written in vanilla ES6+ with no build step. + +--- + +## 2. Login & Session (Cookie-Based) + +### How it works + +1. User fills email + password in `#login-modal` (inside `#login-backdrop`). +2. `doSignIn()` POSTs to the auth endpoint with `{ email, password }`. +3. The backend returns an object with a `sessionid` field. +4. The session ID and email are saved in cookies: + - `al_session` — the session token + - `al_email` — the signed-in email + +### On page load + +```js +const _boot = getCookie("al_session"); +if (_boot) { + currentSession = _boot; + currentEmail = getCookie("al_email") || ""; + showApp(); // hides login modal, shows sidebar + loadData(); // loads your default section data +} else { + showAuth(); // shows login modal +} +``` + +### Cookie helpers (already in `app.js`) + +```js +setCookie(name, value, days) // SameSite=Strict +getCookie(name) +deleteCookie(name) +``` + +### API fetch wrapper + +```js +async function apiFetch(url, options = {}) +``` + +- Automatically attaches `X-Session-Id` header from `currentSession`. +- On HTTP 401, deletes cookies, clears local state, and reloads the page (back to login). + +### Sign out + +```js +function doSignOut() +``` + +- Sends a `DELETE` to the auth endpoint with the session ID. +- Deletes cookies (`al_session`, `al_email`). +- Clears `localStorage`. +- Shows the login screen again. + +### What you need to change for a new project + +| Constant / Variable | Change to | +|---|---| +| `const API_BASE` (L2) | Your backend base URL, e.g. `"https://api.yourproject.com/webhook"` | +| `ROUTES.auth` (L6) | Your login endpoint path, e.g. `"/auth/login"` | +| Cookie names `al_session` / `al_email` | Rename to avoid conflicts, e.g. `"myapp_session"` | +| `apiFetch` 401 handler | Customize or keep (auto-redirects to login) | + +--- + +## 3. How Sections Work (Routing) + +### Sidebar navigation + +Each sidebar item in `index.html`: + +```html +
+``` + +The click handler (L175–239 in `app.js`): + +1. Reads `el.dataset.section` → e.g. `"servers"` +2. Toggles `.active` class on the nav item +3. Toggles `.active` class on `#section-servers` +4. Sets the page title from a label map +5. Shows the refresh button +6. Lazy-loads data if empty + +### Corresponding section element + +```html +