# lordzedith/anomaly-detection-platform architecture

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

- Interactive diagram: https://gitdiagram.com/lordzedith/anomaly-detection-platform
- Repository: https://github.com/lordzedith/anomaly-detection-platform

## Overview

##### Project Type and Purpose
- Type: Full-stack web application with a separate ML pipeline.

##### File Structure
- Top-level directories:
- anomaly_models: Python ML training + prediction code, data, results
- server: Node.js/TypeScript backend (Express style)
- src: React/TypeScript frontend (Vite)
- Key files:
- anomaly_models/run_prediction.py & ai_chat.py
- server/index.ts, server/routes/*.ts, server/config/database.ts
- src/App.tsx, src/api/api.ts, components, hooks
- Config/build files:
- README.md, .env, package.json, tsconfig*, tailwind.config.js, Vite configs, requirements.txt

##### Extract Insights from the README
- ML models: 225 total, 117 active, 9 algorithms, 25 strategies
- Features: real-time detection, AI Robo Advisor (OpenAI), visualization, news integration
- Tech stack: Python 3.12 (scikit-learn, NumPy, joblib), Node.js/TypeScript, React/Vite, Tailwind CSS, OpenAI API, relational DB

##### Main Components
a. Users & Clients
- Web browser / UI (React + Vite dev server or static hosted)
b. Frontend Application
- React App
- API client module (src/api/api.ts)
- UI components (charts, dashboard, strategy manager)
c. Backend API Server
- Node.js/Express (server/index.ts)
- Middleware (auth, installation)
- Routes/controllers (anomaly, auth, strategies, install)
- Database connector & migrations (server/config)
d. Database
- Relational DB (PostgreSQL or MySQL)
- Tables: users, strategies, installations, perhaps model metadata
e. ML Pipeline (Python)
- Training module (anomaly_models/prepared_data → anomaly_models/results)
- Prediction service (run_prediction.py)
- AI chat module (ai_chat.py calling OpenAI API)
- Model artifact storage (joblib / pkl files under results/)
f. External Services
- OpenAI API (AI Robo Advisor)
- Financial data feeds (stock prices, news sources – implied)

##### Relationships & Data Flow
- User interacts with React UI → sends HTTP requests to Backend API
- Backend API authenticates user → reads/writes from Database
- On anomaly detection request:
- Backend invokes Prediction Service (either via REST call, CLI spawn, or microservice endpoint)
- Prediction Service loads model artifacts → returns anomaly results
- Backend stores/updates results metadata in Database → returns response to frontend
- For AI Robo Advisor:
- Backend or Prediction Service calls ai_chat.py → communicates with OpenAI API → returns advisory
- Offline Model Training:
- Data engineers run anomaly_models training scripts → ingest prepared_data → output model artifacts in results/
- Results are versioned on disk or in artifact repository

##### Architectural Patterns
- Client-Server (React front-end vs Node.js API)
- Microservice-like separation of ML pipeline (Python) from API server
- Layered architecture: presentation → API business logic → data persistence → model/prediction layer
- Use of environment-based configuration (.env for ports, API keys)
- Infrastructure as code: migrations for DB schema (SQL scripts)

##### Technologies & Frameworks to Annotate
- Frontend: React, Vite, TypeScript, Tailwind CSS
- Backend: Node.js, Express (TypeScript), ts-node, Knex or TypeORM (implied), JWT auth
- ML Pipeline: Python 3.12, scikit-learn, NumPy, joblib/pickle, pandas
- External APIs: OpenAI (ChatGPT), market data providers
- Database: PostgreSQL (or similar)

##### Final Checklist
- Components: User, Frontend, Backend API, ML Pipeline, Database, External APIs
- Flows: HTTP requests, DB queries, model loading, API calls to OpenAI
- Patterns: client-server, microservice, layered architecture

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Users & Clients"
        HTML["index.html"]:::client
        MainTSX["src/main.tsx"]:::client
    end

    subgraph "Frontend Application"
        App["src/App.tsx"]:::frontend
        APIClient["src/api/api.ts"]:::frontend
        Components["src/components/"]:::frontend
        Tailwind["tailwind.config.js"]:::frontend
        IndexCSS["src/index.css"]:::frontend
        ViteConfig["vite.config.ts"]:::frontend
    end

    subgraph "Backend API Server"
        Server["server/index.ts"]:::backend
        AuthMW["server/middleware/auth.ts"]:::backend
        InstallMW["server/middleware/installation.ts"]:::backend
        RouteAnom["server/routes/anomaly.ts"]:::backend
        RouteAuth["server/routes/auth.ts"]:::backend
        RouteInstall["server/routes/install.ts"]:::backend
        RouteStrat["server/routes/strategies.ts"]:::backend
        DBConfig["server/config/database.ts"]:::backend
        Migration["server/config/migrations/STRUCTURE_InstallWizard.sql"]:::backend
        Utils["server/utils/encryption.ts"]:::backend
    end

    DB["Relational DB"]:::db

    subgraph "ML Pipeline (Python)"
        Prediction["anomaly_models/run_prediction.py"]:::ml
        AIChat["anomaly_models/ai_chat.py"]:::ml
        Prepared["anomaly_models/prepared_data/"]:::ml
        Results["anomaly_models/results/"]:::ml
        Requirements["anomaly_models/requirements.txt"]:::ml
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        MarketData["Market Data Feeds"]:::external
    end

    HTML --> MainTSX
    MainTSX --> App
    App --> APIClient
    APIClient --> Server
    Server --> AuthMW
    Server --> InstallMW
    Server --> RouteAuth
    Server --> RouteAnom
    Server --> RouteInstall
    Server --> RouteStrat
    Server --> DBConfig
    Server --> Utils
    Server --> DB
    Server --> Migration
    Server --> Prediction
    Prediction --> Results
    Prediction --> AIChat
    AIChat --> OpenAI
    Prepared --> Results
    MarketData --> Server

    click HTML "https://github.com/lordzedith/anomaly-detection-platform/blob/main/index.html"
    click MainTSX "https://github.com/lordzedith/anomaly-detection-platform/blob/main/src/main.tsx"
    click App "https://github.com/lordzedith/anomaly-detection-platform/blob/main/src/App.tsx"
    click APIClient "https://github.com/lordzedith/anomaly-detection-platform/blob/main/src/api/api.ts"
    click Components "https://github.com/lordzedith/anomaly-detection-platform/tree/main/src/components/"
    click Tailwind "https://github.com/lordzedith/anomaly-detection-platform/blob/main/tailwind.config.js"
    click IndexCSS "https://github.com/lordzedith/anomaly-detection-platform/blob/main/src/index.css"
    click ViteConfig "https://github.com/lordzedith/anomaly-detection-platform/blob/main/vite.config.ts"
    click Server "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/index.ts"
    click AuthMW "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/middleware/auth.ts"
    click InstallMW "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/middleware/installation.ts"
    click RouteAnom "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/routes/anomaly.ts"
    click RouteAuth "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/routes/auth.ts"
    click RouteInstall "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/routes/install.ts"
    click RouteStrat "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/routes/strategies.ts"
    click DBConfig "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/config/database.ts"
    click Migration "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/config/migrations/STRUCTURE_InstallWizard.sql"
    click Utils "https://github.com/lordzedith/anomaly-detection-platform/blob/main/server/utils/encryption.ts"
    click Prediction "https://github.com/lordzedith/anomaly-detection-platform/blob/main/anomaly_models/run_prediction.py"
    click AIChat "https://github.com/lordzedith/anomaly-detection-platform/blob/main/anomaly_models/ai_chat.py"
    click Prepared "https://github.com/lordzedith/anomaly-detection-platform/tree/main/anomaly_models/prepared_data/"
    click Results "https://github.com/lordzedith/anomaly-detection-platform/tree/main/anomaly_models/results/"
    click Requirements "https://github.com/lordzedith/anomaly-detection-platform/blob/main/anomaly_models/requirements.txt"

    classDef client fill:#B3D4FC,stroke:#0366D6,color:#0366D6;
    classDef frontend fill:#D0E8FF,stroke:#007BFF,color:#0056b3;
    classDef backend fill:#DFF2D8,stroke:#28A745,color:#1e7e34;
    classDef db fill:#FFE5B4,stroke:#FF8C00,color:#cc7000,shape:cylinder;
    classDef ml fill:#E1D4F0,stroke:#6F42C1,color:#4b0082;
    classDef external fill:#E2E3E5,stroke:#6C757D,color:#495057;
```
