# hellohaptik/chatbot_ner architecture

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

- Interactive diagram: https://gitdiagram.com/hellohaptik/chatbot_ner
- Repository: https://github.com/hellohaptik/chatbot_ner

## Overview

##### Project type and purpose
- This is an open-source, Python-based Named-Entity-Recognition (NER) API framework tailored for conversational AI (chatbots).
- It exposes HTTP endpoints (via Django/ASGI) to accept text inputs, runs a pipeline of detectors (numeral, pattern, temporal, textual), and returns extracted entities.
- It also provides CLI commands to manage/support its Datastore (Google Cloud Datastore or Elasticsearch) and ships with Docker setups for development and production.

##### File structure
- Top-level “chatbot_ner/” directory is a Django project (asgi.py, wsgi.py, settings.py, urls.py, manage.py).
- “ner_v1/” and “ner_v2/” contain detector implementations (v2 for numeral, temporal, pattern with multi-language support; v1 for textual lookups).
- “datastore/” holds code to create/populate/query Google Datastore or Elasticsearch.
- “external_api/” wraps any third-party API calls (e.g., dictionary lookups).
- “lib/nlp/” contains common NLP utilities (tokenizers, lemmatizers, CRF models under data/models).
- “dev_docker/” and “docker/” define separate Dockerfiles and compose setups (development vs production with Nginx + Supervisor).
- Configuration and logging/Sentry setup under “config.py”, “setup_logs.py”, “setup_sentry.py”.
- “docs/” contains architecture sketches (entity hierarchy), install/API docs, and images.

##### README for additional insights
- Confirms four detector categories (numeral, pattern, temporal, textual) and their language support.
- Shows high-level entity hierarchy.
- Mentions API endpoints (detailed in docs/api_call.md).
- Points out separate deployment configs for Docker and contribution patterns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Client([Client]):::external
        Nginx["Nginx Reverse Proxy"]:::frontend
        Uvicorn["Uvicorn/Gunicorn"]:::frontend
        DjangoASGI["Django ASGI\n(chatbot_ner)"]:::frontend
    end

    Client -->|HTTPS| Nginx
    Nginx -->|Proxy| Uvicorn
    Uvicorn -->|Runs| DjangoASGI

    %% Application Layer
    subgraph "Application Layer"
        APIrouter["URL Router\n(chatbot_ner/urls.py)"]:::app
        NER_api1["NER API v1\n(ner_v1/api.py)"]:::app
        NER_api2["NER API v2\n(ner_v2/api.py)"]:::app
        DetectorPipeline["Detector Pipeline"]:::app
        BaseDetector1["Base Detector v1\nner_v1/detectors/base_detector.py"]:::app
        BaseDetector2["Base Detector v2\nner_v2/detectors/base_detector.py"]:::app
        Numeral1["Numeral Detectors v1"]:::app
        Pattern1["Pattern Detectors v1"]:::app
        Temporal1["Temporal Detectors v1"]:::app
        Textual1["Textual Detectors v1"]:::app
        Numeral2["Numeral Detectors v2"]:::app
        Pattern2["Pattern Detectors v2"]:::app
        Temporal2["Temporal Detectors v2"]:::app
        Textual2["Textual Detectors v2"]:::app
        NLPutils["Lib NLP & CRF Models"]:::library
        ExternalAPI["External API Module"]:::externalAPI
    end

    DjangoASGI --> APIrouter
    APIrouter --> NER_api1
    APIrouter --> NER_api2
    NER_api1 --> DetectorPipeline
    NER_api2 --> DetectorPipeline
    DetectorPipeline --> BaseDetector1
    DetectorPipeline --> BaseDetector2
    BaseDetector1 --> Numeral1
    BaseDetector1 --> Pattern1
    BaseDetector1 --> Temporal1
    BaseDetector1 --> Textual1
    BaseDetector2 --> Numeral2
    BaseDetector2 --> Pattern2
    BaseDetector2 --> Temporal2
    BaseDetector2 --> Textual2
    Numeral1 --> NLPutils
    Pattern1 --> NLPutils
    Temporal1 --> NLPutils
    Textual1 -->|Queries| DatastoreSDK
    Numeral2 --> NLPutils
    Pattern2 --> NLPutils
    Temporal2 --> NLPutils
    Textual2 -->|Queries| DatastoreSDK
    DetectorPipeline --> ExternalAPI

    %% Data Layer
    subgraph "Data Layer"
        StaticData["Static CSV Data"]:::data
        DatastoreSDK["Google Cloud Datastore"]:::db
        Elastic["Elasticsearch"]:::db
        DSCommands["CLI Commands\n(datastore)"]:::cli
    end

    Numeral1 --> StaticData
    Pattern1 --> StaticData
    Temporal1 --> StaticData
    Textual1 --> StaticData
    Numeral2 --> StaticData
    Pattern2 --> StaticData
    Temporal2 --> StaticData
    Textual2 --> StaticData
    Textual1 -->|SDK Calls| DatastoreSDK
    Textual2 -->|SDK Calls| DatastoreSDK
    Textual1 -->|SDK Calls| Elastic
    Textual2 -->|SDK Calls| Elastic
    DSCommands --> DatastoreSDK
    DSCommands --> Elastic

    %% Infrastructure & DevOps
    subgraph "Infrastructure & DevOps"
        DevCompose["Docker Compose (Dev)"]:::infra
        ProdCompose["Docker Compose (Prod)"]:::infra
        DevDockerfile["Dockerfile (Dev)"]:::infra
        ProdDockerfile["Dockerfile (Prod)"]:::infra
        Entrypoint["Entrypoint Script"]:::infra
        CMDscript["CMD Script"]:::infra
        Supervisord["Supervisor Config"]:::infra
        Logs["Logging Setup"]:::infra
        Sentry["Sentry Setup"]:::infra
    end

    DevCompose --> DevDockerfile
    DevCompose --> Entrypoint
    ProdCompose --> ProdDockerfile
    ProdCompose --> CMDscript
    ProdCompose --> Supervisord
    DjangoASGI --> Logs
    DjangoASGI --> Sentry

    %% Testing & QA
    subgraph "Testing & QA"
        UnitTests["Unit Tests"]:::test
        Postman["Postman Tests"]:::test
    end

    %% Click Events
    click Nginx "https://github.com/hellohaptik/chatbot_ner/blob/develop/docker/nginx.conf"
    click DevCompose "https://github.com/hellohaptik/chatbot_ner/blob/develop/dev_docker/docker-compose.yml"
    click ProdCompose "https://github.com/hellohaptik/chatbot_ner/blob/develop/docker/docker-compose.yml"
    click DevDockerfile "https://github.com/hellohaptik/chatbot_ner/tree/develop/dev_docker/Dockerfile-python3"
    click ProdDockerfile "https://github.com/hellohaptik/chatbot_ner/tree/develop/docker/Dockerfile"
    click Entrypoint "https://github.com/hellohaptik/chatbot_ner/blob/develop/dev_docker/entrypoint.sh"
    click CMDscript "https://github.com/hellohaptik/chatbot_ner/blob/develop/docker/cmd.sh"
    click Supervisord "https://github.com/hellohaptik/chatbot_ner/blob/develop/docker/supervisord.conf"
    click DjangoASGI "https://github.com/hellohaptik/chatbot_ner/blob/develop/chatbot_ner/asgi.py"
    click APIrouter "https://github.com/hellohaptik/chatbot_ner/blob/develop/chatbot_ner/urls.py"
    click Logs "https://github.com/hellohaptik/chatbot_ner/blob/develop/chatbot_ner/setup_logs.py"
    click Sentry "https://github.com/hellohaptik/chatbot_ner/blob/develop/chatbot_ner/setup_sentry.py"
    click NER_api1 "https://github.com/hellohaptik/chatbot_ner/blob/develop/ner_v1/api.py"
    click BaseDetector1 "https://github.com/hellohaptik/chatbot_ner/blob/develop/ner_v1/detectors/base_detector.py"
    click NER_api2 "https://github.com/hellohaptik/chatbot_ner/blob/develop/ner_v2/api.py"
    click BaseDetector2 "https://github.com/hellohaptik/chatbot_ner/blob/develop/ner_v2/detectors/base_detector.py"
    click NLPutils "https://github.com/hellohaptik/chatbot_ner/tree/develop/lib/nlp/"
    click StaticData "https://github.com/hellohaptik/chatbot_ner/tree/develop/data/entity_data/"
    click ExternalAPI "https://github.com/hellohaptik/chatbot_ner/blob/develop/external_api/api.py"
    click DatastoreSDK "https://github.com/hellohaptik/chatbot_ner/blob/develop/datastore/datastore.py"
    click Elastic "https://github.com/hellohaptik/chatbot_ner/blob/develop/datastore/elastic_search/connect.py"
    click DSCommands "https://github.com/hellohaptik/chatbot_ner/blob/develop/datastore/commands/create_datastore.py"
    click UnitTests "https://github.com/hellohaptik/chatbot_ner/tree/develop/lib/nlp/tests/"
    click UnitTests "https://github.com/hellohaptik/chatbot_ner/tree/develop/ner_v1/tests/"
    click UnitTests "https://github.com/hellohaptik/chatbot_ner/tree/develop/ner_v2/tests/"
    click Postman "https://github.com/hellohaptik/chatbot_ner/blob/develop/postman_tests/run_postman_tests.py"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6;
    classDef app fill:#e6ffe6,stroke:#00b300;
    classDef library fill:#f9f,stroke:#d900d9;
    classDef externalAPI fill:#f9f,stroke:#9d009d;
    classDef data fill:#fff2cc,stroke:#d6a500;
    classDef db fill:#ffd9b3,stroke:#cc7a00;
    classDef cli fill:#ffe6e6,stroke:#d90000;
    classDef infra fill:#f2f2f2,stroke:#666666;
    classDef test fill:#f2f2f2,stroke:#999999;
    classDef external fill:#ffe6e6,stroke:#d90000;
```
