# Project Name Backend

## Overview

The backend of the project is a Django web application that provides an API for parsing receipts and storing the extracted information in a PostgreSQL database. 

## Installation

The backend requires the following dependencies:

- Python 3.6 or higher
- Django 3.2 or higher
- NumPy 1.20 or higher
- SciPy 1.6 or higher
- psycopg2 2.8 or higher

To install the dependencies, run the following command:

```
pip install django numpy scipy psycopg2
```

## Usage

To use the backend, follow these steps:

1. Clone the repository to your local machine.
2. Install the dependencies as described in the Installation section.
3. Create a PostgreSQL database and configure the database settings in the `settings.py` file.
4. Run the Django server by executing the following command in the project directory:

   ```
   python manage.py runserver
   ```

5. The API endpoints are available at `http://localhost:8000/api/`.

## Implementation

The backend consists of the following components:

- `receipe/views.py`: Defines the views for the parser web application.
- `receipe/models.py`: Defines the models for the parser database.
- `receipe/forms.py`: Defines the forms for the parser web application.
- `receipe/parser.py`: Defines the parser class that extracts information from the receipt image.
- `receipe/alignment.py`: Defines the linear alignment class that aligns the extracted information with the known articles in the database.
- `receipe/serializers.py`: Defines the serializers for the parser API.

The backend uses the Django web framework and the Django REST framework to provide the API endpoints. The backend also uses the NumPy and SciPy libraries for image processing and clustering, and the psycopg2 library for interacting with the PostgreSQL database.

The backend provides the following API endpoints:

- `GET /api/articles/`: Returns a list of all articles in the database.
- `POST /api/articles/`: Adds a new article to the database.
- `GET /api/articles/<id>/`: Returns the details of a specific article.
- `PUT /api/articles/<id>/`: Updates the details of a specific article.
- `DELETE /api/articles/<id>/`: Deletes a specific article from the database.
- ...

## Limitations

The backend has the following limitations:

- The backend assumes that the receipt image is of good quality and is properly aligned.
- The backend may not be able to extract information from handwritten receipts or receipts with non-standard formats.
- The backend may not be able to match the extracted information with the known articles in the database if the names are misspelled or the database is incomplete.

## Future Work

The backend can be improved in the following ways:

- Use machine learning algorithms to improve the accuracy of the article matching.
- Use deep learning / conventional algorithms to detect and correct image distortions and misalignments.