# ahmadkamrans/ai-classifier-with-embedding-based-semantic-search architecture

> Architecture diagram of the GitHub repository ahmadkamrans/ai-classifier-with-embedding-based-semantic-search, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search
- Repository: https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search

## Overview

##### Project type and purpose
– This is a small full-stack MVP that exposes REST endpoints via Express.js to classify patient symptoms using the OpenAI GPT-4o API, stores the results in a Supabase (PostgreSQL) database, and provides both a static front-end (index.html + index.js) for manual testing and integration points for analytics (Metabase).

##### File structure
– Top level
- .env – environment variables for OpenAI and Supabase
- index.html + index.js – static client page that calls your REST API
- schema.sql – database schema for symptom_reports table
- pictures/ – screenshots for documentation
- README.md – project overview and instructions
– No separate “frontend” or “backend” folders, but their responsibilities are clearly separated by file purpose.

##### README for additional insights
– Backend stack: Node.js + Express.js
– Database: Supabase (hosted PostgreSQL)
– AI service: OpenAI GPT-4o API
– Analytics: Metabase connected to Supabase
– Testing: Postman for API endpoints
– SQL schema provided for reproducibility

a. Main components
- User (Browser/Postman)
- Static Frontend (index.html + index.js)
- REST API Server (Express.js)
- OpenAI GPT-4o Service (external API)
- Supabase PostgreSQL Database
- Metabase Analytics Dashboard (external BI tool)
b. Relationships & interactions
1. User → Frontend: enters or posts symptom data
2. Frontend → Express API: HTTP POST /submit (symptom_description)
3. Express API → OpenAI GPT-4o: classification request
4. OpenAI → Express API: returns triage_level label
5. Express API → Supabase DB: INSERT symptom_report record
6. User/Postman → Express API: GET /reports (retrieve stored records)
7. Metabase → Supabase DB: polling/queries for dashboards
c. Architectural patterns & design principles
– Layered architecture: Presentation (static HTML/JS), API layer (Express), Data layer (PostgreSQL)
– External service integration for AI classification
– Stateless REST endpoints (no in-memory session state)
– Single-page static client for quick testing/demo (no SPA framework)
d. Key technologies & libraries
– Node.js & Express.js for REST server
– openai npm package for GPT-4o integration
– @supabase/supabase-js or PostgreSQL client for DB operations
– Metabase for analytics (reads directly from Supabase)
– Postman for manual endpoint testing

##### Detail without overcomplicating
– Optionally show environment variable store (.env) feeding both the API and the database client
– Reflect the SQL schema as part of the DB component or note the table name “symptom_reports”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        User["User (Browser / Postman)"]:::external
        FrontendHTML["index.html"]:::frontend
        FrontendJS["index.js"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Env[".env"]:::config
        ExpressAPI["Express API Server"]:::api
        AILogic["AI Logic Module"]:::api
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SupabaseDB["Supabase PostgreSQL Database"]:::db
        Schema["schema.sql"]:::config
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI GPT-4o API"]:::external
        Metabase["Metabase Analytics Dashboard"]:::analytics
        Pictures["pictures/"]:::config
        README["README.md"]:::config
    end

    %% Connections
    User -->|"opens"| FrontendHTML
    FrontendHTML -->|"loads"| FrontendJS
    FrontendJS -->|"POST /submit"| ExpressAPI
    Env -->|provides keys| ExpressAPI
    ExpressAPI -->|calls| AILogic
    AILogic -->|"OpenAI API call"| OpenAI
    OpenAI -->|"response triage_level"| AILogic
    AILogic -->|"INSERT symptom_report"| SupabaseDB
    SupabaseDB -->|reads schema| Schema
    User -->|"GET /reports"| ExpressAPI
    Metabase -->|"queries"| SupabaseDB

    %% Click Events
    click FrontendHTML "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/blob/main/Healthcare Triage/index.html"
    click FrontendJS "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/blob/main/Healthcare Triage/index.js"
    click Env "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/blob/main/Healthcare Triage/.env"
    click Schema "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/blob/main/Healthcare Triage/schema.sql"
    click Pictures "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/tree/main/Healthcare Triage/pictures"
    click README "https://github.com/ahmadkamrans/ai-classifier-with-embedding-based-semantic-search/blob/main/Healthcare Triage/README.md"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0066CC,color:#000;
    classDef api fill:#CCE5FF,stroke:#004A99,color:#000;
    classDef db fill:#FFE5CC,stroke:#CC6600,color:#000;
    classDef external fill:#E8FFE8,stroke:#33AA33,color:#000;
    classDef analytics fill:#F0E0FF,stroke:#9933CC,color:#000;
    classDef config fill:#F2F2F2,stroke:#999999,color:#000;
```
