π§ Backend API for LocalStore Platform - A Vietnamese-first, multi-tenant SaaS platform for small businesses.
This repository contains the backend API implementation for LocalStore Platform, built with NestJS and Python (AI service). It provides REST, GraphQL, and WebSocket endpoints for managing products, orders, customers, and analytics for Vietnamese restaurants and small businesses.
Primary Market: Vietnamese small businesses (restaurants, street food vendors, cafΓ©s)
Target Cost: ~$20/month MVP deployment
Localization: Vietnamese-first (vi-VN locale, VND currency)
- Backend Framework: NestJS 10 + TypeScript 5
- Database: PostgreSQL 14 with Row-Level Security (RLS)
- Cache: Redis 7
- Queue: Bull Queue for background jobs
- APIs: REST + GraphQL (Apollo) + gRPC
- Real-time: Socket.io for live updates
- AI Service: Python 3.11 + FastAPI (receipt OCR, analytics)
- ORM: TypeORM
- Logging: Winston
- Specifications: localstore-platform/specs (v1.1-specs)
- Spec Links: docs/SPEC_LINKS.md - Curated links to relevant specifications
- Copilot Instructions: .github/copilot-instructions.md
- Node.js 18+ and npm
- Docker and Docker Compose
- PostgreSQL 14+ (if running without Docker)
- Redis 7+ (if running without Docker)
-
Clone the repository:
git clone https://github.com/localstore-platform/api.git cd api -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Start services with Docker Compose:
# Start all services (API, PostgreSQL, Redis, AI Service) docker-compose up -d # For development with hot reload and debug tools docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
-
Run database migrations:
npm run migration:run
-
Seed initial data (optional):
npm run seed
# Development mode with hot reload
npm run start:dev
# Debug mode
npm run start:debug
# Watch mode
npm run start:watchAccess the API:
- REST API: http://localhost:3000/api/v1
- GraphQL Playground: http://localhost:3000/graphql
- API Documentation: http://localhost:3000/api/docs (Swagger)
- AI Service: http://localhost:8000 (FastAPI)
Development tools (when using docker-compose.dev.yml):
- PgAdmin: http://localhost:5050 (admin@localstore.local / admin)
- Redis Commander: http://localhost:8081
api/
βββ src/
β βββ modules/ # Feature modules (products, orders, etc.)
β βββ common/ # Shared utilities, decorators, guards
β βββ database/ # Database configuration and seeds
β βββ config/ # Configuration modules
β βββ main.ts # Application entry point
βββ ai-service/ # Python AI service (OCR, analytics)
βββ migrations/ # TypeORM migrations
βββ test/ # E2E tests
βββ docs/ # Documentation
βββ docker/ # Docker configuration files
βββ kubernetes/ # Kubernetes manifests (production)
npm run start:dev # Start in development mode
npm run start:debug # Start with debugger
npm run build # Build for production
npm run start:prod # Start production buildnpm run migration:create # Create new migration
npm run migration:generate # Generate migration from entities
npm run migration:run # Run pending migrations
npm run migration:revert # Revert last migration
npm run seed # Seed database with initial datanpm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:cov # Run tests with coverage
npm run test:e2e # Run E2E testsnpm run lint # Lint code
npm run lint:fix # Fix linting errors
npm run format # Format code with Prettier
npm run format:check # Check code formatting- β Multi-tenancy: Complete data isolation with PostgreSQL RLS
- β Vietnamese Localization: vi-VN locale, VND currency formatting
- β Authentication: JWT-based with refresh tokens
- β Authorization: Role-based access control (RBAC)
- β Real-time Updates: WebSocket support for live data
- β Background Jobs: Bull Queue for async processing
- β Caching: Redis for performance optimization
- β AI Features: Receipt OCR, sales analytics, predictions
- β API Documentation: Auto-generated Swagger docs
- β Monitoring: Winston logging + Sentry integration
POST /api/v1/auth/login
POST /api/v1/auth/register
GET /api/v1/products
POST /api/v1/products
GET /api/v1/orders
POST /api/v1/orders
GET /api/v1/customers
GET /api/v1/analytics/revenueFull API specification: architecture/api-specification.md
query {
products(tenantId: "xxx") {
id
name
price
}
}
mutation {
createOrder(input: {...}) {
id
total
}
}Full GraphQL schema: architecture/graphql-schema.md
See .env.example for all available configuration options.
Key variables:
DATABASE_URL- PostgreSQL connection stringREDIS_URL- Redis connection stringJWT_SECRET- JWT signing secretAI_SERVICE_URL- AI service endpointDEFAULT_LOCALE- Default locale (vi-VN)DEFAULT_CURRENCY- Default currency (VND)
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Coverage report
npm run test:covTarget coverage: 80% for business logic modules.
# Build Docker image
docker build -t localstore-api:latest .
# Run with Docker Compose
docker-compose -f docker-compose.yml up -dSee architecture/backend-setup-guide.md (lines 1200-1600) for detailed production deployment instructions.
- Check docs/SPEC_LINKS.md for relevant specifications
- Create a feature branch from
main - Implement changes following the specification
- Write tests (unit + E2E)
- Submit PR with reference to spec sections
- Ensure all checks pass (lint, tests, coverage)
See CONTRIBUTING.md for detailed guidelines.
All API endpoints enforce tenant isolation:
- Every entity includes
tenant_id - PostgreSQL RLS policies enforce data isolation
- JWT tokens contain tenant context
- Queries automatically scoped to tenant
- Default locale:
vi-VN - Currency: VND (β«) with no decimal places
- Date format: DD/MM/YYYY
- Time zone: Asia/Ho_Chi_Minh
- All user-facing messages in Vietnamese
AGPL-3.0 - See LICENSE for details.
- Specifications: https://github.com/localstore-platform/specs
- Implementation Roadmap: planning/implementation-roadmap.md
- Database Schema: architecture/database-schema.md
- Backend Setup Guide: architecture/backend-setup-guide.md
For questions or issues:
- Check docs/SPEC_LINKS.md
- Review specifications at https://github.com/localstore-platform/specs
- Open an issue using the provided templates
Built for Vietnamese small businesses π»π³!