How oshekharo/cyber-ai works
Purpose and Entry Points
Cyber AI is a React/TypeScript single-page cybersecurity assistant: authenticated users run multi-session AI chats; administrators manage Supabase users and roles. The browser bootstraps at src/main.tsx, renders application routing/state through src/App.tsx, and calls serverless admin APIs under api/. Vite builds the frontend; vercel.json supports Vercel deployment.
Application Shell and Access Control
src/App.tsx is the top-level gate: it selects authentication, chat workspace, or admin views based on auth state and role. src/hooks/useAuth.ts owns session lifecycle—sign-up, sign-in, sign-out, and user/role resolution—against the configured Supabase client in src/lib/supabase.ts. src/components/AuthScreen.tsx is the credential UI; src/components/AdminDashboard.tsx is restricted to administrators.
Chat State and Session Boundary
src/hooks/useChat.ts is the client-side chat domain layer. It manages conversation sessions, active-session selection, messages, streaming/loading state, and actions such as create/delete/rename/export/search. Per the design, sessions and conversations persist in browser localStorage, separating conversational state from Supabase-backed identity. The workspace composition is rooted at src/components/ChatWorkspace.tsx, with session navigation in src/components/Sidebar.tsx.
AI Request Flow
Message submission travels from src/components/InputBar.tsx through chat-state actions in src/hooks/useChat.ts to src/api/chat.ts. That client calls the configurable primary /api/chat backend (VITE_API_URL), which is external to this repository, and supports a Brave Search fallback using a browser-provided token. Returned/streamed assistant content is incorporated into the active local session and displayed through src/components/MessageList.tsx and src/components/MessageBubble.tsx.
User Interaction Layer
src/components/ChatWorkspace.tsx coordinates the responsive workspace: sidebar/session controls, message rendering, input, error state, and auxiliary search/command surfaces. src/components/CommandPalette.tsx exposes chat-oriented slash actions, while src/components/MessageSearch.tsx searches the current conversation. Rendering supports Markdown/GFM and syntax highlighting; message-level copy, feedback, and regeneration remain UI actions over the active chat state.
Identity, Database, and Privileged APIs
Supabase provides email/password authentication and PostgreSQL-backed authorization data. Its expected tables, role model, and RLS policies are defined in supabase/schema.sql. Browser code uses the anon-key Supabase client; privileged user enumeration, role update, and account deletion are isolated in api/admin/users.ts, which requires server-side SUPABASE_SERVICE_ROLE_KEY. This is the principal trust boundary: service-role credentials must never reach Vite client code.
Runtime and Deployment Boundaries
The frontend runs as a Vite SPA (React 19, TypeScript) and requires Node.js 18+ for development/build. Supabase is the managed auth/database service. /api/chat is an independently deployed AI backend, optionally hosted on Render; Brave Search is an optional external fallback. Vercel can serve the static app and api/admin/users.ts serverless endpoint, while deployment configuration resides in vercel.json.
Main entry points: App.tsx App gate · ChatWorkspace.tsx Chat workspace · useChat.ts Chat domain state · chat.ts AI request client
Components 20
Browser SPA
Vite-built React application.
- Browser bootstrap
src/main.tsx - App gate · Selects auth, chat, or admin views by session and role.
src/App.tsx - Auth lifecycle · Manages sign-in, sign-up, sign-out, and role resolution.
src/hooks/useAuth.ts - Auth screen
src/components/AuthScreen.tsx - Chat workspace · Coordinates sessions, messages, input, and auxiliary chat surfaces.
src/components/ChatWorkspace.tsx - Chat domain state · Owns local sessions, active conversation, messages, and streaming state.
src/hooks/useChat.ts - Conversation storage · Persists sessions and conversations separately from identity.
- Session navigation
src/components/Sidebar.tsx - Message input
src/components/InputBar.tsx - Message rendering · Renders assistant and user messages with Markdown and syntax highlighting.
src/components/MessageList.tsx - Message actions · Provides copy, feedback, and regeneration actions.
src/components/MessageBubble.tsx - AI request client · Calls the configurable chat backend and supports Brave fallback.
src/api/chat.ts - Admin dashboard
src/components/AdminDashboard.tsx - Supabase client
src/lib/supabase.ts
Supabase
Managed identity and authorization data.
- Auth and PostgreSQL
- Role schema and RLS · Defines authorization tables, roles, and row-level policies.
supabase/schema.sql
External Services
- AI chat backend · Independently deployed endpoint addressed by VITE_API_URL.
- Brave Search
Vercel
Static hosting and serverless runtime.
- Admin users API · Uses service-role credentials for user and role administration.
api/admin/users.ts - Deployment routing
vercel.json
Connections 23
- Browser bootstrap → App gate: renders
- App gate → Auth lifecycle: uses
- App gate → Auth screen: shows when signed out
- App gate → Chat workspace: shows for users
- App gate → Admin dashboard: shows for admins
- Auth screen → Auth lifecycle: submits credentials
- Auth lifecycle → Supabase client: authenticates through
- Supabase client → Auth and PostgreSQL: uses anon access
- Role schema and RLS → Auth and PostgreSQL: defines
- Chat workspace → Chat domain state: coordinates
- Chat workspace → Session navigation: composes
- Chat workspace → Message input: composes
- Chat workspace → Message rendering: composes
- Message rendering → Message actions: renders
- Message input → Chat domain state: submits message
- Chat domain state → Conversation storage: persists sessions
- Chat domain state → AI request client: sends prompt
- AI request client → AI chat backend: calls /api/chat
- AI request client → Brave Search: fallback search
- Admin dashboard → Admin users API: admin operations
- Admin users API → Auth and PostgreSQL: service-role access · Privileged server-side boundary.
- Deployment routing → Admin users API: deploys
- Deployment routing → Browser bootstrap: serves SPA