Want to vibe code this App ? It's recommended to use this $10 Coding AI tool with OpenCode ๐ (+10% off via this link!) - the AGENTS.md file is optimized for it.
OpenStock
A modern, self-hosted inventory and stock management system built with Nuxt 4 and Cloudflare.
๐ฎ Demo
Give it a try: openstock-v2.pages.dev
- User: [email protected]
- Password: 12345678
โจ Features
- Product Management โ Track products with SKU, barcode, variants, and categories
- Supplier Management โ Manage supplier information, contacts, and product associations
- Automatic Pricing โ Calculate selling prices from cost + margin with tax support
- Tax Configuration โ Multiple tax rates with default selection
- Stock Movements โ Full audit trail of inventory changes (in/out/adjustment)
- Price History โ Track price changes over time
- Low Stock Alerts โ Get notified when stock runs low
- Dashboard & Charts โ Visual analytics for stock levels and movements
- Multi-variant Support โ Products with size, color, or other variants
๐ Tech Stack
| Category | Technology |
|---|---|
| Framework | Nuxt 4 with Vue 3 Composition API |
| Styling | TailwindCSS |
| Database | Cloudflare D1 (SQLite at the edge) |
| ORM | Drizzle ORM |
| Hosting | Cloudflare Pages |
| Cache/KV | Cloudflare KV |
| Hub | NuxtHub |
| Charts | Chart.js with vue-chartjs |
| Icons | Lucide Icons via @nuxt/icon |
๐ Prerequisites
๐ Quick Start (Automated)
The easiest way to get started is using the installation script:
# Clone the repository
git clone https://github.com/florianjs/openstock.git
cd openstock
# Make the script executable
chmod +x install.sh
# Run the installer (full setup + deployment)
./install.sh
Installation Script Options
| Command | Description |
|---|---|
./install.sh |
Full installation and deployment to Cloudflare |
./install.sh --dev |
Development setup only (no deployment) |
./install.sh --deploy |
Skip setup, deploy existing configuration |
./install.sh --no-deploy |
Full setup without deployment |
./install.sh --help |
Show help message |
The script will:
- โ Check prerequisites (Node.js, npm)
- โ Install project dependencies
- โ
Create and configure
.envfile with secure session password - โ Authenticate with Cloudflare (opens browser)
- โ Create D1 database and KV namespace
- โ
Update
wrangler.tomlwith resource IDs - โ Run database migrations
- โ Build and deploy to Cloudflare Pages
๐ง Manual Setup
If you prefer manual setup or need more control:
1. Install Dependencies
npm install
2. Environment Configuration
# Copy environment template
cp .env.example .env
# Edit .env and set a secure session password (32+ characters)
3. Cloudflare Authentication
npx wrangler login
4. Create Cloudflare Resources
# Create D1 database
npx wrangler d1 create openstock-db
# Create KV namespace
npx wrangler kv:namespace create openstock_kv
โ ๏ธ After creation, copy the returned IDs to
wrangler.toml.
5. Run Migrations
# Apply migrations to remote database
for file in migrations/*.sql; do
npx wrangler d1 execute openstock-db --remote --file="$file" --yes
done
6. Configure Cloudflare Pages Environment
After the first deployment, add the session password in Cloudflare Dashboard:
- Go to Workers & Pages โ openstock-v2 โ Settings โ Environment variables
- Add variable:
- Name:
NUXT_SESSION_PASSWORD - Value: Copy from your
.envfile (or generate withopenssl rand -base64 32) - Check Encrypt
- Name:
- Save and redeploy
7. Deploy
npm run build
npm run deploy:cf
๐ป Development
Start the development server on http://localhost:3000:
npm run dev
The development server uses NuxtHub's local proxy for Cloudflare resources.
๐ฆ Available Scripts
| Script | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run preview |
Preview production build locally |
npm run deploy:cf |
Build and deploy to Cloudflare Pages |
npm run db:generate |
Generate migrations from schema changes |
๐ Database
Schema
The database schema is defined in server/database/schema.ts using Drizzle ORM.
Generate Migrations
After modifying the schema:
npm run db:generate
Apply Migrations (Remote)
npx wrangler d1 execute openstock-db --remote --file=migrations/XXXX_migration.sql --yes
๐ Project Structure
โโโ app/ # Frontend application (Nuxt 4)
โ โโโ components/ # Vue components
โ โ โโโ ui/ # Reusable UI components
โ โ โโโ charts/ # Chart components
โ โโโ composables/ # Vue composables
โ โโโ layouts/ # Page layouts
โ โโโ pages/ # File-based routing
โ โโโ plugins/ # Nuxt plugins
โ โโโ assets/ # CSS and static assets
โโโ server/ # Backend (Nitro)
โ โโโ api/ # API endpoints
โ โโโ database/ # Drizzle schema
โ โโโ utils/ # Server utilities
โโโ migrations/ # SQL migration files
โโโ documentation/ # Product documentation
โโโ public/ # Static files
โโโ install.sh # Automated setup script
โโโ wrangler.toml # Cloudflare configuration
โโโ nuxt.config.ts # Nuxt configuration
๐ API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/products |
List all products |
POST |
/api/products |
Create a product |
GET |
/api/products/:id |
Get product details |
PUT |
/api/products/:id |
Update a product |
DELETE |
/api/products/:id |
Delete a product |
GET |
/api/categories |
List all categories |
GET |
/api/suppliers |
List all suppliers |
GET |
/api/movements |
List stock movements |
POST |
/api/movements |
Record a stock movement |
GET |
/api/taxes |
List tax rates |
GET |
/api/dashboard/stats |
Dashboard statistics |
GET |
/api/dashboard/charts |
Chart data |
๐ Environment Variables
| Variable | Description | Required |
|---|---|---|
NUXT_SESSION_PASSWORD |
Session encryption key (32+ chars) | โ |
NUXT_MIGRATE_SECRET |
Secret key to access /api/__migrate in production |
โ |
NUXT_ADMIN_SECRET_KEY |
Secret key to access admin endpoints (seed/clear) in production | โ |
๐ ๏ธ Admin Endpoints
These endpoints are available for database management:
| Endpoint | Description |
|---|---|
POST /api/__seed |
Seed the database with sample data |
POST /api/__clear |
Clear all data (preserves users and settings) |
Access Control
- Development: Always accessible without authentication
- Production: Requires
NUXT_ADMIN_SECRET_KEYenvironment variable
Usage in Production
-
Set
NUXT_ADMIN_SECRET_KEYin your Cloudflare Pages environment:# Generate a secure key openssl rand -hex 32 -
Call the endpoint with the secret key:
Via query parameter:
curl -X POST "https://your-app.pages.dev/api/__seed?key=YOUR_SECRET_KEY"Via header:
curl -X POST -H "x-admin-secret: YOUR_SECRET_KEY" https://your-app.pages.dev/api/__seed
โ ๏ธ Security Note: These endpoints are powerful and should only be used for demo/staging environments. Never expose the secret key publicly.
๐๏ธ Database Migrations
Automatic Table Creation
On first deployment, the users table is automatically created when accessing /api/auth/check or /api/auth/setup. No manual migration is required for initial setup.
Manual Migration Endpoint
For applying all database migrations manually, use the protected /api/__migrate endpoint:
In development:
curl http://localhost:3000/api/__migrate
In production:
- Set
NUXT_MIGRATE_SECRETenvironment variable in Cloudflare Pages - Call the endpoint with the secret header:
curl -H "x-migrate-secret: YOUR_SECRET" https://your-app.pages.dev/api/__migrate
Using Wrangler (Alternative)
You can also apply migrations directly using Wrangler:
npx wrangler d1 execute openstock-db --remote --file=migrations/XXXX_migration.sql --yes
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Resources
- Nuxt Documentation
- NuxtHub Documentation
- Cloudflare D1 Documentation
- Drizzle ORM Documentation
- TailwindCSS Documentation
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.