Anthill is a modern multi-tenant inventory management SaaS platform built with Rust (backend microservices) and SvelteKit 2 with Svelte 5 (frontend), optimized for e-commerce businesses.
This project standardizes on SQLx compile-time checked macros plus Offline Mode metadata to get both:
- Schema safety (catch SQL/type mistakes at compile time)
- Stable CI build (no need for a live DB during compilation)
- Prefer
sqlx::query!,sqlx::query_as!,sqlx::query_scalar!for static SQL (string literals). - Avoid
sqlx::query(...)+.bind(...)unless the query is truly dynamic. - Treat
.sqlx/as required workspace metadata:- any change to migrations or query macros must update
.sqlx/ .sqlx/must be committed to git
- any change to migrations or query macros must update
- Start Postgres with the correct schema/migrations applied.
- Set
DATABASE_URLto that database. - Run:
cargo install sqlx-cli --no-default-features --features postgres
cargo sqlx prepare- Commit the resulting changes in
.sqlx/together with your code/migrations.
Verify metadata is in sync:
cargo sqlx prepare --check🐜 Just like an anthill works efficiently and organized, Anthill helps you manage inventory intelligently and automatically.
- ✅ Multi-tenant Architecture: Support multiple tenants on the same infrastructure
- ✅ Real-time Inventory Tracking: Update inventory in real-time
- ✅ Marketplace Integration: Connect with Shopee, Lazada, Tiki, WooCommerce, Shopify
- ✅ Order Management: Manage orders from multiple channels
- ✅ Payment Gateway: Integrate with VNPay, Stripe, MoMo, ZaloPay
- ✅ Analytics & Reporting: Analytics dashboard with Cube
- ✅ Zero Downtime Deployment: Continuous deployment without interruption
The project uses Event-Driven Microservices architecture with the following technologies:
- Backend: Rust + Axum + Tokio + SQLx
- Frontend: SvelteKit 2 + Svelte 5 + TypeScript + Tailwind CSS + shadcn-svelte
- Authentication: Kanidm (OAuth2/OIDC Identity Provider)
- Authorization: Casbin-rs (RBAC)
- Database: PostgreSQL
- Cache: Redis
- Message Queue: NATS
- Analytics: Cube
- Deployment: CapRover (Docker Swarm)
- Gateway: NGINX (managed by CapRover)
See architecture details at ARCHITECTURE.md
anthill/
├── services/ # Rust microservices
│ ├── user-service/ # Authentication & tenancy
│ ├── inventory-service/ # Inventory management
│ ├── order-service/ # Order management
│ ├── integration-service/ # Marketplace integration
│ └── payment-service/ # Payment processing
├── frontend/ # SvelteKit 2 with Svelte 5 application
│ ├── src/
│ │ ├── app.html # Main HTML template
│ │ ├── app.d.ts # TypeScript declarations
│ │ ├── lib/ # Shared libraries
│ │ │ ├── components/ # Reusable UI components (shadcn-svelte)
│ │ │ ├── stores/ # Svelte 5 runes state management
│ │ │ ├── utils/ # Utility functions
│ │ │ ├── auth/ # Authentication helpers
│ │ │ └── api/ # API client functions
│ │ └── routes/ # Page routes
│ ├── static/ # Static assets
│ ├── package.json # Dependencies and scripts
│ ├── svelte.config.js # SvelteKit configuration
│ ├── vite.config.ts # Vite build configuration
│ ├── tsconfig.json # TypeScript configuration
│ ├── tailwind.config.js # Tailwind CSS configuration
│ └── playwright.config.ts # E2E testing configuration
├── shared/ # Shared libraries
│ ├── auth/ # Casbin RBAC, Kanidm integration
│ ├── config/ # Environment config loader
│ ├── db/ # Database utilities
│ ├── error/ # Error types and HTTP responses
│ ├── jwt/ # JWT encoding/decoding
│ ├── kanidm_client/ # Kanidm OAuth2/OIDC client
│ └── openapi/ # OpenAPI spec generation
├── infra/ # Infrastructure config
│ ├── docker_compose/ # Local dev environment
│ ├── nginx/ # API Gateway configuration
│ └── monitoring/ # Prometheus, Grafana, Loki setup
├── migrations/ # Database migrations
├── scripts/ # Utility scripts
├── PROJECT_TRACKING/ # Project tracking and tasks
│ └── TASKS_OVERVIEW.md # Task list and progress
├── docs/ # Documentation
├── Cargo.toml # Rust workspace
├── ARCHITECTURE.md # Architecture documentation
├── STRUCTURE.md # Code structure guide
└── README.md # This file- Rust (stable + nightly):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Bun:
curl -fsSL https://bun.sh/install | bash(fast JavaScript runtime and package manager for SvelteKit frontend - replaces Node.js) - Docker & Docker Compose: For running local environment
- PostgreSQL Client:
psql(optional, for debugging)
# Install Rust toolchain
rustup default stable
rustup toolchain add nightly
rustup component add clippy rustfmt
# Install cargo tools
cargo install cargo-watch # Auto-reload
cargo install sqlx-cli --features postgres # DB migrations
# Install Bun (if not already installed)
curl -fsSL https://bun.sh/install | bash# Clone repository
git clone <your-repo-url>
cd anthill
# Start PostgreSQL, Redis, NATS
docker-compose up -d
# Return to root directory# Navigate to frontend directory
cd frontend
# Install dependencies
bun install
# Start development server
bun dev
# In another terminal, run backend services...# Return to root directory
cd ..
# Build all services
cargo build --workspace
# Run user-service (default port 3000, configurable via PORT env var)
cargo run --bin user-service
# In another terminal, run inventory-service (port 8001 as per nginx config)
PORT=8001 cargo run --bin inventory-service
# Or run multiple services with different ports (in separate terminals):
# Terminal 1:
PORT=3000 cargo run --bin user-service
# Terminal 2:
PORT=8001 cargo run --bin inventory-service
# Terminal 3:
PORT=8002 cargo run --bin order-service
# And continue with other services...# Run database migrations
sqlx migrate run --database-url postgres://inventory_user:inventory_pass@localhost:5432/inventory_saas
# Verify schema
psql postgres://inventory_user:inventory_pass@localhost:5432/inventory_saas -c "\dt"This project uses pre-commit hooks to automatically check code quality before commits.
# Install pre-commit (one-time setup)
pipx install pre-commit
# Install git hooks (run in project root)
pre-commit install
# Run hooks manually on all files
pre-commit run --all-files
# Skip hooks for a specific commit (use sparingly)
git commit --no-verifyWhat the hooks do:
- ✅ Format Rust code with
cargo fmt - ✅ Lint Rust code with
cargo clippy(blocks commits with warnings) - ✅ Check YAML syntax
- ✅ Trim trailing whitespace
- ✅ Fix end-of-file issues
- ✅ Format TOML files
- ✅ Prevent large files from being committed
# Navigate to frontend directory
cd frontend
# Install dependencies
bun install
# Start development server
bun dev
# Build for production
bun run build
# Preview production build
bun run preview
# Run unit tests (Vitest)
bun run test:unit
# Run E2E tests (Playwright)
bun run test:e2e
# Format code
bun run format
# Lint code
bun run lint# Format code
cargo fmt --all
# Lint code
cargo clippy --all -- -D warnings
# Run tests
cargo test --workspace
# Run specific service with auto-reload
cargo watch -x 'run -p user-service'
# Check code without building
cargo check --workspace# Run migrations
sqlx migrate run --database-url postgres://user:password@localhost:5432/inventory_db
# Create new migration
sqlx migrate add <migration_name>
# Revert migration
sqlx migrate revert --database-url postgres://user:password@localhost:5432/inventory_dbSee details in migrations/. Main tables:
tenants: Tenant informationusers: Users within each tenantproducts: Productsinventory_levels: Inventory levelsorders: Ordersintegrations: Marketplace integrationspayments: Payment transactionscasbin_rule: RBAC policies
- Authentication: Kanidm (OAuth2/OIDC Provider)
- User registration, login, password management
- Multi-factor authentication (Passkeys, WebAuthn, TOTP)
- JWT token issuance and validation
- Session management
- Authorization: Casbin-rs with multi-tenant RBAC
- Policy-based access control
- Group-based role mapping from Kanidm
- Tenant Isolation: Automatically filter queries by
tenant_idfrom Kanidm groups
Each service exposes OpenAPI spec at /api/docs endpoint.
Example: http://localhost:3000/api/docs for user-service.
- Install CapRover on your VPS: https://caprover.com/docs/get-started.html
- Deploy stateful services (PostgreSQL, Redis, NATS) via One-Click Apps
- Create
Dockerfilefor each microservice - Create app in CapRover and connect with GitHub
- Push code → CapRover automatically builds & deploys
See details in docs/production-deployment.md
- Unit Tests:
cargo test- Coverage > 70% - Integration Tests: Test API endpoints with test database
- E2E Tests: Playwright for frontend
- Load Tests: K6 for stress testing
- Logging:
tracingcrate + OpenTelemetry - Metrics: Prometheus + Grafana
- Tracing: Distributed tracing with Jaeger (optional)
- Health Checks:
/healthendpoint for each service
See details in docs/monitoring-setup.md
- Fork repository
- Create feature branch:
git checkout -b feature/amazing-feature - Install pre-commit hooks:
pre-commit install - Make your changes (hooks will run automatically on commit)
- Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Create Pull Request
- Rust: Pre-commit hooks will automatically run
cargo fmtandcargo clippy - Follow existing patterns in the codebase
- Write tests for new features
- Update documentation as needed
- Commit messages: Use conventional commits (e.g.,
feat:,fix:,chore:)
- ARCHITECTURE.md - Detailed system architecture
- STRUCTURE.md - Code structure and patterns
- PROJECT_TRACKING/TASKS_OVERVIEW.md - Task list and progress tracking
- docs/production-deployment.md - Production deployment guide
- docs/monitoring-setup.md - Monitoring setup guide
- docs/troubleshooting.md - Troubleshooting guide
- API Docs - OpenAPI spec at each service endpoint
MIT License - See LICENSE file for more details.
- Your Name - Initial work
- Axum - Web framework
- SvelteKit - Frontend framework
- Kanidm - Identity management platform
- CapRover - PaaS platform
- Casbin - Authorization library
- Cube - Analytics platform
Status: 🚧 In Development - Phase 3 (User Service) & Phase 4 (Inventory Service)
MVP Target: 2-3 months
See PROJECT_TRACKING/TASKS_OVERVIEW.md for detailed progress tracking.