# aamnaqueen94-dotcom/supperweb-ai architecture

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

- Interactive diagram: https://gitdiagram.com/aamnaqueen94-dotcom/supperweb-ai
- Repository: https://github.com/aamnaqueen94-dotcom/supperweb-ai

## Overview

#### Purpose and entry points
This is a large Next.js/TypeScript modular web platform spanning AI, messaging, productivity, media, browser capabilities, commerce, and domain tools. The main UI entry is `src/app/page.tsx`; global rendering and cross-cutting setup begin in `src/app/layout.tsx` and `src/middleware.ts`. HTTP backend entry points are Next App Router handlers under `src/app/api`.

#### Route composition and feature surfaces
App Router route groups separate public, authentication, and dashboard experiences, while feature namespaces own their layouts and pages. Major surfaces include AI, messaging, cloud storage, meetings, maps, education, games, payments, and browser APIs.
- `src/app/(auth)/layout.tsx`
- `src/app/(dashboard)/layout.tsx`
- `src/app/ai/layout.tsx`

Pages generally compose domain-specific view components, feature components, hooks, and client-side state rather than embedding backend behavior directly.
- `src/components/views/messaging-view.tsx`
- `src/components/ai/ai-chat/ai-chat.tsx`
- `src/hooks/messaging/use-messaging.ts`

#### API boundary and request handling
`src/app/api/**/route.ts` is the server boundary for browser clients and integrations. APIs are organized by business domain, including auth, AI, chat/messaging, storage/files, payments, construction, and administration. Middleware and API pipeline modules provide intended common handling for authentication, validation, caching, retry, timeout, rate limiting, and response behavior.
- `src/app/api/auth/login/route.ts`
- `src/app/api/messaging/conversations/route.ts`
- `src/lib/api/api.pipeline.ts`

#### Authentication, authorization, and security
Authentication endpoints cover signup, login, logout, password recovery/reset, OAuth-style Google login, OTP, and identity checks. Security is a distinct layer with CSRF, SSRF, sanitization, upload validation, audit logging, and rate limiting. A broad permission subsystem models browser/device permissions and role or policy enforcement.
- `src/app/api/auth/otp/verify/route.ts`
- `src/lib/security/security.ts`
- `src/lib/permissions/PermissionEngine.ts`

#### Domain orchestration and state model
The repository uses repeated domain layers: interfaces/types define contracts; services and managers implement operations; React providers/hooks expose state to UI; stores hold feature state. AI, messaging, analytics, payments, storage, search, speech, video, and weather follow this pattern. There are parallel `src/lib/services` and `src/services` trees, so engineers should establish which layer is authoritative per feature before extending it.
- `src/lib/services/ai/chat.service.ts`
- `src/providers/messaging/messaging.provider.ts`
- `src/store/messaging/messaging.store.ts`

#### Persistence, realtime, and operations
Prisma is the visible database integration, with schema, seed process, and database scripts for migration, backup, and restore. Messaging has dedicated HTTP routes plus a socket module and a standalone messaging microservice; call handling also has a separate TypeScript microservice. This creates a boundary between Next.js request/response features and long-lived realtime processes.
- `prisma/schema.prisma`
- `src/lib/messaging-socket.ts`
- `mini-services/messaging-service/index.ts`

#### Runtime and deployment
The primary runtime is Node.js/Next.js, with React client components and browser-native capabilities accessed through feature hooks/services. Deployment is configured for Netlify; Caddy configuration suggests an optional reverse-proxy deployment path. A service worker and web manifests support PWA behavior.
- `netlify.toml`
- `caddyfile`
- `public/sw.js`

Main entry points: [`src/app/layout.tsx`](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/layout.tsx) (Root layout), [`src/lib/api/api.pipeline.ts`](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/api/api.pipeline.ts) (API pipeline), [`src/middleware.ts`](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/middleware.ts) (Request middleware), [`src/lib/services/ai/chat.service.ts`](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/services/ai/chat.service.ts) (Feature services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js Web App"]
  node_middleware["Request middleware<br/>Next middleware<br/>[middleware.ts]"]
  node_root_layout["Root layout<br/>React layout<br/>[layout.tsx]"]
  node_home["Home entry<br/>App Router page<br/>[page.tsx]"]
  node_route_groups["Auth &amp; dashboard routes<br/>route layouts<br/>[layout.tsx]"]
  node_ai_routes["AI feature routes<br/>feature layout<br/>[layout.tsx]"]
  node_messaging_view["Messaging UI<br/>view component<br/>[messaging-view.tsx]"]
  node_ai_chat["AI chat UI<br/>feature component<br/>[ai-chat.tsx]"]
  node_api_routes{{"Domain API routes<br/>App Router handlers<br/>[route.ts]"}}
end

subgraph group_domain["Domain Layer"]
  node_api_pipeline["API pipeline<br/>request pipeline<br/>[api.pipeline.ts]"]
  node_security["Security controls<br/>security layer<br/>[security.ts]"]
  node_permissions["Permission engine<br/>authorization"]
  node_feature_services["Feature services<br/>domain services<br/>[chat.service.ts]"]
  node_messaging_state["Messaging state<br/>provider and store"]
  node_messaging_hook["Messaging hook<br/>React hook<br/>[use-messaging.ts]"]
end

subgraph group_realtime["Realtime Services"]
  node_socket_gateway["Messaging socket<br/>realtime gateway"]
  node_messaging_service{{"Messaging microservice<br/>Node microservice<br/>[index.ts]"}}
end

subgraph group_data["Data &amp; Operations"]
  node_prisma[("Prisma database model<br/>persistence schema<br/>[schema.prisma]")]
  node_pwa["PWA service worker<br/>[sw.js]"]
  node_netlify["Netlify deployment<br/>deployment config<br/>[netlify.toml]"]
  node_caddy["Caddy proxy option<br/>reverse proxy config"]
end

node_browser(("Browser clients"))

node_browser -->|"requests"| node_middleware
node_middleware -->|"renders app"| node_root_layout
node_root_layout -->|"hosts"| node_home
node_root_layout -->|"composes"| node_route_groups
node_root_layout -->|"composes"| node_ai_routes
node_route_groups -->|"renders"| node_messaging_view
node_ai_routes -->|"renders"| node_ai_chat
node_messaging_view -->|"uses"| node_messaging_hook
node_messaging_hook -->|"reads and updates"| node_messaging_state
node_ai_chat -->|"invokes"| node_feature_services
node_browser -->|"HTTP calls"| node_api_routes
node_api_routes -->|"runs through"| node_api_pipeline
node_api_pipeline -->|"applies"| node_security
node_api_pipeline -->|"authorizes"| node_permissions
node_api_pipeline -->|"dispatches"| node_feature_services
node_feature_services -->|"persists"| node_prisma
node_messaging_state -->|"realtime events"| node_socket_gateway
node_socket_gateway -->|"connects to"| node_messaging_service
node_messaging_service -->|"stores messages"| node_prisma
node_browser -.->|"registers"| node_pwa
node_netlify -.->|"deploys"| node_root_layout
node_caddy -.->|"optional proxy"| node_middleware

click node_middleware "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/middleware.ts"
click node_root_layout "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/layout.tsx"
click node_home "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/page.tsx"
click node_route_groups "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/(auth)/layout.tsx"
click node_ai_routes "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/ai/layout.tsx"
click node_messaging_view "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/components/views/messaging-view.tsx"
click node_ai_chat "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/components/ai/ai-chat/ai-chat.tsx"
click node_api_routes "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/api/messaging/conversations/route.ts"
click node_api_pipeline "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/api/api.pipeline.ts"
click node_security "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/security/security.ts"
click node_permissions "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/permissions/PermissionEngine.ts"
click node_feature_services "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/services/ai/chat.service.ts"
click node_messaging_state "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/providers/messaging/messaging.provider.ts"
click node_messaging_hook "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/hooks/messaging/use-messaging.ts"
click node_socket_gateway "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/messaging-socket.ts"
click node_messaging_service "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/mini-services/messaging-service/index.ts"
click node_prisma "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/prisma/schema.prisma"
click node_pwa "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/public/sw.js"
click node_netlify "https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/netlify.toml"
click node_caddy "https://github.com/aamnaqueen94-dotcom/supperweb-ai/tree/main/caddyfile"

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_middleware,node_root_layout,node_home,node_route_groups,node_ai_routes,node_messaging_view,node_ai_chat,node_api_routes toneBlue
class node_api_pipeline,node_security,node_permissions,node_feature_services,node_messaging_state,node_messaging_hook toneAmber
class node_socket_gateway,node_messaging_service toneMint
class node_prisma,node_pwa,node_netlify,node_caddy toneRose
class node_browser toneNeutral
```

## Components

### Next.js Web App

App Router UI and request boundary.

- [Request middleware](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/middleware.ts): Next middleware · Applies cross-cutting request controls. · `src/middleware.ts`
- [Root layout](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/layout.tsx): React layout · Global rendering and application setup. · `src/app/layout.tsx`
- [Home entry](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/page.tsx): App Router page · `src/app/page.tsx`
- [Auth & dashboard routes](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/(auth)/layout.tsx): route layouts · Separates authentication and dashboard experiences. · `src/app/(auth)/layout.tsx`
- [AI feature routes](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/ai/layout.tsx): feature layout · `src/app/ai/layout.tsx`
- [Messaging UI](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/components/views/messaging-view.tsx): view component · `src/components/views/messaging-view.tsx`
- [AI chat UI](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/components/ai/ai-chat/ai-chat.tsx): feature component · `src/components/ai/ai-chat/ai-chat.tsx`
- [Domain API routes](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/app/api/messaging/conversations/route.ts): App Router handlers · Server boundary for auth, AI, messaging, storage, payments, and administration. · `src/app/api/messaging/conversations/route.ts`

### Domain Layer

Feature services, state, and policy.

- [API pipeline](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/api/api.pipeline.ts): request pipeline · Shared authentication, validation, caching, retry, timeout, and response handling. · `src/lib/api/api.pipeline.ts`
- [Security controls](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/security/security.ts): security layer · CSRF, SSRF, sanitization, upload validation, auditing, and rate limits. · `src/lib/security/security.ts`
- [Permission engine](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/permissions/PermissionEngine.ts): authorization · Enforces browser/device and role or policy permissions. · `src/lib/permissions/PermissionEngine.ts`
- [Feature services](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/services/ai/chat.service.ts): domain services · Contracts and operations for AI, messaging, payments, storage, search, and media. · `src/lib/services/ai/chat.service.ts`
- [Messaging state](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/providers/messaging/messaging.provider.ts): provider and store · Exposes messaging state and client operations to views. · `src/providers/messaging/messaging.provider.ts`
- [Messaging hook](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/hooks/messaging/use-messaging.ts): React hook · `src/hooks/messaging/use-messaging.ts`

### Realtime Services

Long-lived messaging and call processes.

- [Messaging socket](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/src/lib/messaging-socket.ts): realtime gateway · Connects web messaging to long-lived socket behavior. · `src/lib/messaging-socket.ts`
- [Messaging microservice](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/mini-services/messaging-service/index.ts): Node microservice · Standalone realtime messaging process. · `mini-services/messaging-service/index.ts`

### Data & Operations

Persistence and deployment assets.

- [Prisma database model](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/prisma/schema.prisma): persistence schema · Database schema with migration, seed, backup, and restore workflows. · `prisma/schema.prisma`
- [PWA service worker](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/public/sw.js): service worker · Provides offline and installable web behavior. · `public/sw.js`
- [Netlify deployment](https://github.com/aamnaqueen94-dotcom/supperweb-ai/blob/main/netlify.toml): deployment config · `netlify.toml`
- [Caddy proxy option](https://github.com/aamnaqueen94-dotcom/supperweb-ai/tree/main/caddyfile): reverse proxy config · `caddyfile`

### Other components

- **Browser clients**: client

## Connections

- Browser clients → Request middleware: requests
- Request middleware → Root layout: renders app
- Root layout → Home entry: hosts
- Root layout → Auth & dashboard routes: composes
- Root layout → AI feature routes: composes
- Auth & dashboard routes → Messaging UI: renders
- AI feature routes → AI chat UI: renders
- Messaging UI → Messaging hook: uses
- Messaging hook → Messaging state: reads and updates
- AI chat UI → Feature services: invokes
- Browser clients → Domain API routes: HTTP calls
- Domain API routes → API pipeline: runs through
- API pipeline → Security controls: applies
- API pipeline → Permission engine: authorizes
- API pipeline → Feature services: dispatches
- Feature services → Prisma database model: persists
- Messaging state → Messaging socket: realtime events
- Messaging socket → Messaging microservice: connects to
- Messaging microservice → Prisma database model: stores messages
- Browser clients → PWA service worker: registers
- Netlify deployment → Root layout: deploys
- Caddy proxy option → Request middleware: optional proxy
