How inkyulim0215-sudo/ai-security-analyzer works
Purpose and Runtime
AI Security Log Analyzer is a Next.js 15 App Router application that lets authenticated users upload network-log files, persist them in Supabase, and request AI-generated threat analysis. It runs as a TypeScript web application, styled with Tailwind CSS, typically deployed on Vercel. Core external services are Supabase (Auth, PostgreSQL, Storage) and Groq’s Llama 3.3 70B API.
Application Entry and Route Topology
The root application shell and landing entry are app/layout.tsx and app/page.tsx. Public authentication screens are served from app/(auth)/login/page.tsx and app/(auth)/signup/page.tsx.
Authenticated workflow pages are grouped under app/(protected), with shared protection/layout behavior in app/(protected)/layout.tsx. The principal user journey is dashboard → upload → analysis detail:
• app/(protected)/dashboard/page.tsx
• app/(protected)/upload/page.tsx
• app/(protected)/analysis/[id]/page.tsx
Authentication and Access Boundary
Supabase Auth provides signup, login, logout, and cookie-backed session state. middleware.ts is the application-wide route gate, enforcing access boundaries before protected pages or flows execute. Browser, server, and privileged Supabase client contexts are separated under:
• lib/supabase/client.ts
• lib/supabase/server.ts
• lib/supabase/admin.ts
The admin client is an important trust boundary because it uses the service-role credential; it should remain server-only. At the data layer, Supabase RLS limits analyses rows to their owning user_id.
Upload and Persistence Stage
The upload UI is implemented by components/FileUploader.tsx and rendered from app/(protected)/upload/page.tsx. It submits multipart FormData to app/api/upload/route.ts.
That endpoint validates/handles a log file, stores its content in the Supabase log-files Storage bucket, and creates a pending analyses database record containing file identity, storage path, size, owner, and status. This creates the durable handoff between file ingestion and AI processing.
AI Analysis Stage
app/(protected)/analysis/[id]/page.tsx displays a specific persisted analysis and initiates processing through components/AnalyzeButton.tsx. The request reaches app/api/analyze/route.ts.
The analysis route is the central orchestration boundary: it resolves the user-owned analysis record, accesses the uploaded file through Supabase Storage, sends log content to Groq, parses the structured AI output, and updates the database record. Analysis state transitions are represented by the analyses.status lifecycle: pending, analyzing, done, or error. Persisted output includes threat level, summary, detected threats, and raw model result.
Read Models and Presentation
The dashboard at app/(protected)/dashboard/page.tsx is the history/read model for a user’s analyses; the README identifies it as a Server Component that reads Supabase directly. The dynamic analysis page is the detailed result view. Reusable presentation controls include:
• components/ThreatBadge.tsx
• components/AnalyzeButton.tsx
• components/LogoutButton.tsx
These pages should rely on authenticated server context and RLS-scoped queries rather than accepting arbitrary user IDs from clients.
Primary Control Flow
1. User authenticates through public auth routes; session is maintained via Supabase cookies.
2. middleware.ts permits or redirects requests based on session/protected-route status.
3. User uploads a supported log file through the upload page; /api/upload writes Storage plus a pending database row.
4. User opens /analysis/[id]; the page loads the owned record and calls /api/analyze.
5. /api/analyze retrieves file data, invokes Groq, persists normalized results, and the UI renders threat level, summary, and threat list.
6. Dashboard queries the user-scoped analyses history.
Main entry points: route.ts Analysis orchestrator · layout.tsx Protected layout · admin.ts Supabase client contexts · page.tsx Analysis detail
Components 16
Public access
- Login & signup
app/(auth)/login/page.tsx
Authenticated application
- Protected layout
app/(protected)/layout.tsx - Analysis dashboard · Shows the authenticated user's analysis history.
app/(protected)/dashboard/page.tsx - Upload page
app/(protected)/upload/page.tsx - File uploader
components/FileUploader.tsx - Analysis detail
app/(protected)/analysis/[id]/page.tsx - Analyze button
components/AnalyzeButton.tsx
Server API
- Upload endpoint · Stores file content and creates a pending analysis handoff.
app/api/upload/route.ts - Analysis orchestrator · Loads owned input, invokes AI, and persists normalized results.
app/api/analyze/route.ts
Supabase platform
Auth, RLS-scoped data, and uploaded files.
- Supabase Auth · Provides sessions through cookies.
- Supabase client contexts · Admin service-role client is server-only.
lib/supabase/admin.ts - log-files bucket · Stores uploaded network-log content.
- analyses records · RLS restricts rows to their owning user; status tracks processing.
Other components
- App shell
app/layout.tsx - Route gate · Redirects based on cookie-backed session and route access.
middleware.ts - Groq Llama 3.3 70B
Connections 22
- App shell → Login & signup: renders public routes
- Route gate → Protected layout: permits authenticated requests
- Login & signup → Supabase Auth: signs up and logs in
- Supabase Auth → Route gate: session cookies
- Protected layout → Analysis dashboard: hosts
- Protected layout → Upload page: hosts
- Protected layout → Analysis detail: hosts
- Upload page → File uploader: renders
- File uploader → Upload endpoint: multipart FormData
- Upload endpoint → log-files bucket: writes log file
- Upload endpoint → analyses records: creates pending record
- Analysis detail → Analyze button: initiates processing
- Analyze button → Analysis orchestrator: requests analysis
- Analysis orchestrator → log-files bucket: reads uploaded log
- Analysis orchestrator → Groq Llama 3.3 70B: submits log content
- Groq Llama 3.3 70B → Analysis orchestrator: structured threat result
- Analysis orchestrator → analyses records: updates lifecycle and results
- Analysis dashboard → analyses records: queries user history
- Analysis detail → analyses records: loads owned result
- Supabase client contexts → Supabase Auth: uses auth context
- Supabase client contexts → log-files bucket: accesses storage
- Supabase client contexts → analyses records: queries under RLS