# metavert-io/lastsaas architecture

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

- Interactive diagram: https://gitdiagram.com/metavert-io/lastsaas
- Repository: https://github.com/metavert-io/lastsaas

## Overview

LastSaaS is a Go and React SaaS foundation. The main user workflow runs from browser sign-in and tenant selection through protected application or admin features, which call the backend API. The product also provides billing and entitlements, tenant and user administration, branding, webhooks, telemetry and analytics, health and financial dashboards, and CLI/MCP operations. Frontend routing and several context/API interactions are evidenced in excerpts; many backend and feature-specific connections are based on README capabilities and remain unverified.

Main entry points: [`backend/internal/api/handlers`](https://github.com/metavert-io/lastsaas/tree/master/backend/internal/api/handlers) (Product API handlers), [`frontend/src/api/client.ts`](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/api/client.ts) (REST API client), [`frontend/src/App.tsx`](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/App.tsx) (Route application), [`backend/cmd/server/main.go`](https://github.com/metavert-io/lastsaas/blob/master/backend/cmd/server/main.go) (HTTP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend experience"]
  node_app["Route application<br/>[App.tsx]"]
  node_auth_ui["Authentication screens"]
  node_auth_state["Auth session<br/>[AuthContext.tsx]"]
  node_tenant_state["Tenant context<br/>[TenantContext.tsx]"]
  node_api_client["REST API client<br/>[client.ts]"]
  node_customer_ui["Customer workspace"]
  node_admin_ui["Admin console"]
  node_branding_ui["Branding context"]
  node_theme_state["Theme preferences<br/>[ThemeContext.tsx]"]
end

subgraph group_backend["Backend services"]
  node_server["HTTP server<br/>[main.go]"]
  node_auth_handlers["Auth endpoints<br/>[auth.go]"]
  node_feature_handlers["Product API handlers"]
  node_tenant_access["Tenant and RBAC"]
  node_telemetry["Telemetry analytics<br/>[service.go]"]
  node_webhook_dispatch["Webhook delivery<br/>[dispatcher.go]"]
  node_database[("MongoDB data<br/>[mongodb.go]")]
end

subgraph group_operations["Operations and integrations"]
  node_stripe["Stripe billing<br/>[stripe.go]"]
  node_email["Email delivery<br/>[resend.go]"]
  node_health["Health monitoring"]
  node_cli["Admin CLI and MCP"]
  node_external_services{{"External services"}}
end

node_browser(("SaaS user"))

node_browser -->|"opens"| node_app
node_app -->|"routes"| node_auth_ui
node_app -->|"routes"| node_customer_ui
node_app -->|"routes"| node_admin_ui
node_auth_ui -.->|"uses session"| node_auth_state
node_auth_state -->|"calls auth"| node_api_client
node_tenant_state -->|"reads memberships"| node_auth_state
node_tenant_state -->|"sets tenant header"| node_api_client
node_customer_ui -.->|"requests data"| node_api_client
node_admin_ui -.->|"requests data"| node_api_client
node_branding_ui -->|"loads branding"| node_api_client
node_theme_state -->|"updates preference"| node_api_client
node_api_client -.->|"sends API requests"| node_server
node_server -.->|"routes requests"| node_auth_handlers
node_server -.->|"routes requests"| node_feature_handlers
node_auth_handlers -.->|"enforces access"| node_tenant_access
node_feature_handlers -.->|"enforces access"| node_tenant_access
node_auth_handlers -.->|"reads and writes"| node_database
node_feature_handlers -.->|"reads and writes"| node_database
node_feature_handlers -.->|"handles billing"| node_stripe
node_feature_handlers -.->|"sends messages"| node_email
node_feature_handlers -.->|"dispatches events"| node_webhook_dispatch
node_feature_handlers -.->|"records events"| node_telemetry
node_health -.->|"checks metrics"| node_database
node_external_services -.->|"provides billing"| node_stripe
node_external_services -.->|"provides delivery"| node_email
node_webhook_dispatch -.->|"sends webhooks"| node_external_services
node_cli -.->|"administers"| node_server

click node_app "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/App.tsx"
click node_auth_ui "https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/auth"
click node_auth_state "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/AuthContext.tsx"
click node_tenant_state "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/TenantContext.tsx"
click node_api_client "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/api/client.ts"
click node_customer_ui "https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/app"
click node_admin_ui "https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/admin"
click node_branding_ui "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/BrandingContext.tsx"
click node_theme_state "https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/ThemeContext.tsx"
click node_server "https://github.com/metavert-io/lastsaas/blob/master/backend/cmd/server/main.go"
click node_auth_handlers "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/api/handlers/auth.go"
click node_feature_handlers "https://github.com/metavert-io/lastsaas/tree/master/backend/internal/api/handlers"
click node_tenant_access "https://github.com/metavert-io/lastsaas/tree/master/backend/internal/middleware"
click node_telemetry "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/telemetry/service.go"
click node_webhook_dispatch "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/webhooks/dispatcher.go"
click node_database "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/db/mongodb.go"
click node_stripe "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/stripe/stripe.go"
click node_email "https://github.com/metavert-io/lastsaas/blob/master/backend/internal/email/resend.go"
click node_health "https://github.com/metavert-io/lastsaas/tree/master/backend/internal/health"
click node_cli "https://github.com/metavert-io/lastsaas/tree/master/backend/cmd/lastsaas"

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_app,node_auth_ui,node_auth_state,node_tenant_state,node_api_client,node_customer_ui,node_admin_ui,node_branding_ui,node_theme_state,node_browser toneBlue
class node_server,node_auth_handlers,node_feature_handlers,node_tenant_access,node_telemetry,node_webhook_dispatch,node_database toneAmber
class node_stripe,node_email,node_health,node_cli,node_external_services toneMint
```

## Components

### Frontend experience

- [Route application](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Authentication screens](https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/auth): `frontend/src/pages/auth`
- [Auth session](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/AuthContext.tsx): `frontend/src/contexts/AuthContext.tsx`
- [Tenant context](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/TenantContext.tsx): `frontend/src/contexts/TenantContext.tsx`
- [REST API client](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Customer workspace](https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/app): `frontend/src/pages/app`
- [Admin console](https://github.com/metavert-io/lastsaas/tree/master/frontend/src/pages/admin): `frontend/src/pages/admin`
- [Branding context](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/BrandingContext.tsx): `frontend/src/contexts/BrandingContext.tsx`
- [Theme preferences](https://github.com/metavert-io/lastsaas/blob/master/frontend/src/contexts/ThemeContext.tsx): `frontend/src/contexts/ThemeContext.tsx`

### Backend services

- [HTTP server](https://github.com/metavert-io/lastsaas/blob/master/backend/cmd/server/main.go): `backend/cmd/server/main.go`
- [Auth endpoints](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/api/handlers/auth.go): `backend/internal/api/handlers/auth.go`
- [Product API handlers](https://github.com/metavert-io/lastsaas/tree/master/backend/internal/api/handlers): `backend/internal/api/handlers`
- [Tenant and RBAC](https://github.com/metavert-io/lastsaas/tree/master/backend/internal/middleware): `backend/internal/middleware`
- [Telemetry analytics](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/telemetry/service.go): `backend/internal/telemetry/service.go`
- [Webhook delivery](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/webhooks/dispatcher.go): `backend/internal/webhooks/dispatcher.go`
- [MongoDB data](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/db/mongodb.go): `backend/internal/db/mongodb.go`

### Operations and integrations

- [Stripe billing](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/stripe/stripe.go): `backend/internal/stripe/stripe.go`
- [Email delivery](https://github.com/metavert-io/lastsaas/blob/master/backend/internal/email/resend.go): `backend/internal/email/resend.go`
- [Health monitoring](https://github.com/metavert-io/lastsaas/tree/master/backend/internal/health): `backend/internal/health`
- [Admin CLI and MCP](https://github.com/metavert-io/lastsaas/tree/master/backend/cmd/lastsaas): `backend/cmd/lastsaas`
- **External services**

### Other components

- **SaaS user**

## Connections

- SaaS user → Route application: opens (evidence: `frontend/src/App.tsx`)
- Route application → Authentication screens: routes (evidence: `frontend/src/App.tsx`)
- Route application → Customer workspace: routes (evidence: `frontend/src/App.tsx`)
- Route application → Admin console: routes (evidence: `frontend/src/App.tsx`)
- Authentication screens → Auth session: uses session (evidence: `frontend/src/pages/auth/AuthCallbackPage.tsx`)
- Auth session → REST API client: calls auth (evidence: `frontend/src/contexts/AuthContext.tsx`)
- Tenant context → Auth session: reads memberships (evidence: `frontend/src/contexts/TenantContext.tsx`)
- Tenant context → REST API client: sets tenant header (evidence: `frontend/src/contexts/TenantContext.tsx`)
- Customer workspace → REST API client: requests data (evidence: `frontend/src/pages/app/settings/SessionsTab.tsx`)
- Admin console → REST API client: requests data (evidence: `frontend/src/pages/admin/PlansPage.tsx`)
- Branding context → REST API client: loads branding (evidence: `frontend/src/contexts/BrandingContext.tsx`)
- Theme preferences → REST API client: updates preference (evidence: `frontend/src/contexts/ThemeContext.tsx`)
- REST API client → HTTP server: sends API requests
- HTTP server → Auth endpoints: routes requests
- HTTP server → Product API handlers: routes requests
- Auth endpoints → Tenant and RBAC: enforces access
- Product API handlers → Tenant and RBAC: enforces access
- Auth endpoints → MongoDB data: reads and writes
- Product API handlers → MongoDB data: reads and writes
- Product API handlers → Stripe billing: handles billing
- Product API handlers → Email delivery: sends messages
- Product API handlers → Webhook delivery: dispatches events
- Product API handlers → Telemetry analytics: records events
- Health monitoring → MongoDB data: checks metrics
- External services → Stripe billing: provides billing
- External services → Email delivery: provides delivery
- Webhook delivery → External services: sends webhooks
- Admin CLI and MCP → HTTP server: administers
