# anshikagarg2005/java-log-analyzer architecture

> Architecture diagram of the GitHub repository anshikagarg2005/java-log-analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anshikagarg2005/java-log-analyzer
- Repository: https://github.com/anshikagarg2005/java-log-analyzer

## Overview

##### Project type and purpose
- This is a Java-based command-line tool (“Suspicious Activity Detection CLI Tool”) for parsing server logs, detecting suspicious IP addresses (3+ failed logins within 60 seconds), enriching them with geolocation via an external API, and presenting/exporting results.
- It is neither a web app nor a microservices system, but a standalone, pipeline-style CLI utility.

##### File structure
- Top-level directories:
- lib/         → external JARs (JSON parsing library)
- logs/        → sample input log files
- src/         → Java source code files
- out/         → compiled .class files
- test/        → unit tests
- Key source files (in src/):
- main.java         → CLI entrypoint, argument parsing, menu
- LogParser.java    → reads/parses Apache-style log lines into LogEntry objects
- GeoIPService.java → calls external HTTP API, parses JSON, returns country info
- SuspiciousIPDetector.java → core detection logic, scanning sequences of failures
- CSVExporter.java  → writes results to CSV
- Utils.java        → shared helpers (e.g., date parsing)
- There’s one external dependency (org.json) loaded from lib/json-…jar, invoked by GeoIPService.

##### README for additional insights
- Confirms pipeline: read → detect → enrich → display/export.
- Mentions interactive menu, CLI flags (--file, --export).

##### Elements
- Clear labels for each component/module
- Rectangles for internal modules (parsing, detection, exporting)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External user
    User((User)):::external

    %% Application boundary
    subgraph "Suspicious Activity Detection CLI Tool"
        direction TB
        CLI["CLI Controller\n(main.java)"]:::modules
        FSIn[(Logs Directory\nlogs/sample.log)]:::datastore
        LogParser["Log Parser\n(LogParser.java)"]:::modules
        LogEntry["LogEntry Model\n(LogEntry.java)"]:::modules
        Detector["Detection Engine\n(SuspiciousIPDetector.java)"]:::modules
        SuspIP["SuspiciousIP Model\n(SuspiciousIP.java)"]:::modules
        GeoIP["Geo-IP Enricher\n(GeoIPService.java)"]:::modules
        Utils["Utils Library\n(Utils.java)"]:::modules
        CSVExp["Result Exporter\n(CSVExporter.java)"]:::modules
        Console["Console Output"]:::modules
        FSOut[(Output CSV\nout/suspicious)]:::datastore
    end

    %% External systems
    ExternalAPI((External GeoIP API)):::external
    JSONLib[(org.json JAR\nlib/json-20240303.jar)]:::library
    TestSuite["Detection Engine Tests\n(SuspiciousIPDetectorTest.java)"]:::test

    %% Data flow
    User -->|"runs CLI"| CLI
    CLI -->|"--file path"| FSIn
    FSIn -->|"raw text lines"| LogParser
    LogParser -->|"LogEntry objects"| LogEntry
    LogEntry --> Detector
    Detector -->|"SuspiciousIP list"| SuspIP
    SuspIP --> GeoIP
    GeoIP -->|"enriched data"| CLI
    CLI --> Console
    CLI -->|"--export flag"| CSVExp
    CSVExp --> FSOut

    %% Dependencies
    GeoIP -->|"uses JSON library"| JSONLib
    GeoIP -->|"HTTP call"| ExternalAPI
    CLI --> Utils
    LogParser --> Utils
    Detector --> Utils
    CSVExp --> Utils

    %% Testing
    TestSuite --> Detector

    %% Click events
    click CLI "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/main.java"
    click FSIn "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/logs/sample.log"
    click LogParser "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/LogParser.java"
    click LogEntry "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/LogEntry.java"
    click Detector "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/SuspiciousIPDetector.java"
    click SuspIP "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/SuspiciousIP.java"
    click GeoIP "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/GeoIPService.java"
    click JSONLib "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/lib/json-20240303.jar"
    click Utils "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/Utils.java"
    click CSVExp "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/src/CSVExporter.java"
    click FSOut "https://github.com/anshikagarg2005/java-log-analyzer/tree/main/out/suspicious"
    click TestSuite "https://github.com/anshikagarg2005/java-log-analyzer/blob/main/test/SuspiciousIPDetectorTest.java"

    %% Styles
    classDef modules fill:#D6EAF8,stroke:#1B4F72,color:#1B2631;
    classDef external fill:#F5B7B1,stroke:#78281F,color:#512E5F;
    classDef datastore fill:#F9E79F,stroke:#7D6608,color:#4E342E;
    classDef library fill:#FAD7A0,stroke:#B9770E,color:#4E342E;
    classDef test fill:#ABEBC6,stroke:#1D8348,color:#145A32
```
