# 1666sapple/bangla-ner-pos architecture

> Architecture diagram of the GitHub repository 1666sapple/bangla-ner-pos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1666sapple/bangla-ner-pos
- Repository: https://github.com/1666sapple/bangla-ner-pos

## Overview

##### Project Type and Purpose
- This project is a full-stack NLP application. It integrates machine learning model training (in the model/ module) and inference (in the app/ module) to offer NER and POS tagging via a FastAPI server.
- The README clearly describes that the FastAPI application accepts input Bangla text and returns annotated results. It also includes a web front-end component (templates and static files) for user interaction.

##### Analyzing the File Structure
- The top-level contains:
- The app/ directory: Contains the API endpoints, HTML templates, static assets, and utility scripts which serve as the front-end and the interface for querying the model.
- The model/ directory: Contains code for model configuration, dataset handling, model architecture, training scripts, and utility functions.
- The data/ directory: Contains the dataset used for training and validation.
- The scripts/ directory: Includes scripts for running the application (run_app.sh) and for training the model (train_model.py).
- The structure implies a separation of concerns: one part (app/) handles API/inference and user interactions, and another (model/) handles training and model-related configurations.

a. Main Components:
- Frontend Web UI: Represented by files in app/templates and app/static (HTML, CSS, JavaScript). It allows users to enter Bangla text.
- FastAPI Server: Driven by files like app/main.py and app/api/routes.py. This component manages API requests, calls prediction functions, and returns results.
- Inference Engine: Within app/models/ner_pos_model.py and app/utils/predict.py. This loads the model weights (from app/models-weight/) and executes inference (NER and POS tagging).
- Machine Learning Module: Comprising model/ (config.py, dataset.py, model.py, train.py, utils.py) which handles training, data processing, and configuration settings.
- Data Component: The data/ directory for training datasets.
- Auxiliary Scripts: Located in scripts/ (train_model.py and run_app.sh) to set up training and to start the FastAPI server.
- Storage and Configuration: Model weights stored in app/models-weight/ and configuration parameters in model/config.py.

b. Relationships and Interactions:
- User Interaction flows from the frontend through a web browser to the FastAPI API endpoints.
- API endpoints (from app/api/routes.py) pass input data to utility functions (in app/utils/predict.py) which call the inference model (in app/models/ner_pos_model.py).
- The inference engine uses pre-trained weights stored in app/models-weight/ to perform predictions.
- The training module (model/) is executed separately (triggered by scripts/train_model.py) and, once trained, updates the weights in app/models-weight/.
- The system configuration and dataset handling (from model/config.py and model/dataset.py) are underlying supports for the entire machine learning pipeline.

c. Architectural Patterns/Design Principles:
- Separation of Concerns: API layer separated from training/model logic.
- MVC-like Pattern: Although not strictly MVC, the separation between presentation (templates/static) and business logic (API, models, utils) is evident.
- Modular design: Clear boundaries between application serving (app/) and heavy computation/model training (model/).

d. Relevant Technologies and Frameworks:
- FastAPI and Uvicorn for the web server and API.
- PyTorch (torch) and transformer frameworks (from Hugging Face) for the underlying model architecture.
- Jinja2 for templating (HTML).
- Additional libraries include pandas, scikit-learn, and numpy for data processing.
- Shell scripts to bootstrap training and running of the application.

##### Elements
- Clear Labels: Label components such as "Web UI," "FastAPI Server," "API Routes Module," "Prediction Utility & Inference Engine," "Model Training Pipeline," "Model Weights Storage," "Dataset," and "Configuration Module."

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface
    U["User (Browser)"]:::user

    subgraph "Frontend"
        UI["Web UI (Templates & Static)"]:::frontend
    end

    subgraph "Backend Inference"
        FS["FastAPI Server (API Endpoints)"]:::api
        PH["Prediction Handler"]:::api
        ML["Inference Engine"]:::inference
        MW["Model Weights Storage"]:::storage
    end

    subgraph "Training Pipeline"
        DI["Dataset (data/data.tsv)"]:::data
        MM["Machine Learning Module (Train & Config)"]:::ml
        MT["Model Training Process"]:::ml
    end

    subgraph "Auxiliary Scripts"
        RS["Run App Script"]:::script
        RT["Train Model Script"]:::script
    end

    %% Data Flow
    U -->|"initiates"| UI
    UI -->|"calls"| FS
    FS -->|"invokes"| PH
    PH -->|"executes"| ML
    ML -->|"loads weights from"| MW
    MW -->|"supplies to"| ML
    MM -->|"provides config to"| PH
    DI -->|"feeds data to"| MM
    MM -->|"trains model via"| MT
    MT -->|"updates"| MW
    RS -->|"boots"| FS
    RT -->|"triggers training in"| MM
    FS -->|"responds to"| UI

    %% Click Events for Component Mapping
    click UI "https://github.com/1666sapple/bangla-ner-pos/tree/main/app/templates"
    click UI "https://github.com/1666sapple/bangla-ner-pos/tree/main/app/static"
    click FS "https://github.com/1666sapple/bangla-ner-pos/blob/main/app/main.py"
    click FS "https://github.com/1666sapple/bangla-ner-pos/blob/main/app/api/routes.py"
    click ML "https://github.com/1666sapple/bangla-ner-pos/blob/main/app/models/ner_pos_model.py"
    click ML "https://github.com/1666sapple/bangla-ner-pos/blob/main/app/utils/predict.py"
    click MW "https://github.com/1666sapple/bangla-ner-pos/tree/main/app/models-weight"
    click MM "https://github.com/1666sapple/bangla-ner-pos/tree/main/model"
    click DI "https://github.com/1666sapple/bangla-ner-pos/blob/main/data/data.tsv"
    click RS "https://github.com/1666sapple/bangla-ner-pos/blob/main/scripts/run_app.sh"
    click RT "https://github.com/1666sapple/bangla-ner-pos/blob/main/scripts/train_model.py"
    
    %% Styles
    classDef user fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef frontend fill:#F9E79F,stroke:#D68910,stroke-width:2px;
    classDef api fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef inference fill:#F7DC6F,stroke:#B7950B,stroke-width:2px;
    classDef storage fill:#D6EAF8,stroke:#2471A3,stroke-width:2px;
    classDef data fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef ml fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef script fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
