Developer Guide
Complete guide for developers working on Lager Guru.
Overview
This guide provides everything you need to start developing on Lager Guru, including setup instructions, coding standards, testing practices, and contribution guidelines.
Quick Start
Prerequisites
- Node.js 18+ and npm
- Git
- Supabase account (or local Supabase instance)
- Code editor (VS Code recommended)
Setup Steps
Clone Repository
bashgit clone <repository-url> cd lager-guruInstall Dependencies
bashnpm installEnvironment Setup
bashcp .env.example .env.local # Edit .env.local with your Supabase credentialsStart Development Server
bashnpm run devRun Database Migrations
bashnpx supabase migration up
Project Structure
lager-guru/
├── src/
│ ├── components/ # React components
│ │ ├── admin/ # Admin components
│ │ ├── dashboard/ # Dashboard components
│ │ └── ui/ # UI primitives
│ ├── lib/ # Business logic
│ │ ├── inventory.ts # Inventory functions
│ │ ├── pickpack.ts # Pick & Pack functions
│ │ └── routingEngine.ts # Routing functions
│ ├── pages/ # Route pages
│ ├── contexts/ # React contexts
│ └── hooks/ # Custom hooks
├── supabase/
│ ├── migrations/ # Database migrations
│ └── functions/ # Edge functions
├── docs/ # Documentation
└── scripts/ # Utility scriptsCoding Standards
TypeScript
- Strict Mode: Always use strict TypeScript
- Types: Define interfaces for all data structures
- No
any: Avoidanytype, useunknownif needed
typescript
// ✅ GOOD
interface InventoryItem {
id: string;
sku: string;
quantity: number;
}
// ❌ BAD
const item: any = { ... };React Components
- Functional Components: Use function components with hooks
- Props Interface: Define props interface
- Error Boundaries: Wrap components in error boundaries
typescript
// ✅ GOOD
interface InventoryListProps {
items: InventoryItem[];
onItemClick: (item: InventoryItem) => void;
}
export function InventoryList({ items, onItemClick }: InventoryListProps) {
// Component logic
}Database Queries
- Always Filter by Tenant: Every query must include
tenant_idfilter - Use RLS: Rely on RLS but also filter explicitly
- Error Handling: Always handle errors
typescript
// ✅ GOOD
const tenantId = await getCurrentUserTenantId();
const { data, error } = await supabase
.from('shipments')
.select('*')
.eq('tenant_id', tenantId);
if (error) {
console.error('Error fetching shipments:', error);
return;
}File Naming
- Components: PascalCase (
InventoryList.tsx) - Functions: camelCase (
getInventoryItems.ts) - Constants: UPPER_SNAKE_CASE (
MAX_QUANTITY.ts)
Testing
Unit Tests
typescript
// tests/lib/inventory.test.ts
import { describe, it, expect } from 'vitest';
import { createItem } from '@/lib/inventory';
describe('createItem', () => {
it('should create item with correct data', async () => {
const { data, error } = await createItem({
sku: 'TEST-001',
name: 'Test Item',
});
expect(error).toBeNull();
expect(data?.sku).toBe('TEST-001');
});
});Integration Tests
typescript
// tests/integration/pickpack.test.ts
import { describe, it, expect } from 'vitest';
import { createPickList } from '@/lib/pickpack';
describe('Pick & Pack Integration', () => {
it('should create pick list with optimal route', async () => {
// Test implementation
});
});Multi-Tenant Standards
CRITICAL: Follow Multi-Tenant Standards strictly:
- ✅ Every table has
tenant_id - ✅ Every query filters by
tenant_id - ✅ Every RLS policy checks tenant access
- ✅ No cross-tenant data exposure
- ✅ Seeds use service role
- ✅ Scripts set tenant context
Git Workflow
Branch Naming
feature/- New featuresfix/- Bug fixesdocs/- Documentationrefactor/- Code refactoring
Commit Messages
type(scope): description
[optional body]
[optional footer]Types:
feat: New featurefix: Bug fixdocs: Documentationrefactor: Code refactoringtest: Testschore: Maintenance
Example:
feat(inventory): add low stock alerts
- Add getLowStockItems function
- Add UI component for alerts
- Add testsCode Review Checklist
Before submitting PR:
- [ ] Code follows TypeScript standards
- [ ] All queries filter by
tenant_id - [ ] RLS policies are correct
- [ ] Tests pass
- [ ] No console.logs in production code
- [ ] Error handling implemented
- [ ] Documentation updated
- [ ] No breaking changes
Related Documentation
- Multi-Tenant Standards - Strict rules
- Architecture - System design
- API Reference - API documentation
- Database Schema - Database structure