b9126c286f1d392f82e208fd19f4c1399dad0c24
Components Inventory - Elixir/Phoenix Implementation
A modern, idiomatic Elixir/Phoenix port of the original PHP-based component inventory management system.
Features
✨ Improvements over the original PHP version:
-
Modern Architecture
- Phoenix LiveView for real-time, reactive UI without JavaScript
- Ecto for type-safe database operations
- Proper separation of concerns with Phoenix contexts
- Built-in validation and error handling
-
Enhanced User Experience
- Real-time search with no page refreshes
- Responsive design with Tailwind CSS
- Loading states and better feedback
- Improved mobile experience
-
Better Data Management
- Full-text search with PostgreSQL
- Hierarchical categories with parent-child relationships
- Proper foreign key constraints
- Database migrations for schema management
-
Security & Reliability
- CSRF protection built-in
- SQL injection prevention through Ecto
- Session-based authentication
- Input validation and sanitization
🔧 Core Functionality
- Component Management: Add, edit, delete, and track electronic components
- Inventory Tracking: Monitor component quantities with increment/decrement buttons
- Search & Filter: Fast search across component names, descriptions, and keywords
- Category Organization: Hierarchical category system for better organization
- Category Management: Add, edit, delete categories through the web interface with hierarchical support
- Datasheet Links: Direct links to component datasheets
- Position Tracking: Track component storage locations
- Real-time Updates: All changes are immediately reflected in the interface
Setup
-
Install dependencies:
mix deps.get -
Set up the database:
mix ecto.create mix ecto.migrate mix run priv/repo/seeds.exs -
Start the server:
mix phx.server -
Visit the application: Open http://localhost:4000
Authentication
The application uses a simple password-based authentication system:
- Default password:
changeme - Set custom password via environment variable:
AUTH_PASSWORD=your_password
Database Schema
Categories
id: Primary keyname: Category name (required)description: Optional descriptionparent_id: Foreign key for hierarchical categories- Supports unlimited nesting levels
Components
id: Primary keyname: Component name (required)description: Detailed descriptionkeywords: Search keywordsposition: Storage location/positioncount: Current quantity (default: 0)datasheet_url: Optional link to datasheetimage_filename: Optional image file namecategory_id: Required foreign key to categories
Architecture
Contexts
ComponentsElixir.Inventory: Business logic for components and categoriesComponentsElixir.Auth: Simple authentication system
Live Views
ComponentsElixirWeb.LoginLive: Authentication interfaceComponentsElixirWeb.ComponentsLive: Main component management interfaceComponentsElixirWeb.CategoriesLive: Category management interface
Key Features
- Real-time updates: Changes are immediately reflected without page refresh
- Infinite scroll: Load more components as needed
- Search optimization: Uses PostgreSQL full-text search for long queries, ILIKE for short ones
- Responsive design: Works on desktop and mobile devices
API Comparison
| Original PHP | New Elixir/Phoenix | Improvement |
|---|---|---|
getItems.php |
Inventory.list_components/1 |
Type-safe, composable queries |
getCategories.php |
Inventory.list_categories/0 |
Proper associations, hierarchical support |
addItem.php |
Inventory.create_component/1 |
Built-in validation, changesets |
| Manual editing | Inventory.update_component/2 |
NEW: Full edit functionality with validation |
changeAmount.php |
Inventory.update_component_count/2 |
Atomic operations, constraints |
| Manual category management | CategoriesLive + Inventory.create_category/1 |
NEW: Full category CRUD with web interface |
imageUpload.php |
Phoenix LiveView file uploads with .live_file_input |
IMPLEMENTED: Full image upload with preview, validation, and automatic cleanup |
| Session management | Phoenix sessions + LiveView | Built-in CSRF protection |
Future Enhancements
Image Upload: Implement Phoenix file uploads for component images✅ COMPLETED- Bulk Operations: Import/export components via CSV
- API Endpoints: REST API for external integrations
- User Management: Multi-user support with roles and permissions
- Advanced Search: Filters by category, stock level, etc.
- Barcode/QR Codes: Generate and scan codes for quick inventory updates
✅ Recently Implemented Features
Image Upload System
- Phoenix LiveView file uploads with
.live_file_inputcomponent - Image preview during upload with progress indication
- File validation (JPG, PNG, GIF up to 5MB)
- Automatic cleanup of old images when updated or deleted
- Responsive image display in component listings with fallback placeholders
- Upload error handling with user-friendly messages
Visual Datasheet Indicators
- Datasheet emoji (📄) displayed next to component names when datasheet URL is present
- Clickable datasheet links with clear visual indication
- Improved component listing with image thumbnails and datasheet indicators
Technical Implementation Details
Image Upload Architecture
- LiveView uploads configured with
allow_upload/3in mount - File processing with
consume_uploaded_entries/3for secure file handling - Unique filename generation to prevent conflicts
- Static file serving through Phoenix.Plug.Static with
/uploadspath - Database integration with
image_filenamefield in components schema
Upload Features
- File type validation: Only JPG, PNG, GIF files accepted
- Size limits: Maximum 5MB per file
- Single file uploads: One image per component
- Progress indication: Real-time upload progress display
- Cancel functionality: Users can cancel uploads in progress
- Preview system: Live image preview before form submission
File Management
- Automatic cleanup: Old images deleted when new ones uploaded
- Orphan prevention: Images deleted when components are removed
- Error handling: Graceful fallback for missing or corrupted files
- Static serving: Images served directly through Phoenix static file handler
Development
Running Tests
mix test
Code Quality
mix format
mix credo
Database Management
# Reset database
mix ecto.reset
# Add new migration
mix ecto.gen.migration add_feature
# Check migration status
mix ecto.migrations
Deployment
For production deployment:
-
Set environment variables:
export AUTH_PASSWORD=your_secure_password export SECRET_KEY_BASE=your_secret_key export DATABASE_URL=postgresql://user:pass@host/db -
Build release:
MIX_ENV=prod mix release -
Run migrations:
_build/prod/rel/components_elixir/bin/components_elixir eval "ComponentsElixir.Release.migrate"
Contributing
This is a modernized, idiomatic Elixir/Phoenix implementation that maintains feature parity with the original PHP version while providing significant improvements in code quality, security, and user experience.
The application follows Phoenix and Elixir best practices:
- Contexts for business logic
- LiveView for interactive UI
- Ecto for database operations
- Comprehensive error handling
- Input validation and sanitization
Description
A modern, comprehensive electronic component inventory management system built with Elixir/Phoenix LiveView.
Languages
Elixir
75.1%
PostScript
16.7%
HTML
4.5%
CSS
1.3%
JavaScript
1.1%
Other
1.3%