# inkyulim0215-sudo/ai-security-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/inkyulim0215-sudo/ai-security-analyzer
- Repository: https://github.com/inkyulim0215-sudo/ai-security-analyzer

## Overview

#### 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: [`app/api/analyze/route.ts`](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/api/analyze/route.ts) (Analysis orchestrator), [`app/(protected)/layout.tsx`](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/layout.tsx) (Protected layout), [`lib/supabase/admin.ts`](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/lib/supabase/admin.ts) (Supabase client contexts), [`app/(protected)/analysis/[id]/page.tsx`](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/analysis/%5Bid%5D/page.tsx) (Analysis detail)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public access"]
  node_auth_pages["Login &amp; signup<br/>public pages<br/>[page.tsx]"]
end

subgraph group_protected["Authenticated application"]
  node_protected_layout["Protected layout<br/>access layout<br/>[layout.tsx]"]
  node_dashboard["Analysis dashboard<br/>server read model<br/>[page.tsx]"]
  node_upload_page["Upload page<br/>workflow page<br/>[page.tsx]"]
  node_file_uploader["File uploader<br/>client component<br/>[FileUploader.tsx]"]
  node_analysis_page["Analysis detail<br/>dynamic result page<br/>[page.tsx]"]
  node_analyze_button["Analyze button<br/>client component<br/>[AnalyzeButton.tsx]"]
end

subgraph group_api["Server API"]
  node_upload_api{{"Upload endpoint<br/>multipart API route<br/>[route.ts]"}}
  node_analyze_api{{"Analysis orchestrator<br/>API route<br/>[route.ts]"}}
end

subgraph group_supabase["Supabase platform"]
  node_supabase_auth(("Supabase Auth<br/>identity service"))
  node_supabase_clients["Supabase client contexts<br/>browser, server, admin<br/>[admin.ts]"]
  node_storage[("log-files bucket<br/>Supabase Storage")]
  node_analyses[("analyses records<br/>Supabase PostgreSQL")]
end

node_app_shell["App shell<br/>Next.js layout<br/>[layout.tsx]"]
node_middleware{{"Route gate<br/>Next.js middleware<br/>[middleware.ts]"}}
node_groq(("Groq Llama 3.3 70B<br/>AI inference API"))

node_app_shell -->|"renders public routes"| node_auth_pages
node_middleware -->|"permits authenticated requests"| node_protected_layout
node_auth_pages -->|"signs up and logs in"| node_supabase_auth
node_supabase_auth -->|"session cookies"| node_middleware
node_protected_layout -->|"hosts"| node_dashboard
node_protected_layout -->|"hosts"| node_upload_page
node_protected_layout -->|"hosts"| node_analysis_page
node_upload_page -->|"renders"| node_file_uploader
node_file_uploader -->|"multipart FormData"| node_upload_api
node_upload_api -->|"writes log file"| node_storage
node_upload_api -->|"creates pending record"| node_analyses
node_analysis_page -->|"initiates processing"| node_analyze_button
node_analyze_button -->|"requests analysis"| node_analyze_api
node_analyze_api -->|"reads uploaded log"| node_storage
node_analyze_api -->|"submits log content"| node_groq
node_groq -->|"structured threat result"| node_analyze_api
node_analyze_api -->|"updates lifecycle and results"| node_analyses
node_dashboard -->|"queries user history"| node_analyses
node_analysis_page -->|"loads owned result"| node_analyses
node_supabase_clients -.->|"uses auth context"| node_supabase_auth
node_supabase_clients -.->|"accesses storage"| node_storage
node_supabase_clients -.->|"queries under RLS"| node_analyses

click node_app_shell "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/layout.tsx"
click node_auth_pages "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(auth)/login/page.tsx"
click node_middleware "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/middleware.ts"
click node_protected_layout "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/layout.tsx"
click node_dashboard "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/dashboard/page.tsx"
click node_upload_page "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/upload/page.tsx"
click node_file_uploader "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/components/FileUploader.tsx"
click node_analysis_page "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/analysis/%5Bid%5D/page.tsx"
click node_analyze_button "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/components/AnalyzeButton.tsx"
click node_upload_api "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/api/upload/route.ts"
click node_analyze_api "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/api/analyze/route.ts"
click node_supabase_clients "https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/lib/supabase/admin.ts"

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_auth_pages toneBlue
class node_protected_layout,node_dashboard,node_upload_page,node_file_uploader,node_analysis_page,node_analyze_button toneAmber
class node_upload_api,node_analyze_api toneMint
class node_supabase_auth,node_supabase_clients,node_storage,node_analyses toneRose
class node_app_shell,node_middleware,node_groq toneNeutral
```

## Components

### Public access

- [Login & signup](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(auth)/login/page.tsx): public pages · `app/(auth)/login/page.tsx`

### Authenticated application

- [Protected layout](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/layout.tsx): access layout · `app/(protected)/layout.tsx`
- [Analysis dashboard](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/dashboard/page.tsx): server read model · Shows the authenticated user's analysis history. · `app/(protected)/dashboard/page.tsx`
- [Upload page](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/upload/page.tsx): workflow page · `app/(protected)/upload/page.tsx`
- [File uploader](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/components/FileUploader.tsx): client component · `components/FileUploader.tsx`
- [Analysis detail](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/(protected)/analysis/%5Bid%5D/page.tsx): dynamic result page · `app/(protected)/analysis/[id]/page.tsx`
- [Analyze button](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/components/AnalyzeButton.tsx): client component · `components/AnalyzeButton.tsx`

### Server API

- [Upload endpoint](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/api/upload/route.ts): multipart API route · Stores file content and creates a pending analysis handoff. · `app/api/upload/route.ts`
- [Analysis orchestrator](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/api/analyze/route.ts): API route · 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**: identity service · Provides sessions through cookies.
- [Supabase client contexts](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/lib/supabase/admin.ts): browser, server, admin · Admin service-role client is server-only. · `lib/supabase/admin.ts`
- **log-files bucket**: Supabase Storage · Stores uploaded network-log content.
- **analyses records**: Supabase PostgreSQL · RLS restricts rows to their owning user; status tracks processing.

### Other components

- [App shell](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/app/layout.tsx): Next.js layout · `app/layout.tsx`
- [Route gate](https://github.com/inkyulim0215-sudo/ai-security-analyzer/blob/main/middleware.ts): Next.js middleware · Redirects based on cookie-backed session and route access. · `middleware.ts`
- **Groq Llama 3.3 70B**: AI inference API

## Connections

- 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
