# emn90909/struta architecture

> Architecture diagram of the GitHub repository emn90909/struta, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emn90909/struta
- Repository: https://github.com/emn90909/struta

## Overview

#### Purpose and entry points
Struta is a multi-tenant funeral-services platform for bereaved families, funeral homes, vendors, staff, administrators, and developer API consumers. The primary browser app is a Vite/React SPA bootstrapped by `src/main.tsx` and routed from `src/App.tsx`. A separate Next shell exists at `app/page.tsx`, but the README’s development path indicates the Vite app plus API server is the operational entry point.

#### Client portal and role surfaces
The client is organized by domain/role rather than a single generic dashboard: family memorials and requests, provider operations, staff workspaces, marketplace, ERP, administration, and developer portal. These surfaces share authentication, layouts, Supabase access, localization, and UI components.
- `src/features/bereaved/pages/Dashboard.tsx`
- `src/features/manager/pages/Dashboard.tsx`
- `src/features/erp/pages/Dashboard.tsx`
- `src/developer/pages/Dashboard.tsx`

#### Identity, authorization, and tenant boundaries
Supabase Auth provides client identity; `AuthProvider` and role/profile helpers drive route and UI access. The Node API applies server-side request security and permissions, while database migrations establish RLS, role, tenant-isolation, and RPC controls. Admin MFA and provider verification are specialized security gates.
- `src/components/auth/AuthProvider.tsx`
- `server/security/requestSecurity.ts`
- `server/security/permissions.ts`
- `supabase/migrations/0028_role_based_struta_erp.sql`

#### Core API and service layer
The TypeScript Node server is the main API boundary: it loads configuration, mounts domain routes, and uses a Supabase service-role client for privileged work. Routes delegate payment, subscription, notification, email/OTP, audit, connector, and refund behavior to services rather than embedding it in the SPA.
- `server/index.ts`
- `server/routes/proErpRoutes.ts`
- `server/routes/workflowAutomationRoutes.ts`
- `server/services/subscription-service.ts`
- `server/supabase-admin.ts`

#### Operations workflow, ERP, and automation
Service requests flow from families into provider/funeral-home operations, staff assignments, tasks, schedules, vehicles, and reporting. Pro ERP adds tenant workspace and workflow-canvas capabilities. Server routes and a queue support automation execution; UI includes a workflow builder and task workspace.
- `src/components/workflow/RequestWorkflowBuilder.tsx`
- `src/features/manager/pages/TasksWorkspace.tsx`
- `server/jobs/queue.ts`
- `server/routes/workflowAutomationRoutes.ts`

#### Persistence, realtime, media, and background processing
Supabase/Postgres is the system of record for profiles, organizations, memorials, requests, billing, notifications, ERP, and developer usage. Migrations also define storage and RLS policies. Realtime hub, web-push server, Redis-capable cache, moderation scheduler/worker, and queue provide asynchronous or live behavior.
- `supabase/migrations/0004_funeral_operations_platform.sql`
- `server/realtime/realtimeHub.ts`
- `server/push-server/pushServer.ts`
- `server/moderation/moderationWorker.ts`
- `server/performance/redisCache.ts`

#### External integrations and deployable runtimes
Payments support Paystack, Stripe, and PayPal through server routes/services. Provider verification is a JWT-protected Supabase Edge Function using Google Maps/Places and optionally Resend. Browser push uses VAPID and a service worker. The repository also contains independently deployable Go services, Python calendar/email service, and a Go MCP API server. Deployment targets include Render, Docker, and Oracle.
- `supabase/functions/provider-verification/index.ts`
- `server/routes/paystackRoutes.ts`
- `public/push-sw.js`
- `go-services/api-backend/main.go`
- `MCP/cmd/mcp/main.go`
- `render.yaml`

Main entry points: [`server/index.ts`](https://github.com/emn90909/struta/blob/main/server/index.ts) (Node API server), [`supabase/migrations/0004_funeral_operations_platform.sql`](https://github.com/emn90909/struta/blob/main/supabase/migrations/0004_funeral_operations_platform.sql) (Supabase Postgres), [`render.yaml`](https://github.com/emn90909/struta/blob/main/render.yaml) (Render deployment), [`src/App.tsx`](https://github.com/emn90909/struta/blob/main/src/App.tsx) (App router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_vite["Vite React SPA<br/>client entry<br/>[main.tsx]"]
  node_app["App router<br/>client routing<br/>[App.tsx]"]
  node_auth["Auth provider<br/>identity client<br/>[AuthProvider.tsx]"]
  node_role_surfaces["Role workspaces<br/>domain UI<br/>[Dashboard.tsx]"]
  node_workflow_ui["Workflow and tasks<br/>operations UI"]
end

subgraph group_api["Node API"]
  node_api_server{{"Node API server<br/>API boundary<br/>[index.ts]"}}
  node_request_security["Request security<br/>API middleware<br/>[requestSecurity.ts]"]
  node_erp_routes["ERP routes<br/>domain routes<br/>[proErpRoutes.ts]"]
  node_automation_routes["Automation routes<br/>domain routes"]
  node_billing_service["Subscription service<br/>billing service"]
  node_supabase_admin["Service-role client<br/>privileged data access<br/>[supabase-admin.ts]"]
end

subgraph group_platform["Data and async platform"]
  node_supabase[("Supabase Postgres<br/>system of record")]
  node_tenant_controls["RLS and tenant controls<br/>database security"]
  node_automation_queue["Job queue<br/>async execution<br/>[queue.ts]"]
  node_realtime["Realtime and push<br/>live delivery<br/>[realtimeHub.ts]"]
  node_moderation_cache["Moderation and cache<br/>background processing"]
end

subgraph group_external["External and deployable services"]
  node_payments["Payment providers<br/>external payments<br/>[paystackRoutes.ts]"]
  node_verification{{"Provider verification<br/>Supabase Edge Function<br/>[index.ts]"}}
  node_push_worker["Browser push worker<br/>service worker<br/>[push-sw.js]"]
  node_go_backend["Go API backend<br/>deployable service<br/>[main.go]"]
  node_mcp_server["Go MCP server<br/>deployable API<br/>[main.go]"]
  node_deployment["Render deployment<br/>deployment target<br/>[render.yaml]"]
end

node_vite -->|"boots"| node_app
node_app -->|"uses"| node_auth
node_app -->|"routes to"| node_role_surfaces
node_role_surfaces -->|"operational work"| node_workflow_ui
node_auth -->|"authenticates with"| node_supabase
node_role_surfaces -->|"API requests"| node_api_server
node_workflow_ui -->|"automation commands"| node_automation_routes
node_api_server -->|"protects requests"| node_request_security
node_request_security -->|"authorizes"| node_erp_routes
node_request_security -->|"authorizes"| node_automation_routes
node_api_server -->|"delegates billing"| node_billing_service
node_api_server -->|"privileged access"| node_supabase_admin
node_supabase_admin -->|"reads and writes"| node_supabase
node_tenant_controls -->|"secures"| node_supabase
node_automation_routes -->|"enqueues jobs"| node_automation_queue
node_automation_queue -->|"background work"| node_moderation_cache
node_supabase -->|"data changes"| node_realtime
node_realtime -->|"push notifications"| node_push_worker
node_billing_service -->|"charges through"| node_payments
node_api_server -->|"provider verification"| node_verification
node_deployment -.->|"deploys"| node_api_server
node_deployment -.->|"deploys"| node_go_backend
node_deployment -.->|"deploys"| node_mcp_server

click node_vite "https://github.com/emn90909/struta/blob/main/src/main.tsx"
click node_app "https://github.com/emn90909/struta/blob/main/src/App.tsx"
click node_auth "https://github.com/emn90909/struta/blob/main/src/components/auth/AuthProvider.tsx"
click node_role_surfaces "https://github.com/emn90909/struta/blob/main/src/features/manager/pages/Dashboard.tsx"
click node_workflow_ui "https://github.com/emn90909/struta/blob/main/src/components/workflow/RequestWorkflowBuilder.tsx"
click node_api_server "https://github.com/emn90909/struta/blob/main/server/index.ts"
click node_request_security "https://github.com/emn90909/struta/blob/main/server/security/requestSecurity.ts"
click node_erp_routes "https://github.com/emn90909/struta/blob/main/server/routes/proErpRoutes.ts"
click node_automation_routes "https://github.com/emn90909/struta/blob/main/server/routes/workflowAutomationRoutes.ts"
click node_billing_service "https://github.com/emn90909/struta/blob/main/server/services/subscription-service.ts"
click node_supabase_admin "https://github.com/emn90909/struta/blob/main/server/supabase-admin.ts"
click node_supabase "https://github.com/emn90909/struta/blob/main/supabase/migrations/0004_funeral_operations_platform.sql"
click node_tenant_controls "https://github.com/emn90909/struta/blob/main/supabase/migrations/0028_role_based_struta_erp.sql"
click node_automation_queue "https://github.com/emn90909/struta/blob/main/server/jobs/queue.ts"
click node_realtime "https://github.com/emn90909/struta/blob/main/server/realtime/realtimeHub.ts"
click node_moderation_cache "https://github.com/emn90909/struta/blob/main/server/moderation/moderationWorker.ts"
click node_payments "https://github.com/emn90909/struta/blob/main/server/routes/paystackRoutes.ts"
click node_verification "https://github.com/emn90909/struta/blob/main/supabase/functions/provider-verification/index.ts"
click node_push_worker "https://github.com/emn90909/struta/blob/main/public/push-sw.js"
click node_go_backend "https://github.com/emn90909/struta/blob/main/go-services/api-backend/main.go"
click node_mcp_server "https://github.com/emn90909/struta/blob/main/MCP/cmd/mcp/main.go"
click node_deployment "https://github.com/emn90909/struta/blob/main/render.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vite,node_app,node_auth,node_role_surfaces,node_workflow_ui toneBlue
class node_api_server,node_request_security,node_erp_routes,node_automation_routes,node_billing_service,node_supabase_admin toneAmber
class node_supabase,node_tenant_controls,node_automation_queue,node_realtime,node_moderation_cache toneMint
class node_payments,node_verification,node_push_worker,node_go_backend,node_mcp_server,node_deployment toneRose
```

## Components

### Browser client

- [Vite React SPA](https://github.com/emn90909/struta/blob/main/src/main.tsx): client entry · Primary operational browser entry point. · `src/main.tsx`
- [App router](https://github.com/emn90909/struta/blob/main/src/App.tsx): client routing · `src/App.tsx`
- [Auth provider](https://github.com/emn90909/struta/blob/main/src/components/auth/AuthProvider.tsx): identity client · Supabase identity and role-aware client access. · `src/components/auth/AuthProvider.tsx`
- [Role workspaces](https://github.com/emn90909/struta/blob/main/src/features/manager/pages/Dashboard.tsx): domain UI · Family, provider, ERP, and developer portal surfaces. · `src/features/manager/pages/Dashboard.tsx`
- [Workflow and tasks](https://github.com/emn90909/struta/blob/main/src/components/workflow/RequestWorkflowBuilder.tsx): operations UI · Request workflow design and staff task execution. · `src/components/workflow/RequestWorkflowBuilder.tsx`

### Node API

- [Node API server](https://github.com/emn90909/struta/blob/main/server/index.ts): API boundary · Loads configuration and mounts domain routes. · `server/index.ts`
- [Request security](https://github.com/emn90909/struta/blob/main/server/security/requestSecurity.ts): API middleware · Applies server-side request protection and permissions. · `server/security/requestSecurity.ts`
- [ERP routes](https://github.com/emn90909/struta/blob/main/server/routes/proErpRoutes.ts): domain routes · Tenant ERP workspace operations. · `server/routes/proErpRoutes.ts`
- [Automation routes](https://github.com/emn90909/struta/blob/main/server/routes/workflowAutomationRoutes.ts): domain routes · Starts workflow automation execution. · `server/routes/workflowAutomationRoutes.ts`
- [Subscription service](https://github.com/emn90909/struta/blob/main/server/services/subscription-service.ts): billing service · `server/services/subscription-service.ts`
- [Service-role client](https://github.com/emn90909/struta/blob/main/server/supabase-admin.ts): privileged data access · Server-only Supabase access for privileged work. · `server/supabase-admin.ts`

### Data and async platform

- [Supabase Postgres](https://github.com/emn90909/struta/blob/main/supabase/migrations/0004_funeral_operations_platform.sql): system of record · Stores tenant data, memorials, requests, billing, ERP, and notifications. · `supabase/migrations/0004_funeral_operations_platform.sql`
- [RLS and tenant controls](https://github.com/emn90909/struta/blob/main/supabase/migrations/0028_role_based_struta_erp.sql): database security · Database roles, tenant isolation, and RPC controls. · `supabase/migrations/0028_role_based_struta_erp.sql`
- [Job queue](https://github.com/emn90909/struta/blob/main/server/jobs/queue.ts): async execution · Queues automation and background work. · `server/jobs/queue.ts`
- [Realtime and push](https://github.com/emn90909/struta/blob/main/server/realtime/realtimeHub.ts): live delivery · Realtime hub and browser push delivery. · `server/realtime/realtimeHub.ts`
- [Moderation and cache](https://github.com/emn90909/struta/blob/main/server/moderation/moderationWorker.ts): background processing · Moderation worker with Redis-capable caching. · `server/moderation/moderationWorker.ts`

### External and deployable services

- [Payment providers](https://github.com/emn90909/struta/blob/main/server/routes/paystackRoutes.ts): external payments · Paystack, Stripe, and PayPal integrations. · `server/routes/paystackRoutes.ts`
- [Provider verification](https://github.com/emn90909/struta/blob/main/supabase/functions/provider-verification/index.ts): Supabase Edge Function · JWT-protected provider verification using Maps/Places and optional email. · `supabase/functions/provider-verification/index.ts`
- [Browser push worker](https://github.com/emn90909/struta/blob/main/public/push-sw.js): service worker · Receives VAPID browser push messages. · `public/push-sw.js`
- [Go API backend](https://github.com/emn90909/struta/blob/main/go-services/api-backend/main.go): deployable service · `go-services/api-backend/main.go`
- [Go MCP server](https://github.com/emn90909/struta/blob/main/MCP/cmd/mcp/main.go): deployable API · `MCP/cmd/mcp/main.go`
- [Render deployment](https://github.com/emn90909/struta/blob/main/render.yaml): deployment target · Repository deployment configuration. · `render.yaml`

## Connections

- Vite React SPA → App router: boots
- App router → Auth provider: uses
- App router → Role workspaces: routes to
- Role workspaces → Workflow and tasks: operational work
- Auth provider → Supabase Postgres: authenticates with
- Role workspaces → Node API server: API requests
- Workflow and tasks → Automation routes: automation commands
- Node API server → Request security: protects requests
- Request security → ERP routes: authorizes
- Request security → Automation routes: authorizes
- Node API server → Subscription service: delegates billing
- Node API server → Service-role client: privileged access
- Service-role client → Supabase Postgres: reads and writes
- RLS and tenant controls → Supabase Postgres: secures
- Automation routes → Job queue: enqueues jobs
- Job queue → Moderation and cache: background work
- Supabase Postgres → Realtime and push: data changes
- Realtime and push → Browser push worker: push notifications
- Subscription service → Payment providers: charges through
- Node API server → Provider verification: provider verification
- Render deployment → Node API server: deploys
- Render deployment → Go API backend: deploys
- Render deployment → Go MCP server: deploys
