Prerequisites
Before you begin, ensure you have the following installed on your development machine:Node.js
Version 18.x or higher
npm
Version 9.x or higher (comes with Node.js)
Git
For cloning the repository
Supabase Account Setup
PAE Inventory System uses Supabase for authentication and database. You’ll need to create a Supabase project:Create Supabase Account
- Go to supabase.com
- Sign up for a free account
- Verify your email address
Create New Project
- Click New Project
- Choose an organization (or create one)
- Enter project details:
- Name:
pae-inventory(or your preferred name) - Database Password: Generate a strong password (save it securely!)
- Region: Choose the closest region to Venezuela
- Name:
- Click Create new project
- Wait 2-3 minutes for provisioning
Get API Credentials
Once the project is ready:
- Go to Settings → API
- Copy these values (you’ll need them later):
- Project URL (looks like
https://xxxxx.supabase.co) - anon public key (under “Project API keys”)
- service_role key (under “Project API keys”)
- Project URL (looks like
Set Up Database Schema
- Go to SQL Editor in your Supabase dashboard
- Create a new query
- Copy the entire contents of
supabase_schema.sqlfrom the repository - Paste and click Run
- Wait for completion (may take 30-60 seconds)
The schema file is located at
/workspace/source/supabase_schema.sql in the repository.Local Development Setup
Clone the Repository
Clone the source code to your local machine:
Replace
<repository-url> with the actual Git repository URL.Install Dependencies
Install all required npm packages:This installs the following key dependencies:Dev dependencies include Vite, Tailwind CSS, and PostCSS.
Configure Environment Variables
Create a Add your Supabase credentials:The application reads these variables in
.env file in the project root:src/supabaseClient.js:Create Initial Admin User
You need at least one Director user to access the system. Create one directly in Supabase:
- Go to Authentication → Users in Supabase dashboard
- Click Add user → Create new user
- Enter:
- Email:
[email protected] - Password: Your secure password
- Auto Confirm User: ✅ Enable
- Email:
- Click Create user
- Copy the User UID (you’ll need it next)
users table:- Go to Table Editor → users
- Click Insert row
- Enter:
- id_user: Paste the User UID from above
- username:
director - full_name:
Director Principal - id_rol:
1(Director role) - is_active:
true
- Click Save
After the first Director account is created, you can create additional users from within the application.
Start Development Server
Launch the Vite development server:You should see output like:Open your browser to
http://localhost:5173Application Structure
Understanding the codebase organization:Key Files Explained
src/App.jsx
src/App.jsx
Main application component that sets up React Router and authentication:Defines all application routes including public (login) and private (dashboard, products, etc.) routes.
src/supabaseClient.js
src/supabaseClient.js
Supabase client initialization and helper functions:Provides helper functions:
getCurrentUser()- Get current authenticated usergetUserData()- Get user data with role from databasesignOut()- Log out current usergetLocalDate()- Get local date in Venezuela timezonecreateUserAccount()- Create new user (admin only)changeUserPassword()- Update user password
supabase_schema.sql
supabase_schema.sql
Complete PostgreSQL database schema with:
- Table definitions for all entities
- Row Level Security (RLS) policies
- Database triggers for automation
- RPC functions for complex operations
- Audit logging
- Sample data
- Tables: users, products, categories, guia_entrada, input, output, etc.
- Triggers: Stock updates, audit logging, user protection
- RPC Functions:
aprobar_guia(),rechazar_guia(),procesar_operacion_diaria(),get_lotes_por_vencer() - RLS Policies: Role-based access control at database level
- Views: Helpful views for common queries
package.json
package.json
Project metadata and dependencies:
Available Scripts
Development and build commands:- npm run dev
- npm run build
- npm run preview
Starts the Vite development server with:
- Hot Module Replacement (HMR)
- Fast refresh for React components
- Source maps for debugging
- Port 5173 by default
Environment Variables Reference
All environment variables must be prefixed withVITE_ to be accessible in the frontend:
| Variable | Required | Description |
|---|---|---|
VITE_SUPABASE_URL | ✅ Yes | Your Supabase project URL (e.g., https://xxxxx.supabase.co) |
VITE_SUPABASE_ANON_KEY | ✅ Yes | Supabase anonymous/public API key (safe for client-side) |
VITE_SUPABASE_SERVICE_ROLE_KEY | ⚠️ Recommended | Service role key for admin operations (user creation, password reset) |
Troubleshooting
Error: Faltan variables de entorno de Supabase
Error: Faltan variables de entorno de Supabase
Problem: Missing or incorrectly named environment variables.Solution:
- Verify
.envfile exists in project root - Check variable names start with
VITE_ - Restart the dev server after changing
.env - Verify no typos in variable names
Login fails with 'Invalid credentials'
Login fails with 'Invalid credentials'
Problem: User not found or wrong password.Solution:
- Verify user exists in Supabase Auth → Users
- Check that user is confirmed (not pending)
- Verify user exists in
userstable with correctid_user - Reset password in Supabase dashboard if needed
Database schema errors when running SQL
Database schema errors when running SQL
Problem: Schema already exists or syntax errors.Solution:
- If updating: Tables may already exist (script uses
IF NOT EXISTS) - Run in SQL Editor, not in migrations
- Check PostgreSQL version compatibility (Supabase uses PostgreSQL 15)
- Look for specific error messages in Supabase logs
RLS policy errors when accessing data
RLS policy errors when accessing data
Problem: Row Level Security blocking access.Solution:
- Verify user has correct
id_rolinuserstable - Check RLS policies are enabled on all tables
- Review policy definitions in schema
- Test with Director role (has broadest access)
Port 5173 already in use
Port 5173 already in use
Problem: Another process is using the default Vite port.Solution:Or kill the process using port 5173:
Deployment
When you’re ready to deploy to production:Configure Production Environment
Set environment variables in your hosting platform (Vercel, Netlify, etc.):
VITE_SUPABASE_URLVITE_SUPABASE_ANON_KEYVITE_SUPABASE_SERVICE_ROLE_KEY
Deploy Static Files
Upload the
dist/ folder to your hosting provider or use their CLI/Git integration.Next Steps
Quick Start Guide
Learn how to use the system
User Management
Create and manage user accounts
Database Schema
Deep dive into the database structure
Security
Understand security features and RLS policies
Development environment ready! Start building and testing features locally.