# polotorom-debug/worm-ai architecture

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

- Interactive diagram: https://gitdiagram.com/polotorom-debug/worm-ai
- Repository: https://github.com/polotorom-debug/worm-ai

## Overview

1. **Overall shape**
   - This is a **client-side React application** built with **Vite**. The architecture is centered around a browser UI, with no backend service visible in the repo tree.
   - The app is organized into three main layers: **pages/UI**, **application logic/hooks**, and **shared services/provider adapters**.

2. **Bootstrapping and routing**
   - `src/main.jsx` is the entry point and mounts the React app.
   - `src/App.jsx` is the top-level composition/routing layer that decides which page is shown.
   - The primary user-facing routes are the pages under `src/pages/`, including landing, auth, dashboard, chat, settings, profile, admin, and docs.

3. **Presentation layer**
   - `src/components/` contains the reusable UI shell and layout primitives:
     - `Layout.jsx` for the app frame
     - `Header.jsx` and `Sidebar.jsx` for navigation/chrome
     - `components/ui/` for base design-system components
   - The project uses a **shadcn/ui-style component set** plus **Tailwind CSS** for styling, so the UI is assembled from small composable primitives rather than a large monolithic widget layer.

4. **Authentication boundary**
   - Authentication is handled through `src/hooks/useAuth.js` and `src/lib/auth.js`.
   - The auth layer appears to manage login state, user identity, and role separation between **admin** and **regular user**.
   - Demo credentials in the README suggest the app supports a local/demo auth mode rather than relying only on an external identity provider.

5. **Data persistence and local state**
   - `src/lib/db.js` is the main persistence abstraction, likely for local/browser-side storage of user/session/conversation data.
   - `src/lib/cache.js` provides a separate caching layer for reducing repeated work or repeated provider calls.
   - `src/lib/logger.js` captures operational/audit events, which is important for the admin workflow.
   - These modules form the app’s internal state boundary; they are the shared data services used by the rest of the app.

6. **Chat subsystem**
   - `src/hooks/useChat.js` is the orchestration hook for the chat experience.
   - The `Chat.jsx` page is the main consumer of this hook and likely drives conversation history, model selection, and message submission.
   - The chat subsystem depends on provider adapters, local persistence, and caching, making it the most integration-heavy part of the app.

7. **LLM provider abstraction**
   - `src/providers/` is a clear adapter layer that normalizes multiple model backends:
     - `openai/`
     - `anthropic/`
     - `google/`
     - `local/` for Ollama
     - `custom/` for arbitrary endpoints
   - `src/providers/index.js` acts as the provider registry/factory, so the rest of the app can switch providers without changing UI logic.
   - Each provider has its own client module and wrapper, which keeps vendor-specific API details isolated.

8. **External integrations**
   - The app can call **OpenAI**, **Anthropic**, **Google Gemini**, or **local Ollama** depending on configuration.
   - The README shows these are configured through environment variables, so provider selection is runtime-configurable.
   - This means the system has two external boundaries: **cloud AI APIs** and **local model serving** via Ollama.

9. **Security and content policy**
   - The product is explicitly positioned as **defensive cybersecurity only**.
   - The guardrails are part of the application architecture, not just product copy: the chat/provider layers are expected to restrict outputs to ethical, defensive content and block malicious requests.
   - That policy boundary is central to the app’s purpose and likely influences prompt construction and response filtering.

10. **Admin and observability**
   - `src/pages/Admin.jsx` is the operational control surface, likely consuming logs and user/system data.
   - `logger.js` plus the admin page create an internal observability path for reviewing activity.
   - This is distinct from end-user chat and indicates the app has a lightweight governance/monitoring subsystem.

11. **Configuration and settings**
   - `Settings.jsx` is the user-facing configuration surface for model/provider preferences and API key management.
   - `src/lib/app-params.js` suggests central app configuration values are separated from feature logic.
   - Environment-driven setup in the README means the app’s runtime behavior is heavily parameterized rather than hardcoded.

12. **Legacy boundary**
   - `src/API/base44Client.js` is called out as **legacy**, which implies there was an older backend/client integration path.
   - Architecturally, this should be treated as a separate compatibility boundary rather than the primary app path.

13. **Operational flow summary**
   - A user enters through landing/login/register, gets authenticated, and lands in the dashboard/chat shell.
   - Chat requests flow from page → `useChat` → provider registry → provider client → external API or local Ollama.
   - Results and metadata can be cached, stored in local DB/state, and surfaced to dashboard/admin views through the shared lib layer.

14. **What to draw as the main boxes**
   - For an architecture diagram, the key boxes are:
     - **React/Vite UI shell**
     - **Auth and local persistence services**
     - **Chat orchestration hook**
     - **Provider adapter layer**
     - **External AI providers / Ollama**
     - **Admin/logging surface**
   - The strongest architectural boundary is between the **browser app** and the **LLM provider backends**, with the provider abstraction insulating the UI from vendor specifics.

Main entry points: [`src/pages`](https://github.com/polotorom-debug/worm-ai/tree/main/src/pages) (Pages), [`src/providers/index.js`](https://github.com/polotorom-debug/worm-ai/blob/main/src/providers/index.js) (Provider registry), [`src/hooks/useChat.js`](https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useChat.js) (useChat), [`src/hooks/useAuth.js`](https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useAuth.js) (useAuth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI shell"]
  node_main(("main<br/>entry<br/>[main.jsx]"))
  node_app["App<br/>router<br/>[App.jsx]"]
  node_layout["Layout<br/>shell<br/>[Layout.jsx]"]
  node_header["Header<br/>nav<br/>[Header.jsx]"]
  node_sidebar["Sidebar<br/>nav<br/>[Sidebar.jsx]"]
  node_pages["Pages<br/>screens"]
  node_uiatoms["UI atoms<br/>design system"]
end

subgraph group_logic["App logic"]
  node_useauth(("useAuth<br/>hook<br/>[useAuth.js]"))
  node_usechat(("useChat<br/>hook<br/>[useChat.js]"))
end

subgraph group_services["Shared services"]
  node_authlib["Auth lib<br/>auth service<br/>[auth.js]"]
  node_db[("DB<br/>local storage<br/>[db.js]")]
  node_cache["Cache<br/>[cache.js]"]
  node_logger["Logger<br/>audit log<br/>[logger.js]"]
  node_params["App params<br/>config<br/>[app-params.js]"]
end

subgraph group_providers["Model adapters"]
  node_registry["Provider registry<br/>factory<br/>[index.js]"]
  node_openai["OpenAI<br/>provider adapter"]
  node_anthropic["Anthropic<br/>provider adapter"]
  node_google["Google<br/>provider adapter"]
  node_local["Local<br/>provider adapter"]
  node_custom["Custom<br/>provider adapter"]
end

subgraph group_external["External systems"]
  node_browser(("Browser<br/>runtime"))
  node_cloudapis{{"Cloud AI APIs<br/>external api"}}
  node_ollama{{"Ollama<br/>local runtime"}}
  node_legacy["Legacy API<br/>compat boundary<br/>[base44Client.js]"]
end

node_browser -->|"loads"| node_main
node_main -->|"mounts"| node_app
node_app -->|"wraps"| node_layout
node_layout -->|"contains"| node_header
node_layout -->|"contains"| node_sidebar
node_app -->|"routes"| node_pages
node_pages -->|"composes"| node_uiatoms
node_useauth -->|"uses"| node_authlib
node_useauth -->|"reads/writes"| node_db
node_useauth -->|"emits"| node_logger
node_usechat -->|"stores"| node_db
node_usechat -->|"caches"| node_cache
node_usechat -->|"emits"| node_logger
node_usechat -->|"selects"| node_registry
node_registry -->|"adapts"| node_openai
node_registry -->|"adapts"| node_anthropic
node_registry -->|"adapts"| node_google
node_registry -->|"adapts"| node_local
node_registry -->|"adapts"| node_custom
node_openai -->|"calls"| node_cloudapis
node_anthropic -->|"calls"| node_cloudapis
node_google -->|"calls"| node_cloudapis
node_local -->|"calls"| node_ollama
node_custom -->|"calls"| node_cloudapis
node_pages -->|"consumes"| node_useauth
node_pages -->|"consumes"| node_usechat
node_pages -->|"configures"| node_params
node_pages -->|"reviews"| node_logger
node_legacy -.->|"integrates"| node_db

click node_main "https://github.com/polotorom-debug/worm-ai/blob/main/src/main.jsx"
click node_app "https://github.com/polotorom-debug/worm-ai/blob/main/src/App.jsx"
click node_layout "https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Layout.jsx"
click node_header "https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Header.jsx"
click node_sidebar "https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Sidebar.jsx"
click node_pages "https://github.com/polotorom-debug/worm-ai/tree/main/src/pages"
click node_uiatoms "https://github.com/polotorom-debug/worm-ai/tree/main/src/components/ui"
click node_useauth "https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useAuth.js"
click node_usechat "https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useChat.js"
click node_authlib "https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/auth.js"
click node_db "https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/db.js"
click node_cache "https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/cache.js"
click node_logger "https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/logger.js"
click node_params "https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/app-params.js"
click node_registry "https://github.com/polotorom-debug/worm-ai/blob/main/src/providers/index.js"
click node_openai "https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/openai"
click node_anthropic "https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/anthropic"
click node_google "https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/google"
click node_local "https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/local"
click node_custom "https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/custom"
click node_legacy "https://github.com/polotorom-debug/worm-ai/blob/main/src/API/base44Client.js"

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_main,node_app,node_layout,node_header,node_sidebar,node_pages,node_uiatoms toneBlue
class node_useauth,node_usechat toneAmber
class node_authlib,node_db,node_cache,node_logger,node_params toneMint
class node_registry,node_openai,node_anthropic,node_google,node_local,node_custom toneRose
class node_browser,node_cloudapis,node_ollama,node_legacy toneIndigo
```

## Components

### UI shell

React views, layout, and shared visual components

- [main](https://github.com/polotorom-debug/worm-ai/blob/main/src/main.jsx): entry · Bootstraps the React app in the browser. · `src/main.jsx`
- [App](https://github.com/polotorom-debug/worm-ai/blob/main/src/App.jsx): router · Top-level composition and route selection. · `src/App.jsx`
- [Layout](https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Layout.jsx): shell · Shared application frame and chrome. · `src/components/Layout.jsx`
- [Header](https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Header.jsx): nav · Top navigation and user controls. · `src/components/Header.jsx`
- [Sidebar](https://github.com/polotorom-debug/worm-ai/blob/main/src/components/Sidebar.jsx): nav · Primary navigation and section switching. · `src/components/Sidebar.jsx`
- [Pages](https://github.com/polotorom-debug/worm-ai/tree/main/src/pages): screens · Landing, auth, dashboard, chat, settings, profile, admin, and docs views. · `src/pages`
- [UI atoms](https://github.com/polotorom-debug/worm-ai/tree/main/src/components/ui): design system · Reusable shadcn-style primitives built on Tailwind. · `src/components/ui`

### App logic

Hooks and app-level orchestration

- [useAuth](https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useAuth.js): hook · Auth state and identity orchestration. · `src/hooks/useAuth.js`
- [useChat](https://github.com/polotorom-debug/worm-ai/blob/main/src/hooks/useChat.js): hook · Conversation orchestration for the chat experience. · `src/hooks/useChat.js`

### Shared services

Local persistence, auth, caching, and logging

- [Auth lib](https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/auth.js): auth service · Credential handling and auth helpers. · `src/lib/auth.js`
- [DB](https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/db.js): local storage · Browser-side persistence for app data. · `src/lib/db.js`
- [Cache](https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/cache.js): cache · Local caching layer for repeated work and provider calls. · `src/lib/cache.js`
- [Logger](https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/logger.js): audit log · Operational and activity logging for admin visibility. · `src/lib/logger.js`
- [App params](https://github.com/polotorom-debug/worm-ai/blob/main/src/lib/app-params.js): config · Central runtime configuration values. · `src/lib/app-params.js`

### Model adapters

Provider registry and vendor-specific clients

- [Provider registry](https://github.com/polotorom-debug/worm-ai/blob/main/src/providers/index.js): factory · Selects and normalizes model providers. · `src/providers/index.js`
- [OpenAI](https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/openai): provider adapter · Adapter for OpenAI models. · `src/providers/openai`
- [Anthropic](https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/anthropic): provider adapter · Adapter for Anthropic models. · `src/providers/anthropic`
- [Google](https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/google): provider adapter · Adapter for Gemini models. · `src/providers/google`
- [Local](https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/local): provider adapter · Adapter for local Ollama models. · `src/providers/local`
- [Custom](https://github.com/polotorom-debug/worm-ai/tree/main/src/providers/custom): provider adapter · Adapter for arbitrary endpoint providers. · `src/providers/custom`

### External systems

Browser, local model runtime, and cloud AI APIs

- **Browser**: runtime · Client-side React/Vite execution environment.
- **Cloud AI APIs**: external api · OpenAI, Anthropic, and Google model services.
- **Ollama**: local runtime · Local model serving backend.
- [Legacy API](https://github.com/polotorom-debug/worm-ai/blob/main/src/API/base44Client.js): compat boundary · Older Base44 integration path kept for compatibility. · `src/API/base44Client.js`

## Connections

- Browser → main: loads · The browser starts the application bundle.
- main → App: mounts · Entry point mounts the routed app shell.
- App → Layout: wraps · Routes are rendered inside the shared frame.
- Layout → Header: contains · Layout includes top navigation.
- Layout → Sidebar: contains · Layout includes primary navigation.
- App → Pages: routes · Top-level route switching selects pages.
- Pages → UI atoms: composes · Pages are built from shared UI primitives.
- useAuth → Auth lib: uses · Auth hook delegates identity logic to auth helpers.
- useAuth → DB: reads/writes · Auth state is persisted locally.
- useAuth → Logger: emits · Auth events can be recorded for audit and admin workflows.
- useChat → DB: stores · Conversation state and metadata are persisted locally.
- useChat → Cache: caches · Chat results and repeated calls are cached.
- useChat → Logger: emits · Chat activity can be logged for operational review.
- useChat → Provider registry: selects · Chat orchestration resolves the active model provider.
- Provider registry → OpenAI: adapts · Registry can route to OpenAI adapter.
- Provider registry → Anthropic: adapts · Registry can route to Anthropic adapter.
- Provider registry → Google: adapts · Registry can route to Google adapter.
- Provider registry → Local: adapts · Registry can route to local Ollama adapter.
- Provider registry → Custom: adapts · Registry can route to custom endpoint adapter.
- OpenAI → Cloud AI APIs: calls · OpenAI adapter connects to external API services.
- Anthropic → Cloud AI APIs: calls · Anthropic adapter connects to external API services.
- Google → Cloud AI APIs: calls · Google adapter connects to external API services.
- Local → Ollama: calls · Local adapter connects to on-device or LAN model serving.
- Custom → Cloud AI APIs: calls · Custom adapter can target arbitrary remote endpoints.
- Pages → useAuth: consumes · Auth pages and protected views depend on auth state.
- Pages → useChat: consumes · Chat page drives conversation orchestration.
- Pages → App params: configures · Settings and app flows read central runtime parameters.
- Pages → Logger: reviews · Admin views surface logged activity.
- Legacy API → DB: integrates · Legacy client sits beside the current local state boundary.
