# surjendu104/logsloth architecture

> Architecture diagram of the GitHub repository surjendu104/logsloth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/surjendu104/logsloth
- Repository: https://github.com/surjendu104/logsloth

## Overview

##### Project type and purpose
- LogSloth is a client-side, single-page application (SPA) built with React and TypeScript, bundled via Vite.
- Its purpose is privacy-first log analysis and visualization: users upload log files (Apache, Nginx, Gunicorn, etc.) and explore metrics entirely in their browser.

##### File structure
- Top-level:
- index.html, package.json, vite.config.ts – SPA entry and build config
- public/ – static assets and demo logs
- src/ – application source
- src/components/LogAnalysis – one directory per log-type, each containing:
– FileUpload.tsx / parser.ts / period.ts (ingestion & preprocessing)
– RawAccessLogViewer, RawErrorLogViewer (raw text)
– PiiDataLeakDetection, SuspeciousIPs, MalFormedRequests (analysis modules)
– Charts/ (a set of reusable chart components)
- src/context/LogContext.tsx & hooks/useLogContext.tsx – global state for parsed logs
- src/App.tsx & src/components/Header.tsx – top-level layout & navigation
- Config files: tsconfig, eslint.config.js, prettier, vercel.json – deployment and tooling.

##### README for additional insights
- Emphasizes client-only processing (“all processed completely on your machine”)
- Main features: file upload, instant exploration, dashboards.

a. Main components:
- Browser (Client)
- UI Layer (React Components)
- In-Browser Processing Engine
– File Upload Module
– Parser Modules (per log type)
– Period grouping & preprocessing
- Visualization Layer (Chart Components)
- State Management (LogContext)
- Static Hosting (Vercel/CDN)
b. Relationships & interactions:
1. User clicks “Upload” → FileUpload component reads file via FileReader API.
2. File contents passed to the correct parser.ts → produces structured records.
3. Period.ts groups records (e.g., by time intervals).
4. Parsed data stored in LogContext → accessible by any analysis & chart components.
5. Analysis modules (PiiDataLeakDetection, MalFormedRequests, etc.) consume context data and derive metrics.
6. Chart components subscribe to LogContext and render graphs.
7. Header & navigation components allow switching between log-type pages.
c. Architectural patterns & design principles:
- Component-based UI (React)
- Context API for state sharing (avoids prop drilling)
- Modular parser/analysis per log type (extensible pattern)
- Client-only, zero-trust model (no backend calls)
d. Key technologies:
- React + TypeScript + Vite
- Browser FileReader API
- CSS modules for styling
- Vercel for static deployment

## Diagram (Mermaid)

```mermaid
graph TB

    subgraph "Browser (Client)"
        Bindex["index.html"]:::infra
        Bmain["src/main.tsx"]:::infra
    end

    subgraph "UI Layer"
        App["App.tsx"]:::ui
        Header["Header.tsx"]:::ui
        LogDir["LogAnalysisDirectory.tsx"]:::ui
        LogPage["LogAnalysisPage.tsx"]:::ui
        Coming["ComingSoon.tsx"]:::ui
    end

    subgraph "Processing Engine"
        subgraph "File Upload Modules"
            FT_AP["Apache FileUpload.tsx"]:::proc
            FT_NG["Nginx FileUpload.tsx"]:::proc
        end
        subgraph "Parser Modules"
            P_AP["Apache parser.ts"]:::proc
            P_NG["Nginx parser.ts"]:::proc
        end
        subgraph "Period Grouping"
            Per_AP["Apache period.ts"]:::proc
            Per_NG["Nginx period.ts"]:::proc
        end
    end

    subgraph "State Management"
        Context["LogContext.tsx"]:::state
        Hook["useLogContext.tsx"]:::state
    end

    subgraph "Visualization Layer"
        subgraph "Apache Charts"
           AReq["ApacheRequestChart.tsx"]:::viz
           AUsage["UsageChart.tsx"]:::viz
           ATraffic["TrafficOverview.tsx"]:::viz
           ATop["TopEndpoints.tsx"]:::viz
           ARSize["ResponseSize.tsx"]:::viz
           ARef["Referrer.tsx"]:::viz
           AMal["MalFormedRequests.tsx"]:::viz
           subgraph "DeviceChart"
             ADevMain["TrafficDeviceChart.tsx"]:::viz
             ADevClient["Client.tsx"]:::viz
             ADevDevice["Device.tsx"]:::viz
             ADevOS["OS.tsx"]:::viz
           end
        end
        subgraph "Nginx Charts"
           NReq["NginxRequestChart.tsx"]:::viz
           NUsage["UsageChart.tsx"]:::viz
           NTraffic["TrafficOverview.tsx"]:::viz
           NTop["TopEndpoints.tsx"]:::viz
           NRSize["ResponseSize.tsx"]:::viz
           NRef["Referrer.tsx"]:::viz
           NMal["MalFormedRequests.tsx"]:::viz
           subgraph "DeviceChart"
             NDevMain["TrafficDeviceChart.tsx"]:::viz
             NDevClient["Client.tsx"]:::viz
             NDevDevice["Device.tsx"]:::viz
             NDevOS["OS.tsx"]:::viz
           end
        end
    end

    subgraph "Static Hosting / Build Config"
        Vite["vite.config.ts"]:::infra
        Vercel["vercel.json"]:::infra
        Pkg["package.json"]:::infra
        TSC["tsconfig.json"]:::infra
        Public["public/"]:::infra
    end

    Bmain -->|boots| App
    App -->|renders| Header
    App -->|renders| LogDir
    App -->|renders| LogPage
    App -->|renders| Coming
    LogPage -->|selects| FT_AP
    LogPage -->|selects| FT_NG
    FT_AP -->|reads file| P_AP
    FT_NG -->|reads file| P_NG
    P_AP -->|groups| Per_AP
    P_NG -->|groups| Per_NG
    Per_AP -->|stores| Context
    Per_NG -->|stores| Context
    App -->|uses| Hook
    Hook -->|provides| Context
    Context -->|feeds| AReq
    Context -->|feeds| AUsage
    Context -->|feeds| ATraffic
    Context -->|feeds| ATop
    Context -->|feeds| ARSize
    Context -->|feeds| ARef
    Context -->|feeds| AMal
    Context -->|feeds| ADevMain
    Context -->|feeds| NReq
    Context -->|feeds| NUsage
    Context -->|feeds| NTraffic
    Context -->|feeds| NTop
    Context -->|feeds| NRSize
    Context -->|feeds| NRef
    Context -->|feeds| NMal
    Context -->|feeds| NDevMain

    click Bindex "https://github.com/surjendu104/logsloth/blob/master/index.html"
    click Bmain "https://github.com/surjendu104/logsloth/blob/master/src/main.tsx"
    click App "https://github.com/surjendu104/logsloth/blob/master/src/App.tsx"
    click Header "https://github.com/surjendu104/logsloth/blob/master/src/components/Header.tsx"
    click LogDir "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysisDirectory.tsx"
    click LogPage "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysisPage.tsx"
    click Coming "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ComingSoon.tsx"
    click FT_AP "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/FileUpload.tsx"
    click FT_NG "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/FileUpload.tsx"
    click P_AP "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/parser.ts"
    click P_NG "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/parser.ts"
    click Per_AP "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/period.ts"
    click Per_NG "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/period.ts"
    click AReq "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/ApacheTomcatRequestChart.tsx"
    click AUsage "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/UsageChart.tsx"
    click ATraffic "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/TrafficOverview.tsx"
    click ATop "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/TopEndpoints.tsx"
    click ARSize "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/ResponseSize.tsx"
    click ARef "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/Referrer.tsx"
    click AMal "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/MalFormedRequests.tsx"
    click ADevMain "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/DeviceChart/TrafficDeviceChart.tsx"
    click ADevClient "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/DeviceChart/Client.tsx"
    click ADevDevice "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/DeviceChart/Device.tsx"
    click ADevOS "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/ApacheTomCatLogAnalysis/Charts/DeviceChart/OS.tsx"
    click NReq "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/NginxRequestChart.tsx"
    click NUsage "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/UsageChart.tsx"
    click NTraffic "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/TrafficOverview.tsx"
    click NTop "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/TopEndpoints.tsx"
    click NRSize "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/ResponseSize.tsx"
    click NRef "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/Referrer.tsx"
    click NMal "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/MalFormedRequests.tsx"
    click NDevMain "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/DeviceChart/TrafficDeviceChart.tsx"
    click NDevClient "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/DeviceChart/Client.tsx"
    click NDevDevice "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/DeviceChart/Device.tsx"
    click NDevOS "https://github.com/surjendu104/logsloth/blob/master/src/components/LogAnalysis/NginxLogAnalysis/Charts/DeviceChart/OS.tsx"
    click Context "https://github.com/surjendu104/logsloth/blob/master/src/context/LogContext.tsx"
    click Hook "https://github.com/surjendu104/logsloth/blob/master/src/hooks/useLogContext.tsx"
    click Vite "https://github.com/surjendu104/logsloth/blob/master/vite.config.ts"
    click Vercel "https://github.com/surjendu104/logsloth/blob/master/vercel.json"
    click Pkg "https://github.com/surjendu104/logsloth/blob/master/package.json"
    click TSC "https://github.com/surjendu104/logsloth/blob/master/tsconfig.json"
    click Public "https://github.com/surjendu104/logsloth/tree/master/public/"

    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef proc fill:#90EE90,stroke:#333,stroke-width:1px
    classDef state fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef viz fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
```
