Home
Softono
OpenStock

OpenStock

Open source Vue
49
Stars
10
Forks
1
Issues
0
Watchers
3 months
Last Commit

About OpenStock

OpenStock is an open-source alternative to expensive market platforms. Track real-time prices, set personalized alerts, and explore detailed company insights โ€” built openly, for everyone, forever free.

Platforms

Web Self-hosted Cloud

Languages

TypeScript Vue

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.

License Nuxt Cloudflare

๐ŸŽฎ Demo

Give it a try: openstock-v2.pages.dev

โœจ 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

  • Node.js 18 or later (Download)
  • Cloudflare account (Sign up - free tier available)

๐Ÿš€ 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:

  1. โœ… Check prerequisites (Node.js, npm)
  2. โœ… Install project dependencies
  3. โœ… Create and configure .env file with secure session password
  4. โœ… Authenticate with Cloudflare (opens browser)
  5. โœ… Create D1 database and KV namespace
  6. โœ… Update wrangler.toml with resource IDs
  7. โœ… Run database migrations
  8. โœ… 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:

  1. Go to Workers & Pages โ†’ openstock-v2 โ†’ Settings โ†’ Environment variables
  2. Add variable:
    • Name: NUXT_SESSION_PASSWORD
    • Value: Copy from your .env file (or generate with openssl rand -base64 32)
    • Check Encrypt
  3. 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_KEY environment variable

Usage in Production

  1. Set NUXT_ADMIN_SECRET_KEY in your Cloudflare Pages environment:

    # Generate a secure key
    openssl rand -hex 32
  2. 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:

  1. Set NUXT_MIGRATE_SECRET environment variable in Cloudflare Pages
  2. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“š Resources

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.