# anhkhoa24/ahp architecture

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

- Interactive diagram: https://gitdiagram.com/anhkhoa24/ahp
- Repository: https://github.com/anhkhoa24/ahp

## Overview

##### Project Type and Purpose
- This is a decision support system that uses the Analytic Hierarchy Process (AHP) to help users compare and choose schools and majors.
- The system is split into two primary parts: a backend API written in Python (using Flask or FastAPI) that performs the AHP calculations, and a frontend UI built with HTML, jQuery, and Bootstrap that collects user input and displays the results.

##### Key Components
a. Frontend (UI):
- Contains static assets such as HTML (index.html), CSS (style.css), and JavaScript files (script.js, bosung.js, broaden.js).
- Responsible for capturing user inputs (such as pairwise comparisons) and displaying results (like ranking lists or charts).
b. Backend:
- Consists of Python scripts located in the “BackEnd” directory.
- Main modules include:
- API.py: Likely responsible for creating the API endpoints, such as the POST /calculate-ahp endpoint.
- AHP.py: Contains the logic for the AHP computations (matrix normalization, calculating criteria weights, consistency checks, etc.).
- ham.py: Possibly supporting or alternative functionality (perhaps a helper module for additional AHP calculations or utility functions).
- The backend implements the core AHP logic and exposes it via a REST API to the frontend.
c. (Potential Future Component) Database:
- Although in the README the database is not yet updated, mention that a database component might be added later for persistent storage.

##### Relationships and Interactions
- The UI sends an HTTP POST request (e.g., to /calculate-ahp) with the user’s pairwise comparison data.
- The backend receives this request, processes the data using its AHP computation modules, and returns the results to the UI.
- User (within the browser) → UI → Backend API.
- Backend API → Computation Modules (AHP.py, ham.py) for processing.
- Backend API → UI (returning the calculated results).

##### Architectural Patterns & Design Principles
- Separation of concerns: clearly separate the “Frontend” from the “Backend” responsibilities.
- API-driven design: the backend exposes RESTful endpoints to handle computation.
- Modularity: Different backend modules (AHP.py, API.py, ham.py) encapsulate distinct aspects of the AHP calculation process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user("User Browser"):::user

    subgraph "Frontend/UI"
        index("index.html"):::frontend
        assets("Assets (style.css, script.js, bosung.js, broaden.js)"):::frontend
    end

    subgraph "Backend API & Modules"
        api("API.py"):::backend
        ahp("AHP Module (AHP.py)"):::backend
        helper("Helper Module (ham.py)"):::backend
    end

    %% Data flow connections
    user -->|"interacts"| index
    index -->|"POST/calculate-ahp"| api
    api -->|"calls-AHP"| ahp
    api -->|"uses-helper"| helper
    api -->|"returns-results"| index

    %% Click Events
    click index "https://github.com/anhkhoa24/ahp/blob/master/UI/index.html"
    click assets "https://github.com/anhkhoa24/ahp/tree/master/UI/assets"
    click api "https://github.com/anhkhoa24/ahp/blob/master/BackEnd/API.py"
    click ahp "https://github.com/anhkhoa24/ahp/blob/master/BackEnd/AHP.py"
    click helper "https://github.com/anhkhoa24/ahp/blob/master/BackEnd/ham.py"

    %% Styles
    classDef user fill:#fef2cc,stroke:#8c6d31,stroke-width:2px;
    classDef frontend fill:#ccf2f4,stroke:#1f78b4,stroke-width:2px;
    classDef backend fill:#d2e0d2,stroke:#2e8b57,stroke-width:2px;
```
