Standard Operating Procedures
Overview
This document defines Standard Operating Procedures for HASSAR.AI — a B2B smart home intelligence platform. These procedures govern day-to-day operation, monitoring, incident response, and maintenance for system administrators and operations staff.
These SOPs apply to: Frontend application (Next.js 16, hosted on Cloudflare) · Backend API (FastAPI, hosted on Railway) · PostgreSQL database (Railway managed) · AI services (AGIM external, Ollama local)
System Architecture
| Component | Technology | Hosting |
|---|---|---|
| Frontend | Next.js 16 + React 19 + Tailwind CSS 4 | Cloudflare |
| Backend API | FastAPI (Python) | Railway |
| Database | PostgreSQL | Railway (managed) |
| Primary AI | AGIM (Agentic Intelligence Manager) | External service |
| Fallback AI | Ollama | Local / self-hosted |
| Auth | JWT (access 30 min + refresh 7 days) | Backend |
| Blueprint Encryption | AES-256-GCM, PBKDF2-SHA256 | Client-side only |
- User submits credentials to
POST /auth/login - Backend verifies credentials, issues JWT access token (30 min) + refresh token (7 days httpOnly cookie)
- Frontend stores access token in
sessionStorage - All API requests include
Authorization: Bearer <token>header - On 401, frontend calls
POST /auth/refreshto get new access token
Deployment & Environment Setup
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection string |
SECRET_KEY | JWT signing secret (minimum 32 chars, random) |
APP_ENV | production, staging, or development |
AGIM URL/Key and Ollama URL/Model are managed through System Admin → AI Config and stored in the database. No hardcoded environment variables needed for AI config.
| Variable | Description |
|---|---|
NEXT_PUBLIC_API_URL | Backend API base URL |
- Merge feature branch into
mainvia Pull Request. - Railway auto-deploys on push to
main. - Verify deployment in Railway dashboard — check build logs.
- Smoke test:
GET /health→{"status": "ok"}; login with test credentials. - Monitor error logs for 10 minutes post-deployment.
Backend: In Railway dashboard → Deployments tab → select previous successful deployment → Redeploy.
Frontend: In Cloudflare dashboard → select previous deployment → Promote to Production.
User Account Management
- Log in as an existing admin.
- Navigate to System Admin → Users.
- Find the target user account.
- Click Promote to Admin and confirm.
Emergency (database direct):
UPDATE users SET role = 'admin' WHERE email = 'user@example.com';
Navigate to System Admin → Users, select the user, click Delete Account, and confirm.
- Generate a bcrypt hash for a temporary password:
import bcrypt hash = bcrypt.hashpw(b"TempPassword123!", bcrypt.gensalt()).decode() print(hash) - Update the database:
UPDATE users SET password_hash = '<hash>' WHERE email = 'user@example.com'; - Communicate the temporary password via secure channel; instruct user to change it immediately.
| Role | Capabilities |
|---|---|
| user | My IoT Blueprint, Talk to Jim, own profile |
| admin | All user capabilities + System Admin panel (user management, logs, AI config) |
Blueprint Operations
- Created — user completes 5-step wizard in Blueprint Hub
- Encrypted — user enters passphrase; AES-256-GCM encryption applied client-side
- Exported —
.hassarfile downloaded to user's device - Used — uploaded to Jim chat or Review Existing Blueprint for inspection
- Archived — user retains the file; no server-side storage
- Inform the user that recovery is not possible.
- Guide the user to recreate the blueprint using the 5-step wizard.
- Remind the user to store the new passphrase securely (e.g. password manager).
AI Service Management
| Tier | Service | Condition |
|---|---|---|
| Primary | AGIM (Agentic Intelligence Manager) | Default for all production AI requests |
| Fallback | Ollama (local) | Automatic fallback if AGIM is unavailable |
- Navigate to System Admin → AI Config.
- Update: AGIM URL · AGIM API Key · Ollama URL · Ollama Model.
- Click Save. Changes apply immediately to new AI requests.
| Task | Command |
|---|---|
| Start Ollama | ollama serve |
| Pull a model | ollama pull llama3.2 |
| List available models | ollama list |
| Check running models | ollama ps |
- Check System Admin → Logs for AI-related errors.
- Verify AGIM service is reachable from the backend server.
- Verify Ollama is running:
curl http://localhost:11434/api/tags - Check AI Config — verify API keys and endpoints are correctly set.
- Test with a simple query through the chat interface.
- If unresolved, escalate to Level 2 (see Escalation Matrix).
System Monitoring & Logs
GET /health
Response: {"status": "ok"}
Monitor every 60 seconds. Alert on non-200 responses or response time > 5 seconds.
Navigate to System Admin → Logs. The log table shows timestamp, log level, and message for recent system events.
| Level | Meaning | Action Required |
|---|---|---|
| INFO | Normal operation | No action required |
| WARNING | Unusual but non-critical event | Monitor; investigate if recurring |
| ERROR | Operation failed | Investigate immediately |
| Metric | Target | Alert Threshold |
|---|---|---|
| API response time (p95) | < 500 ms | > 2000 ms |
| Error rate | < 1% | > 5% |
| AI request success rate | > 95% | < 80% |
| Database connection pool | < 80% used | > 95% used |
Incident Response
| Level | Description | Response Time |
|---|---|---|
| P1 Critical | Platform completely unavailable | 15 minutes |
| P2 High | Major feature broken (login, blueprints, AI) | 1 hour |
| P3 Medium | Minor feature degraded | 4 hours |
| P4 Low | Cosmetic issues, minor bugs | Next business day |
- Detect: Uptime monitor alerts or multiple user reports.
- Acknowledge: Assign incident owner within 15 minutes.
- Assess: Check Railway/Cloudflare dashboards. Check database status.
- Communicate: Post status update to stakeholders.
- Mitigate: Roll back most recent deployment if outage followed a deploy.
- Verify: Confirm
/healthreturns 200 and core flows work. - Post-mortem: Document root cause within 24 hours.
- Check system logs for AI error messages.
- Check AGIM service status.
- Verify Ollama fallback is working.
- If both failing, check AI Config for misconfiguration.
- Escalate to AGIM support if AGIM is confirmed down.
- Check system logs for AUTH event errors.
- Verify
SECRET_KEYenvironment variable is set. - Check database connectivity.
- If JWT secret was rotated, all sessions are invalidated — users must log in again.
Backup & Recovery
Railway automatic backups: Verify daily automated backups are enabled in Railway project settings.
Manual backup:
pg_dump $DATABASE_URL > backup_$(date +%Y%m%d).sql
Store backups off-platform (e.g. encrypted S3 bucket). Minimum retention: 30 days.
psql $DATABASE_URL < backup_YYYYMMDD.sql
Test restores quarterly in a non-production environment.
Blueprint files (stored locally by users) · Chat history (stored in user browsers) · Blueprint passphrases (never stored anywhere).
- Provision new Railway project with PostgreSQL.
- Restore database from latest backup.
- Set all environment variables (see Section 3).
- Deploy backend and frontend from
mainbranch. - Verify all services operational.
RTO: 4 hours · RPO: 24 hours
Security Procedures
JWT Secret Key
- Generate new secret:
openssl rand -hex 32 - Update
SECRET_KEYin Railway environment variables. - Redeploy backend. All existing sessions will be invalidated.
AGIM API Key
- Rotate key in AGIM dashboard.
- Update in System Admin → AI Config.
- Immediately rotate all secrets (JWT, AGIM API key, database password).
- Invalidate all sessions (JWT secret rotation achieves this).
- Review system logs for AUTH events to identify affected accounts.
- Notify affected users.
- Preserve logs for forensic investigation.
- Navigate to System Admin → Users.
- Filter by Role = admin.
- Remove admin privileges from accounts that no longer require them.
Maintenance Schedules
| Cadence | Tasks |
|---|---|
| Daily | Verify uptime · Review ERROR-level logs · Check Railway dashboard |
| Weekly | Review WARNING-level logs · Check AI request success rates · Verify DB backup completed |
| Monthly | Review AGIM API usage · Check Ollama model version |
| Quarterly | DB restore test · Rotate JWT secret · Review admin account list · DR walkthrough |
| Annually | Full security audit · Dependency and platform version review · SOP review |