# abhizx18324/3so architecture

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

- Interactive diagram: https://gitdiagram.com/abhizx18324/3so
- Repository: https://github.com/abhizx18324/3so

## Overview

##### Project type and purpose
- This is a two-part, integrated security system:
- A Node.js-based Single Sign-On (SSO) Identity Provider (IDP) server with multiple client apps and Redis-backed session/token management.
- A Python-based Anomaly Detection microservice (containerized) that fetches login logs from the SSO server, applies rule-based and ML-based detection, and exposes a Streamlit UI for expert verification.

##### File structure analysis
- Top level:
- README.md (overall overview)
- anomaly-detection/ (Python service)
– Dockerfile, requirements.txt, data/, rule/, rule_engine/, utils/, ui_anomaly_verify.py
- sso_server_client/ (Node.js SSO server + sample clients)
– idp.js (main server), client1.js/ client2.js, package.json, views/ EJS templates

- Patterns & components:
- SSO server (REST API + views)
- Redis for token/session store
- Exposed `/admin/logins` endpoint for exporting login events
- Python service: data ingestion, rule engine, ML engine, file storage, Streamlit UI

##### Key architecture notes from README
- SSO flow: User→Client App→IDP→Redis→JWT tokens
- IDP logs attempts and serves logs via HTTP
- Anomaly Detector periodically fetches logs, applies detection, writes to CSV, presents results in UI
- Expert feedback loop updates verified anomaly files, used for retraining

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users & Client Apps
    subgraph "Users & Clients"
        User["User"]:::external
        Client1["Client App 1"]:::service
        Client2["Client App 2"]:::service
    end

    %% SSO Server
    subgraph "SSO Server (IDP)"
        IDP["SSO Server (IDP)"]:::service
        Views["EJS Views"]:::ui
    end

    %% Data Stores & Endpoints
    RedisDB["Redis (Session/Token Store)"]:::db
    LogEndpoint["/admin/logins Endpoint"]:::api
    RawLogStore["Internal Log Store"]:::db

    %% Anomaly Detection Service
    subgraph "Anomaly Detection Service (Docker Container)"
        Dockerfile["Docker Setup"]:::infra
        Req["Dependencies"]:::infra

        subgraph "Log Fetcher"
            Fetcher["fetch_data.py"]:::service
        end

        subgraph "Rule-Based Detector"
            DetectorRB["detectorRB.py"]:::service
            RulesTxt["rules.txt & syntax.txt"]:::db
            subgraph "Rule Engine Modules"
                Factory["factory.py"]:::service
                Plain["plain.py"]:::service
                Relation["relation.py"]:::service
                TimeMod["time.py"]:::service
            end
        end

        subgraph "ML Detector"
            Predict["predict.py"]:::service
            SVM["svm_model.pkl"]:::db
            Scal["scaler.pkl"]:::db
        end

        subgraph "Storage"
            RBCSV["rb_results.csv"]:::db
            MLCsv["ml_results.csv"]:::db
            Verified["data/verified/"]:::db
        end

        UI["Streamlit UI"]:::ui
    end

    %% Expert/Admin
    Expert["Expert/Admin"]:::external

    %% Connections - Login Flow
    User -->|login request| Client1
    User -->|login request| Client2
    Client1 -->|redirect+credentials| IDP
    Client2 -->|redirect+credentials| IDP
    IDP -->|store/validate| RedisDB
    RedisDB -->|response| IDP
    IDP -->|logs attempts| RawLogStore
    IDP -->|expose logs| LogEndpoint

    %% Connections - Detection Flow
    LogEndpoint -->|fetch logs| Fetcher
    Fetcher -->|logs| DetectorRB
    Fetcher -->|logs| Predict
    DetectorRB -->|rb anomalies| RBCSV
    Predict -->|ml anomalies| MLCsv

    %% UI & Feedback Loop
    DetectorRB --> UI
    Predict --> UI
    UI -->|verify anomalies| Verified
    Expert --> UI
    Verified -->|for retraining| UI

    %% Click Events
    click Client1 "https://github.com/abhizx18324/3so/blob/main/sso_server_client/client1.js"
    click Client2 "https://github.com/abhizx18324/3so/blob/main/sso_server_client/client2.js"
    click IDP "https://github.com/abhizx18324/3so/blob/main/sso_server_client/idp.js"
    click Views "https://github.com/abhizx18324/3so/tree/main/sso_server_client/views/"
    click RedisDB "https://github.com/abhizx18324/3so/blob/main/sso_server_client/idp.js"
    click LogEndpoint "https://github.com/abhizx18324/3so/blob/main/sso_server_client/idp.js"
    click Dockerfile "https://github.com/abhizx18324/3so/tree/main/anomaly-detection/Dockerfile"
    click Req "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/requirements.txt"
    click Fetcher "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/utils/fetch_data.py"
    click DetectorRB "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/utils/detectorRB.py"
    click RulesTxt "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule/rules.txt"
    click RulesTxt "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule/syntax.txt"
    click Factory "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule_engine/factory.py"
    click Plain "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule_engine/plain.py"
    click Relation "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule_engine/relation.py"
    click TimeMod "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/rule_engine/time.py"
    click Predict "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/utils/predict.py"
    click SVM "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/utils/ML/svm_model.pkl"
    click Scal "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/utils/ML/scaler.pkl"
    click RBCSV "https://github.com/abhizx18324/3so/tree/main/anomaly-detection/data/"
    click MLCsv "https://github.com/abhizx18324/3so/tree/main/anomaly-detection/data/"
    click Verified "https://github.com/abhizx18324/3so/tree/main/anomaly-detection/data/verified/"
    click UI "https://github.com/abhizx18324/3so/blob/main/anomaly-detection/ui_anomaly_verify.py"

    %% Styles
    classDef service fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef ui fill:#FFA500,stroke:#333,stroke-width:1px,shape:parallelogram;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef external fill:#F5F5F5,stroke:#333,stroke-width:1px;
```
