Skip to content
EmprintPublic

About

Open source material inventory app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

146 Commits

Folders and files

Repository files navigation

πŸ“¦ Itemloop – Open Source Inventory Webapp for Community Reuse Centers

🌍 Overview

Itemloop is a full-stack, multilingual web application for reuse and recycling centers to manage their inventory of second-hand items. It is optimized for collaborative, community-based use, supports desktop and mobile devices, and includes PWA features for offline access.

This project is open source and welcomes contributions under the AGPL v3 license.


πŸ”§ Tech Stack

Layer Technology
Frontend Angular 20+ (standalone components, signals, Angular CDK)
Backend PHP 8.2+ Β· Slim Framework 4
Database MySQL 5.7+
Image processing Intervention Image (GD driver) β€” WebP conversion + thumbnails
Hosting target Shared PHP/MySQL hosting (e.g., OVH) β€” no SSH required after deploy

The backend is built on Slim Framework 4 β€” fully assembled locally with no post-deploy server-side commands required.


πŸš€ Features

  • Product CRUD β€” title, description, category, condition, color, quantity, estimated value, barcode, dimensions (L/W/H cm, weight kg), destination, visibility
  • Product list β€” search, multi-filter (category, condition, location), grid/list toggle, pagination, CSV export
  • Product form β€” 3-column layout: product info / characteristics + location / photos + quick info; view mode (read-only) and edit mode
  • Photo lightbox β€” click any photo to view full-size; ←/β†’ navigation and Esc to close; keyboard support
  • Structured locations β€” Building β†’ Zone β†’ Shelf with auto-generated, editable codes
  • Image management β€” multiple images per product, WebP conversion, thumbnail generation, drag-to-reorder, cover image (first image by sort order)
  • Cart β€” add-to-cart with quantity picker (max = available stock) on product view page; cart page with item list, price/line-total columns, grand total, clear and place-order actions; persisted in localStorage
  • Dashboard β€” KPI cards (total products, total quantity, estimated value) + category donut chart
  • Role-based access β€” Customer (browse + cart), Editor (full product/location CRUD), Admin (everything + user management)
  • Public / private visibility β€” guests see only public products; editors/admins see all
  • Authentication β€” register, login, logout (PHP session-based)
  • User management (admin only)
  • Multilingual UI β€” French + English, auto-detected from browser, manually switchable
  • Comboboxes with inline create β€” colors and categories created on the fly
  • Angular CDK drag-and-drop for image ordering
  • Centralized currency config β€” app-settings.ts sets the currency code (default: EUR) used everywhere

πŸ—‚οΈ Project Structure

itemloop/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ backend/              # Slim Framework 4 API
β”‚   β”‚   β”œβ”€β”€ public/           # Web root (index.php entry point, storage/)
β”‚   β”‚   β”‚   └── storage/products/   # Uploaded images (WebP)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ Controllers/  # ProductController, LocationController, etc.
β”‚   β”‚       └── Middleware/   # Auth, Editor, Admin, OptionalAuth, CSRF
β”‚   └── frontend/             # Angular 20 app
β”‚       └── src/
β”‚           β”œβ”€β”€ app/          # Features: products, locations, users, auth, cart
β”‚           └── assets/i18n/  # en.json, fr.json
β”œβ”€β”€ deploy.sh                 # Local build script β€” generates deploy_package/ (no SSH needed)
└── REQUIREMENTS.md           # User stories and roadmap

πŸ› οΈ Getting Started

Prerequisites

  • PHP 8.2+ with the GD extension enabled
  • Composer
  • Node.js 20.19+ (or 22.12+) and npm β€” required by Angular 20
  • MySQL 5.7+

1. Clone the repository

git clone https://github.com/Emprint/itemloop.git
cd itemloop

2. Backend setup

cd src/backend
composer install
cp .env.example .env
# Edit .env β€” set DB_HOST, DB_NAME, DB_USER, DB_PASS

Tip: The DevDB VS Code extension lets you browse and query the MySQL database directly from the editor.

Import the database schema (first time only):

mysql -u youruser -p yourdb < src/backend/sql/schema.sql

Existing installs: when a new version adds or changes database columns, apply only the relevant file from src/backend/sql/migrations/ β€” do not re-import the full schema.sql. See sql/migrations/README.md.

Start the backend dev server:

php -d upload_max_filesize=20M -d post_max_size=25M -S localhost:8000 -t public

The -d flags matter: PHP's built-in server defaults to upload_max_filesize=2M, which silently rejects most phone photos. They mirror the production limits shipped in deploy/frontend-api.user.ini.

3. Frontend setup

cd src/frontend
npm install
npm start        # runs ng serve β†’ http://localhost:4200

The dev server proxies /api and /storage to http://localhost:8000 via proxy.conf.json.
If you change proxy.conf.json, restart ng serve to pick up the new proxy rules.

Before committing, format and lint:

npx prettier --write src
ng lint

πŸ”Œ API Reference

All routes are prefixed with /api.

Write requests (POST, PUT, PATCH, DELETE) must carry the X-XSRF-TOKEN header β€” call GET /csrf-cookie first to obtain it.

Authentication

Method Path Auth required Description
GET /csrf-cookie β€” Sets the XSRF-TOKEN cookie β€” call before any write request
POST /auth/register β€” Register a new account
POST /auth/login β€” Login
POST /auth/logout βœ… Logout
POST /auth/forgot-password β€” Send a password reset email
POST /auth/reset-password β€” Reset the password from a token
GET /me βœ… Returns current user info

Profile (self-service)

Method Path Auth required Description
GET /me/profile βœ… Get own profile
PATCH /me/profile βœ… Update own profile
POST /me/change-password βœ… Change own password

Products

Method Path Auth required Description
GET /products optional List products β€” all for editors/admins, public-only for guests
GET /products/{id} optional Get a single product
POST /products Editor+ Create product
PUT /products/{id} Editor+ Update product
DELETE /products/{id} Editor+ Delete product
GET /products/{id}/history Editor+ Stock movement / change ledger for a product
POST /products/{id}/stock-movement Editor+ Record a stock movement

Product Images

Method Path Auth required Description
POST /products/{id}/images Editor+ Upload images (multipart/form-data, field: images[])
PATCH /products/{id}/images/reorder Editor+ Reorder images β€” body: {"ids":[3,1,2]}
DELETE /products/{id}/images/{image_id} Editor+ Delete image

Locations

Method Path Auth required Description
GET /buildings βœ… List buildings
POST /buildings Editor+ Create building
PUT /buildings/{id} Editor+ Update building
DELETE /buildings/{id} Editor+ Delete building
GET /zones βœ… List zones
POST /zones Editor+ Create zone
PUT /zones/{id} Editor+ Update zone
DELETE /zones/{id} Editor+ Delete zone
GET /locations βœ… List locations (shelf level)
POST /locations Editor+ Create location
PUT /locations/{id} Editor+ Update location
DELETE /locations/{id} Editor+ Delete location

Orders

Method Path Auth required Description
POST /orders βœ… Place an order (reserves stock)
GET /orders/mine βœ… List own orders
GET /orders Editor+ List all orders
PATCH /orders/{id}/status Editor+ Update an order's status

Users (Admin only)

Method Path Auth required Description
GET /users Admin List all users
POST /users/save Admin Create or update a user
POST /users/delete Admin Delete a user
GET /users/pending Admin List users awaiting validation
GET /users/pending/count Admin Count of users awaiting validation
PATCH /users/{id}/validate Admin Activate a pending user
PATCH /users/{id}/deactivate Admin Deactivate a user

Metadata

Method Path Auth required Description
GET /product-categories β€” List categories
POST /product-categories Editor+ Create category
PUT /product-categories/{id} Editor+ Update category
DELETE /product-categories/{id} Editor+ Delete category
GET /product-conditions βœ… List conditions
POST /product-conditions Editor+ Create condition
PUT /product-conditions/{id} Editor+ Update condition
DELETE /product-conditions/{id} Editor+ Delete condition
GET /product-colors βœ… List colors
POST /product-colors Editor+ Create color
PUT /product-colors/{id} Editor+ Update color
DELETE /product-colors/{id} Editor+ Delete color
GET /dashboard optional Dashboard statistics (total products, qty, estimated value, category breakdown)

Settings, logs and exports

Method Path Auth required Description
GET /settings β€” Read application settings (app_name, currency, public_mode, shop_mode, …)
PUT /settings Admin Update application settings
GET /admin/email-logs Admin List sent emails
GET /export/products.pdf Editor+ Export the product list as PDF
GET /export/orders.pdf Editor+ Export the order list as PDF

Cart: The cart is entirely client-side (localStorage) β€” no backend endpoints. Checkout posts the cart to POST /orders. Excel export is generated client-side (xlsx) β€” there is no server-side endpoint for it.


πŸ–ΌοΈ Image Handling

Property Value
Accepted formats JPEG, PNG, WebP, GIF
Max upload size 4 MB per image
Full image Resized to max 1920Γ—1920 px, WebP quality 90
Thumbnail Resized to max 400Γ—400 px, WebP quality 80
Storage src/backend/public/storage/products/
URL /storage/products/{name}.webp / {name}_thumb.webp
Cover image First image by sort_order β€” drag to reorder in the form
Delete Removes both full-size and thumbnail files from disk

🚒 Deployment (Shared Hosting via SSH/rsync)

deploy.sh builds the Angular frontend + installs Composer dependencies locally, then pushes both to your server using rsync over SSH.

Prerequisites

  • sshpass β€” feeds the SSH password non-interactively to rsync:

    brew install hudochenkov/sshpass/sshpass   # macOS
    sudo apt install sshpass                   # Linux/Debian

    Recommended alternative: set up SSH key authentication on your server and remove the sshpass -p "$SSH_PASS" wrapper from deploy.sh. SSH keys are more secure and don't require sshpass at all.

  • rsync β€” usually pre-installed on macOS and Linux.

  • composer β€” must be available in your PATH. The Angular CLI is run through npx, so the project-local one in node_modules is used; no global install needed.

On Windows: deploy.sh is a POSIX shell script and needs rsync + sshpass, neither of which Git Bash ships with (and there is no reliable sshpass build for Windows). Run the whole toolchain from WSL instead β€” install php-cli php-gd php-mysql php-mbstring php-curl php-zip php-xml composer nodejs npm rsync sshpass there, and install node_modules from WSL too (the native esbuild binary is platform-specific, so a node_modules installed from Windows will not work under WSL and vice versa).

One-time server setup

These steps configure the server directory layout and only need to be done once:

  1. Create the API entry point at ~/frontend/api/index.php:

    <?php require __DIR__ . '/../../backend/public/index.php';
  2. ~/frontend/api/ β€” created and managed automatically by deploy.sh (no manual step needed).

  3. Create ~/frontend/.htaccess β€” use deploy/frontend.htaccess as the content. After this first-time setup, deploy.sh will keep it up to date automatically.

  4. Create ~/backend/.env from src/backend/.env.example with your production DB credentials and APP_URL.

  5. Create the image storage directory at ~/frontend/storage/products/ and set STORAGE_PATH in ~/backend/.env:

    STORAGE_PATH=/absolute/real/path/to/frontend/storage/products
    

    OVH note: PHP-FPM's open_basedir uses the real filesystem path, not the /home/username alias. Run echo $HOME via SSH to get the real path (e.g. /homez.NNN/account/sitename).

  6. PHP upload limits β€” nothing to do by hand: deploy.sh ships deploy/frontend.user.ini and deploy/frontend-api.user.ini to ~/frontend/.user.ini and ~/frontend/api/.user.ini:

    upload_max_filesize = 20M
    post_max_size = 25M

    PHP reads .user.ini from the running script's directory up to the docroot. The entry point is ~/frontend/api/index.php, so ~/backend/public/.user.ini has no effect β€” ~/frontend/api/.user.ini is the file that matters. The default 2 MB limit silently truncates phone photos.

    Changes take up to user_ini.cache_ttl (5 min on OVH) to apply.

  7. Import the database schema once via phpMyAdmin (or mysql CLI):

    mysql -u youruser -p yourdb < src/backend/sql/schema.sql

Deploy config (deploy.env)

Copy deploy.env.example to deploy.env (gitignored β€” never commit it) and fill in your values:

cp deploy.env.example deploy.env
SSH_USER=your_ssh_username
SSH_HOST=your_ssh_host
SSH_PORT=22
SITE_URL=https://yourdomain.com

Running the deploy

SSH_PASS=yourpassword ./deploy.sh

The script will:

  1. Build the Angular app to deploy_package/frontend/
  2. Run composer install --no-dev in src/backend/
  3. rsync deploy_package/frontend/ β†’ ~/frontend/ on the server (--delete, but keeps storage/)
  4. rsync src/backend/ β†’ ~/backend/ on the server (skips .env and public/)
  5. copy src/backend/public/index.php separately β€” it is the only file from public/ the API needs

OVH cache note: .htaccess changes may take 35–60 seconds to take effect due to PHP-FPM opcode caching.


πŸ“‹ Notes

  • Roles: Customer (browse public items, cart), Editor (full product/location CRUD), Admin (everything + user management)
  • Password policy: min 8 characters, at least 1 letter, 1 digit, 1 special character
  • Passwords: hashed with PHP password_hash() (bcrypt / PASSWORD_DEFAULT)
  • Sessions: PHP native session handling (no JWT, no Sanctum)
  • CSRF: token-based protection on mutating API routes
  • Currency: configured in src/frontend/src/app/app-settings.ts β€” change currency: 'EUR' to any ISO 4217 code

πŸ” License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).

  • Any modifications must be published under the same license.
  • If you run the app as a network service, the source code must be made available to users.
  • Commercial use is permitted for your own operations; reselling under a proprietary license is not.

See LICENSE for full terms.


🀝 Contributions

Itemloop is developed as a community-driven project. Pull requests, feedback, and translations are welcome.

This app is developed with the help of GitHub Copilot.

Before contributing, please read the LICENSE (AGPL-3.0) and respect the spirit of fair and open collaboration.

About

Open source material inventory app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages