Skip to content

Commit c0d8f40

Browse files
Merge pull request #42 from animeshchaudhri/main
Docs: Rust backend
2 parents 1966c18 + cd3a815 commit c0d8f40

File tree

12 files changed

+279
-60
lines changed

12 files changed

+279
-60
lines changed

README.md

Lines changed: 98 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,110 @@
1-
# Contents
2-
1. [`Backend`](#Backend)
3-
2. [`Project Description (PictoPy)`](#PictoPy)
1+
# PictoPy
42

5-
# Backend
6-
## Steps to run backend
3+
PictoPy is an advanced desktop gallery application that combines the power of Tauri, React, and Rust for the frontend with a Python backend for sophisticated image analysis and management.
74

8-
1. Head over to `/backend` after cloning
9-
2. Create a virtual env by running: `python3 -m venv venv`
10-
3. Activate the env by running `source venv/bin/activate` and install dependancies via `pip install requirments.txt`
11-
4. Start the server via `./run.sh` (for development mode add the flag `--test` [RECOMMENDED])
12-
5. The server should now be hosted on port `8000` on localhost.
5+
## Architecture
136

14-
## Some pointers for the backend
7+
### Frontend
8+
- **Tauri**: Enables building the desktop application
9+
- **React**: Used for creating the user interface
10+
- **Rust**: Powers the backend, which the frontend communicates with through Tauri's API
1511

16-
- Entry point is `main.py` which calls the routes, currently there is a `/test` route for developing, to test an image, send a request to the backend (`localhost:8000/test/return`) with the following Body format:
17-
```
18-
{
19-
"path": "<Path to image>"
20-
}
12+
### Backend (Python)
13+
- **FastAPI**: Serves as the API framework
14+
- **SQLite**: Database for storing metadata and embeddings
15+
- **YOLO**: Used for object detection
16+
- **FaceNet**: Generates face embeddings
17+
- **ONNX Runtime**: Runs the models efficiently
18+
- **DBSCAN**: Performs clustering for face embeddings
19+
20+
### Backend (Rust via Tauri)
21+
Handles file system operations and provides a secure bridge between the frontend and local system.
22+
23+
## Features
24+
25+
- Smart tagging of photos based on detected objects, faces, and their recognition
26+
- Traditional gallery features of album management
27+
- Advanced image analysis with object detection and facial recognition
28+
- Privacy-focused design with offline functionality
29+
- Efficient data handling and parallel processing
30+
- Smart search and retrieval
31+
- Cross-platform compatibility
32+
33+
## Technical Stack
34+
35+
| Component | Technology |
36+
| --------- | ---------- |
37+
| Frontend | React |
38+
| Desktop Framework | Tauri |
39+
| Rust Backend | Rust |
40+
| Python Backend | Python |
41+
| Database | SQLite |
42+
| Image Processing | OpenCV, ONNX Runtime |
43+
| Object Detection | YOLOv8 |
44+
| Face Recognition | FaceNet |
45+
| API Framework | FastAPI |
46+
| State Management | React Hooks |
47+
| Styling | Tailwind CSS |
48+
| Routing | React Router |
49+
| UI Components | Radix UI |
50+
| Build Tool | Vite |
51+
| Type Checking | TypeScript |
52+
53+
## Setup
54+
55+
### Frontend Setup
56+
57+
#### Prerequisites
58+
- Node.js (LTS version recommended)
59+
- npm (comes with Node.js)
60+
- Rust (latest stable version)
61+
- Tauri CLI
62+
63+
#### Installation
64+
1. Navigate to the frontend directory:
65+
```bash
66+
cd frontend
67+
```
68+
2. Install dependencies:
69+
```bash
70+
npm install
71+
```
72+
73+
#### Running the Application
74+
```bash
75+
npm run tauri dev
2176
```
22-
Eg: try it out with path as`backend/tests/inputs/zidane.jpg`
23-
- A window should pop up showing the highlighted detections, simply press `q` to exit, or comment out the `cv2` lines in `test.py`
24-
- Change the type of inference by changing `model_path` variable in `app/test` route, by default there are two models available in the `app/models` directory (face and object deteciton).
25-
# PictoPy
2677

27-
An open source image sorting tool designed to organize your image collection efficiently.
78+
#### Building for Production
79+
```bash
80+
npm run tauri build
81+
```
2882

29-
## Features to be Implemented
83+
### Python Backend Setup
3084

31-
1. **A dedicated Local Database:**
32-
- A dedicated local database for caching tags, significantly improving the speed and efficiency of image sorting.
85+
#### Installation
86+
1. Navigate to the backend directory:
87+
```bash
88+
cd backend
89+
```
90+
2. Set up a virtual environment (recommended)
91+
3. Install requirements:
92+
```bash
93+
pip install -r requirements.txt
94+
```
3395

34-
2. **Image Recognition Library:**
35-
- Uses an advanced image recognition library for evaluating objects in images along with faces, ensuring a smoother and more accurate sorting process.
96+
#### Running the Backend
97+
For UNIX-based systems:
98+
```bash
99+
./run.sh --test
100+
```
36101

37-
3. **Improved UI/UX:**
38-
- A smooth user interface for a more intuitive and pleasant experience.
102+
The backend should now be running on port 8000 by default.
39103

40-
4. **Multiprocessing Support:**
41-
- Pictopy should supports multiprocessing, optimizing the sorting process and improving overall performance.
104+
## Additional Resources
105+
- [Tauri Documentation](https://tauri.app/v1/guides/)
106+
- [React Documentation](https://reactjs.org/docs/getting-started.html)
107+
- [FastAPI Documentation](https://fastapi.tiangolo.com/)
42108

43-
109+
## Troubleshooting
110+
If you encounter any issues, please check the respective documentation for Tauri, React, and FastAPI. For persistent problems, feel free to open an issue in the project repository.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Backend Setup
2-
1+
# Python Backend Setup
32

43
## Setup Directory
4+
55
!!! note "Base Directory"
6-
All commands executed below are with respect to the `backend/` directory
6+
All commands executed below are with respect to the `backend/` directory
77

88
### Installing requirments
99

1010
We suggest setting up a virtual environment and run the following command
11+
1112
```bash
1213
pip install -r requirements.txt
1314
```
@@ -16,8 +17,8 @@ The entry point for backend is `main.py` , since PictoPy is built on top of Fast
1617
`.bat` and `.sh` formats.
1718

1819
!!! note "UNIX Development"
19-
For UNIX based systems, to run in development mode run
20-
```bash
20+
For UNIX based systems, to run in development mode run
21+
`bash
2122
./run.sh --test
22-
```
23+
`
2324
The backend should now be successfully running on port 8000 by default. To change this modify the start-up scripts.

docs/backend/backend_rust/api.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## API Documentation
2+
3+
The Rust backend provides the following commands that can be invoked from the frontend:
4+
5+
### 1. get_folders_with_images
6+
- **Description**: Retrieves folders containing images from a specified directory.
7+
- **Parameters**:
8+
- `directory`: String
9+
- **Returns**: `Vec<PathBuf>`
10+
11+
### 2. get_images_in_folder
12+
- **Description**: Gets all images in a specific folder.
13+
- **Parameters**:
14+
- `folder_path`: String
15+
- **Returns**: `Vec<PathBuf>`
16+
17+
### 3. get_all_images_with_cache
18+
- **Description**: Retrieves all images, organized by year and month, with caching.
19+
- **Parameters**:
20+
- `directory`: String
21+
- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>`
22+
23+
### 4. get_all_videos_with_cache
24+
- **Description**: Retrieves all videos, organized by year and month, with caching.
25+
- **Parameters**:
26+
- `directory`: String
27+
- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>`
28+
29+
### 5. delete_cache
30+
- **Description**: Deletes all cached data.
31+
- **Parameters**: None
32+
- **Returns**: `bool`
33+
34+
## Usage Example
35+
36+
```javascript
37+
// In your frontend JavaScript/TypeScript code:
38+
import { invoke } from '@tauri-apps/api/tauri';
39+
40+
// Example: Get all images with cache
41+
const imagesData = await invoke('get_all_images_with_cache', { directory: '/path/to/images' });
42+
43+
// Example: Delete cache
44+
const cacheDeleted = await invoke('delete_cache');
45+
```
46+
47+
## Key Components
48+
49+
- **FileService**: Handles file system operations for images and videos.
50+
- **CacheService**: Manages caching of folders, images, and videos.
51+
- **FileRepository**: Interacts directly with the file system to retrieve file information.
52+
- **CacheRepository**: Handles reading from and writing to cache files.
53+
54+
This backend architecture provides efficient file management and caching capabilities, enhancing the performance of image and video retrieval operations in the Tauri application.

docs/backend/backend_rust/setup.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Rust Backend Setup
2+
3+
## Prerequisites
4+
5+
Before setting up the frontend, ensure you have the following installed:
6+
7+
- [Node.js](https://nodejs.org/) (LTS version recommended)
8+
- npm (comes with Node.js)
9+
- [Rust](https://www.rust-lang.org/tools/install) (latest stable version)
10+
- [Tauri CLI](https://v2.tauri.app/start/prerequisites/)
11+
12+
For a comprehensive guide on prerequisites, refer to the [Tauri Prerequisites](https://v2.tauri.app/start/prerequisites/) documentation.
13+
14+
## Setup Directory
15+
16+
!!! note "Base Directory"
17+
All commands executed below are with respect to the `frontend/` directory
18+
19+
### Installing Dependencies
20+
21+
1. Navigate to the frontend directory:
22+
```bash
23+
cd frontend
24+
```
25+
26+
2. Install the project dependencies:
27+
```bash
28+
npm install
29+
```
30+
31+
For more information on npm commands, see the [npm documentation](https://docs.npmjs.com/).
32+
33+
## Running the Application
34+
35+
To start the Tauri application in development mode, run:
36+
37+
```bash
38+
npm run tauri dev
39+
```
40+
41+
This command will:
42+
- Start the [Vite](https://vitejs.dev/) development server for the frontend
43+
- Compile the Rust backend
44+
- Launch the Tauri application window
45+
46+
For more details on Tauri commands, check the [Tauri CLI documentation](https://tauri.app/v1/api/cli).
47+
48+
!!! note "First Run"
49+
The first run might take longer as it needs to compile the Rust code.

docs/index.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ PictoPy is a modern desktop app designed to transform the handling of digital ph
77
<img src="assets/AOSSIE-logo.png" alt="AOSSIE Logo" style="display:flex; margin:0 auto; justify-content: center;">
88
</div>
99

10-
This project was announced by [AOSSIE](https://aossie.org/), an umbrella organization and was to be implemented from scratch. It provides features such as object detection and face similarity,
11-
offering smart tagging capabilities for photos based on objects, faces.
10+
This project was announced by [AOSSIE](https://aossie.org/), an umbrella organization and was to be implemented from scratch. It provides features such as object detection and face similarity, offering smart tagging capabilities for photos based on objects, faces.
1211

1312
<div style="display:flex; margin:0 auto; justify-content: center;">
14-
<div style="width:33%">
13+
<div style="width:25%">
1514
<h2>Overview</h2>
1615
<ul>
1716
<li><a href='./overview/features'>
@@ -24,37 +23,52 @@ offering smart tagging capabilities for photos based on objects, faces.
2423
</li>
2524
</ul>
2625
</div>
27-
<div style="width:33%">
28-
<h2>Backend</h2>
26+
<div style="width:25%">
27+
<h2>Backend Python</h2>
2928
<ul>
3029
<li>
31-
<a href="./backend/setup">
30+
<a href="./backend/backend_python/setup">
3231
Setup
3332
</a>
3433
</li>
3534
<li>
36-
<a href="./backend/database">
35+
<a href="./backend/backend_python/database">
3736
Database
3837
</a>
3938
</li>
4039
<li>
41-
<a href="./backend/directory-structure">
40+
<a href="./backend/backend_python/directory-structure">
4241
Directory Structure
4342
</a>
4443
</li>
4544
<li>
46-
<a href="./backend/api">
45+
<a href="./backend/backend_python/api">
4746
API
4847
</a>
4948
</li>
5049
<li>
51-
<a href="./backend/image-processing">
50+
<a href="./backend/backend_python/image-processing">
5251
Image Processing
5352
</a>
5453
</li>
5554
</ul>
5655
</div>
57-
<div style="width:33%">
56+
<div style="width:25%">
57+
<h2>Backend Rust</h2>
58+
<ul>
59+
<li>
60+
<a href="./backend/backend_rust/setup">
61+
Setup
62+
</a>
63+
</li>
64+
<li>
65+
<a href="./backend/backend_rust/api">
66+
API
67+
</a>
68+
</li>
69+
</ul>
70+
</div>
71+
<div style="width:25%">
5872
<h2>Frontend</h2>
5973
<ul>
6074
<li>
@@ -79,4 +93,4 @@ offering smart tagging capabilities for photos based on objects, faces.
7993
</li>
8094
</ul>
8195
</div>
82-
</div>
96+
</div>

0 commit comments

Comments
 (0)