# tpsis-21/hub-control architecture

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

- Interactive diagram: https://gitdiagram.com/tpsis-21/hub-control
- Repository: https://github.com/tpsis-21/hub-control

## Overview

Hub Control is a Next.js/Supabase administration product for customer, subscription, plan, server, payment, and integration management. The main workflow is an operator or customer using the app, a route handling the request, and domain services updating Supabase or invoking an integration; a payment webhook can then trigger fulfillment and renewal. The README also documents analytics, notifications, marketing, monitoring, security, and optimization capabilities. Edges are limited to README statements and the supplied source index/excerpts; unsampled feature wiring is not asserted.

Main entry points: [`src/app/(app)`](https://github.com/tpsis-21/hub-control/tree/main/src/app/(app)) (Admin workspace), [`src/services/payment-fulfillment.service.ts`](https://github.com/tpsis-21/hub-control/blob/main/src/services/payment-fulfillment.service.ts) (Payment fulfillment), [`src/lib/supabase/unified-client.ts`](https://github.com/tpsis-21/hub-control/blob/main/src/lib/supabase/unified-client.ts) (Supabase client), [`src/middleware/unified-middleware.ts`](https://github.com/tpsis-21/hub-control/blob/main/src/middleware/unified-middleware.ts) (Request security)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and access"]
  node_appui["Admin workspace"]
  node_authhook["Browser auth<br/>[useAuth.ts]"]
  node_adminapi["Admin APIs<br/>[route.ts]"]
  node_ui["Shared UI primitives"]
end

subgraph group_commerce["Commerce and fulfillment"]
  node_checkoutui["Customer checkout"]
  node_publiccheckout["Checkout endpoints<br/>[route.ts]"]
  node_gatesroute["Gates2B webhook<br/>[route.ts]"]
  node_fulfillment["Payment fulfillment"]
  node_orders["Checkout orders"]
  node_subscriptions["Subscriptions"]
end

subgraph group_integrations["External integrations"]
  node_gates["Gates2B service<br/>[gates2b.service.ts]"]
  node_natv["NATV service<br/>[natv.service.ts]"]
  node_thebestui["TheBest package manager"]
  node_thebest["TheBest service<br/>[thebest.service.ts]"]
end

subgraph group_operations["Operations and insights"]
  node_analytics["Analytics dashboards"]
  node_analyticsapi["Analytics routes<br/>[analytics.js]"]
  node_notifications["Notification APIs<br/>[route.ts]"]
  node_templates["Notification templates"]
  node_marketing["Marketing campaigns<br/>[route.ts]"]
  node_reports["Reports API<br/>[route.ts]"]
  node_dbopt["Database optimization"]
end

subgraph group_platform["Platform services"]
  node_authsvc["Supabase Auth<br/>[server.ts]"]
  node_db[("Supabase database<br/>[database.types.ts]")]
  node_unifiedclient["Supabase client<br/>[unified-client.ts]"]
  node_middleware["Request security"]
  node_security["Security controls"]
  node_ratelimit["Rate limiting<br/>[rate-limit.ts]"]
  node_logger["Service logging<br/>[logger.service.ts]"]
  node_prodlogger["Production logger"]
end

node_operator(("Operator"))
node_customer(("Customer"))
node_externalpay{{"Payment provider"}}
node_externalpanels{{"External panels"}}

node_operator -->|"manages"| node_appui
node_customer -.->|"starts checkout"| node_checkoutui
node_appui -.->|"uses administration"| node_adminapi
node_authhook -->|"authenticates"| node_authsvc
node_checkoutui -.->|"submits checkout"| node_publiccheckout
node_publiccheckout -.->|"creates payment"| node_gates
node_externalpay -.->|"sends webhook"| node_gatesroute
node_gatesroute -.->|"dispatches payment"| node_fulfillment
node_fulfillment -->|"reads and updates"| node_orders
node_fulfillment -->|"renews subscription"| node_subscriptions
node_fulfillment -->|"renews panel"| node_natv
node_externalpanels -.->|"provides integration"| node_thebest
node_thebestui -->|"uses service"| node_thebest
node_appui -.->|"views insights"| node_analytics
node_analytics -.->|"reads metrics"| node_analyticsapi
node_appui -.->|"manages notifications"| node_notifications
node_templates -.->|"configures templates"| node_notifications
node_appui -.->|"runs campaigns"| node_marketing
node_appui -.->|"views reports"| node_reports
node_middleware -->|"checks session"| node_authsvc
node_middleware -->|"applies limits"| node_ratelimit
node_middleware -->|"records security"| node_security
node_unifiedclient -->|"types database access"| node_db
node_fulfillment -->|"accesses database"| node_unifiedclient
node_gates -->|"accesses database"| node_unifiedclient
node_notifications -->|"accesses database"| node_unifiedclient
node_dbopt -->|"uses client"| node_unifiedclient
node_fulfillment -->|"logs activity"| node_logger
node_logger -->|"delegates logging"| node_prodlogger
node_templates -->|"renders controls"| node_ui

click node_appui "https://github.com/tpsis-21/hub-control/tree/main/src/app/(app)"
click node_authhook "https://github.com/tpsis-21/hub-control/blob/main/src/hooks/useAuth.ts"
click node_authsvc "https://github.com/tpsis-21/hub-control/blob/main/src/lib/supabase/clients/server.ts"
click node_checkoutui "https://github.com/tpsis-21/hub-control/blob/main/src/components/cliente/cliente-pagamento-client.tsx"
click node_publiccheckout "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/public/checkout/create/route.ts"
click node_gatesroute "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/gates2b/webhook/route.ts"
click node_gates "https://github.com/tpsis-21/hub-control/blob/main/src/services/gates2b.service.ts"
click node_fulfillment "https://github.com/tpsis-21/hub-control/blob/main/src/services/payment-fulfillment.service.ts"
click node_orders "https://github.com/tpsis-21/hub-control/blob/main/src/services/checkout-order.service.ts"
click node_subscriptions "https://github.com/tpsis-21/hub-control/blob/main/src/services/subscription.service.ts"
click node_natv "https://github.com/tpsis-21/hub-control/blob/main/src/services/natv.service.ts"
click node_thebestui "https://github.com/tpsis-21/hub-control/blob/main/src/components/integrations/thebest-package-manager.tsx"
click node_thebest "https://github.com/tpsis-21/hub-control/blob/main/src/services/thebest.service.ts"
click node_adminapi "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/admin/plans/route.ts"
click node_analytics "https://github.com/tpsis-21/hub-control/blob/main/src/components/analytics/AnalyticsDashboard.jsx"
click node_analyticsapi "https://github.com/tpsis-21/hub-control/blob/main/src/routes/analytics.js"
click node_notifications "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/notifications/route.ts"
click node_templates "https://github.com/tpsis-21/hub-control/blob/main/src/components/dashboard/NotificationTemplateManager.tsx"
click node_marketing "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/marketing/send-campaign/route.ts"
click node_reports "https://github.com/tpsis-21/hub-control/blob/main/src/app/api/reports/route.ts"
click node_db "https://github.com/tpsis-21/hub-control/blob/main/src/lib/database.types.ts"
click node_unifiedclient "https://github.com/tpsis-21/hub-control/blob/main/src/lib/supabase/unified-client.ts"
click node_middleware "https://github.com/tpsis-21/hub-control/blob/main/src/middleware/unified-middleware.ts"
click node_security "https://github.com/tpsis-21/hub-control/blob/main/src/lib/security-monitor.ts"
click node_ratelimit "https://github.com/tpsis-21/hub-control/blob/main/src/lib/security/rate-limit.ts"
click node_dbopt "https://github.com/tpsis-21/hub-control/blob/main/src/lib/database-query-optimizer.ts"
click node_logger "https://github.com/tpsis-21/hub-control/blob/main/src/services/logger.service.ts"
click node_prodlogger "https://github.com/tpsis-21/hub-control/blob/main/src/utils/production-logger.ts"
click node_ui "https://github.com/tpsis-21/hub-control/tree/main/src/components/ui"

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_appui,node_authhook,node_adminapi,node_ui toneBlue
class node_checkoutui,node_publiccheckout,node_gatesroute,node_fulfillment,node_orders,node_subscriptions toneAmber
class node_gates,node_natv,node_thebestui,node_thebest toneMint
class node_analytics,node_analyticsapi,node_notifications,node_templates,node_marketing,node_reports,node_dbopt toneRose
class node_authsvc,node_db,node_unifiedclient,node_middleware,node_security,node_ratelimit,node_logger,node_prodlogger,node_operator,node_customer,node_externalpay,node_externalpanels toneIndigo
```

## Components

### Application and access

- [Admin workspace](https://github.com/tpsis-21/hub-control/tree/main/src/app/(app)): `src/app/(app)`
- [Browser auth](https://github.com/tpsis-21/hub-control/blob/main/src/hooks/useAuth.ts): `src/hooks/useAuth.ts`
- [Admin APIs](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/admin/plans/route.ts): `src/app/api/admin/plans/route.ts`
- [Shared UI primitives](https://github.com/tpsis-21/hub-control/tree/main/src/components/ui): `src/components/ui`

### Commerce and fulfillment

- [Customer checkout](https://github.com/tpsis-21/hub-control/blob/main/src/components/cliente/cliente-pagamento-client.tsx): `src/components/cliente/cliente-pagamento-client.tsx`
- [Checkout endpoints](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/public/checkout/create/route.ts): `src/app/api/public/checkout/create/route.ts`
- [Gates2B webhook](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/gates2b/webhook/route.ts): `src/app/api/gates2b/webhook/route.ts`
- [Payment fulfillment](https://github.com/tpsis-21/hub-control/blob/main/src/services/payment-fulfillment.service.ts): `src/services/payment-fulfillment.service.ts`
- [Checkout orders](https://github.com/tpsis-21/hub-control/blob/main/src/services/checkout-order.service.ts): `src/services/checkout-order.service.ts`
- [Subscriptions](https://github.com/tpsis-21/hub-control/blob/main/src/services/subscription.service.ts): `src/services/subscription.service.ts`

### External integrations

- [Gates2B service](https://github.com/tpsis-21/hub-control/blob/main/src/services/gates2b.service.ts): `src/services/gates2b.service.ts`
- [NATV service](https://github.com/tpsis-21/hub-control/blob/main/src/services/natv.service.ts): `src/services/natv.service.ts`
- [TheBest package manager](https://github.com/tpsis-21/hub-control/blob/main/src/components/integrations/thebest-package-manager.tsx): `src/components/integrations/thebest-package-manager.tsx`
- [TheBest service](https://github.com/tpsis-21/hub-control/blob/main/src/services/thebest.service.ts): `src/services/thebest.service.ts`

### Operations and insights

- [Analytics dashboards](https://github.com/tpsis-21/hub-control/blob/main/src/components/analytics/AnalyticsDashboard.jsx): `src/components/analytics/AnalyticsDashboard.jsx`
- [Analytics routes](https://github.com/tpsis-21/hub-control/blob/main/src/routes/analytics.js): `src/routes/analytics.js`
- [Notification APIs](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/notifications/route.ts): `src/app/api/notifications/route.ts`
- [Notification templates](https://github.com/tpsis-21/hub-control/blob/main/src/components/dashboard/NotificationTemplateManager.tsx): `src/components/dashboard/NotificationTemplateManager.tsx`
- [Marketing campaigns](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/marketing/send-campaign/route.ts): `src/app/api/marketing/send-campaign/route.ts`
- [Reports API](https://github.com/tpsis-21/hub-control/blob/main/src/app/api/reports/route.ts): `src/app/api/reports/route.ts`
- [Database optimization](https://github.com/tpsis-21/hub-control/blob/main/src/lib/database-query-optimizer.ts): `src/lib/database-query-optimizer.ts`

### Platform services

- [Supabase Auth](https://github.com/tpsis-21/hub-control/blob/main/src/lib/supabase/clients/server.ts): `src/lib/supabase/clients/server.ts`
- [Supabase database](https://github.com/tpsis-21/hub-control/blob/main/src/lib/database.types.ts): `src/lib/database.types.ts`
- [Supabase client](https://github.com/tpsis-21/hub-control/blob/main/src/lib/supabase/unified-client.ts): `src/lib/supabase/unified-client.ts`
- [Request security](https://github.com/tpsis-21/hub-control/blob/main/src/middleware/unified-middleware.ts): `src/middleware/unified-middleware.ts`
- [Security controls](https://github.com/tpsis-21/hub-control/blob/main/src/lib/security-monitor.ts): `src/lib/security-monitor.ts`
- [Rate limiting](https://github.com/tpsis-21/hub-control/blob/main/src/lib/security/rate-limit.ts): `src/lib/security/rate-limit.ts`
- [Service logging](https://github.com/tpsis-21/hub-control/blob/main/src/services/logger.service.ts): `src/services/logger.service.ts`
- [Production logger](https://github.com/tpsis-21/hub-control/blob/main/src/utils/production-logger.ts): `src/utils/production-logger.ts`

### Other components

- **Operator**
- **Customer**
- **Payment provider**
- **External panels**

## Connections

- Operator → Admin workspace: manages
- Customer → Customer checkout: starts checkout
- Admin workspace → Admin APIs: uses administration
- Browser auth → Supabase Auth: authenticates (evidence: `src/hooks/useAuth.ts`)
- Customer checkout → Checkout endpoints: submits checkout
- Checkout endpoints → Gates2B service: creates payment
- Payment provider → Gates2B webhook: sends webhook
- Gates2B webhook → Payment fulfillment: dispatches payment
- Payment fulfillment → Checkout orders: reads and updates (evidence: `src/services/payment-fulfillment.service.ts`)
- Payment fulfillment → Subscriptions: renews subscription (evidence: `src/services/payment-fulfillment.service.ts`)
- Payment fulfillment → NATV service: renews panel (evidence: `src/services/payment-fulfillment.service.ts`)
- External panels → TheBest service: provides integration
- TheBest package manager → TheBest service: uses service (evidence: `src/components/integrations/thebest-package-manager.tsx`)
- Admin workspace → Analytics dashboards: views insights
- Analytics dashboards → Analytics routes: reads metrics
- Admin workspace → Notification APIs: manages notifications
- Notification templates → Notification APIs: configures templates
- Admin workspace → Marketing campaigns: runs campaigns
- Admin workspace → Reports API: views reports
- Request security → Supabase Auth: checks session (evidence: `src/middleware/unified-middleware.ts`)
- Request security → Rate limiting: applies limits (evidence: `src/middleware/unified-middleware.ts`)
- Request security → Security controls: records security (evidence: `src/middleware/unified-middleware.ts`)
- Supabase client → Supabase database: types database access (evidence: `src/lib/supabase/unified-client.ts`)
- Payment fulfillment → Supabase client: accesses database (evidence: `src/services/payment-fulfillment.service.ts`)
- Gates2B service → Supabase client: accesses database (evidence: `src/services/gates2b.service.ts`)
- Notification APIs → Supabase client: accesses database (evidence: `src/app/api/notifications/route.ts`)
- Database optimization → Supabase client: uses client (evidence: `src/lib/database-query-optimizer.ts`)
- Payment fulfillment → Service logging: logs activity (evidence: `src/services/payment-fulfillment.service.ts`)
- Service logging → Production logger: delegates logging (evidence: `src/services/logger.service.ts`)
- Notification templates → Shared UI primitives: renders controls (evidence: `src/components/dashboard/NotificationTemplateManager.tsx`)
