No description
  • Python 70.7%
  • TypeScript 28.9%
  • CSS 0.2%
  • JavaScript 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Pylon 0bf31132f1 backend: implement serialized inventory integrity for lifecycle paths
Fixes two correctness risks identified during audit:

- _end_item_serialized: validates each serial unit has status 'received'
  and holder_type in 'project_pool'/'user_assignment' before marking
  terminal, preventing inaccurate custody audit trails.

- _recover_lost_serialized: verifies selected serials are actually
  linked to the referenced end_lost transaction via serial_transaction_links
  (using serial_unit_id + direction == 'from'), preventing a recovery
  from writing a reversal link for any qualifying lost unit on the row.

Includes test_serialized_inventory.py with 16 integration tests covering
delegate, warehouse_transfer, relocate, assign/unassign, end, and
recover_lost for both serialized and non-serialized paths.

Related: M10 milestone, V1 Docs/milestones/M10-serialized-inventory-integrity.md
2026-08-18 17:18:19 +00:00
.pi/runs/workflows M7 manual verification repairs 2026-08-14 14:00:40 -06:00
backend backend: implement serialized inventory integrity for lifecycle paths 2026-08-18 17:18:19 +00:00
docker docker: finalize local infrastructure workflow 2026-03-31 14:28:12 -06:00
docs Sync 2026-08-13 19:31:21 -06:00
frontend frontend: add project item assignment flows 2026-08-16 03:06:01 +00:00
V1 Docs backend: implement serialized inventory integrity 2026-08-18 14:19:05 +00:00
.env.example backend: make cors origins and oauth redirect uris config-driven 2026-04-02 18:38:53 -06:00
.gitattributes Initial commit 2026-03-31 13:11:37 -06:00
.gitignore root: ignore OpenClaw workspace files 2026-08-16 03:06:22 +00:00
AGENTS.md backend: implement serialized inventory integrity 2026-08-18 14:19:05 +00:00
docker-compose.yml Sync 2026-08-13 19:31:21 -06:00
LOCAL_TEST_USERS.md Update LOCAL_TEST_USERS.md 2026-04-01 13:46:30 -06:00
package-lock.json Initial docs commit and frameout 2026-03-31 13:38:11 -06:00
package.json Initial docs commit and frameout 2026-03-31 13:38:11 -06:00
README.md Sync 2026-08-13 19:31:21 -06:00

TrackStack v2

TrackStack v2 is a multi-tenant logistics platform for managing projects, materials, assets, vendor collaboration, and transfer workflows.

Tech Stack

Layer Choice
Backend framework FastAPI
ORM SQLAlchemy 2.x (async, via asyncpg)
Database PostgreSQL 16
Auth Custom JWT access tokens + opaque refresh tokens
Password hashing Argon2id (primary), bcrypt (fallback)
Frontend framework React 19
Build tool Vite
CSS Tailwind CSS
Language TypeScript (strict mode)
Server state TanStack Query v5
Forms React Hook Form + Zod
Routing React Router v7
Infrastructure Docker Compose for local dev

Getting Started

Prerequisites

  • Docker Desktop with Docker Compose support
  • Node.js 22+
  • Python 3.12+

Quick Start

# 1. Copy the environment template
cp .env.example .env

# 2. Install the root toolchain
npm install

# 3. Install frontend dependencies
npm run install:frontend

# 4. Start Docker services plus the local Vite dev server
npm run dev:full

# 5. Run shared migrations inside the backend container
docker compose exec backend python scripts/run_migrations.py

# 6. Bootstrap the first superadmin
docker compose exec backend python scripts/create_superadmin.py --email admin@trackstack.local

This starts PostgreSQL, MinIO, and the FastAPI backend in Docker, while the React frontend runs locally for fast hot module reload.

For a production-style all-container run, use npm run docker:up to include the built frontend container as well.

Bootstrap The First Superadmin

After the backend container is running and shared migrations have been applied, create the first platform superadmin from the repo root:

docker compose exec backend python scripts/create_superadmin.py --email admin@trackstack.local

You can also pass --password <value> directly, but omitting it is safer because the script prompts securely.

Run Shared Migrations

Apply shared-schema migrations against the running database:

docker compose exec backend python scripts/run_migrations.py

If there are no new migrations, the script reports that there are no pending shared migrations.

The bootstrap command is idempotent:

  • If a superadmin already exists, it prints a message and exits without creating a duplicate.
  • If the email already belongs to another user, it prints guidance and exits non-zero.
  • New superadmin users are created as active, email-verified platform administrators.

Provision And Verify Tenant Routing

Once the backend is running and a superadmin can authenticate, you can exercise the M2 tenant provisioning and routing flow end to end:

# Create a tenant from the platform layer.
curl -X POST http://127.0.0.1:8000/api/admin/tenants \
  -H "Authorization: Bearer <superadmin_access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Telecom",
    "slug": "acme-telecom",
    "owner_user_id": "<owner_user_uuid>"
  }'

# List the tenants the current user can access.
curl http://127.0.0.1:8000/api/tenants \
  -H "Authorization: Bearer <access_token>"

# Verify tenant-scoped routing against the active tenant schema.
curl http://127.0.0.1:8000/api/tenants/<tenant_uuid>/ping \
  -H "Authorization: Bearer <access_token>" \
  -H "X-Tenant-Id: <tenant_uuid>"

When npm run dev:frontend or npm run dev:full is running, the temporary frontend verification surface at http://127.0.0.1:3000/login lists tenant memberships, lets you switch the active tenant, and includes a Test Tenant Request button to confirm X-Tenant-Id injection through the frontend API client.

Manual Start

If you want separate terminals without using npm run dev:full, keep the backend in Docker and start only the frontend locally:

# Backend services
docker compose up -d db minio backend
docker compose exec backend python scripts/run_migrations.py

# Frontend (separate terminal)
npm run dev:frontend

Full Docker Start

docker compose up --build

Available Scripts

Command Purpose
npm run dev:full Launch Docker services (db, minio, backend) and the local Vite frontend together
npm run dev:services Launch only Docker services
npm run dev:frontend Launch only the Vite dev server
npm run docker:up Build and start all Docker services, including the frontend container
npm run docker:down Stop all Docker services
npm run install:frontend Install frontend npm dependencies

Project Structure

.
├── backend/               # FastAPI application and backend tooling
│   ├── app/
│   │   ├── api/
│   │   │   ├── dependencies/  # FastAPI Depends helpers (auth, tenant context)
│   │   │   └── routes/        # HTTP route handlers (thin)
│   │   ├── core/          # Config, DB, security, errors, logging
│   │   ├── integrations/  # External provider interfaces
│   │   ├── middleware/    # Request ID, auth context, tenant context
│   │   ├── models/
│   │   │   ├── shared/    # SQLAlchemy models for public schema
│   │   │   └── tenant/    # SQLAlchemy models for tenant schemas
│   │   ├── repositories/
│   │   │   ├── shared/    # Data access for public schema
│   │   │   └── tenant/    # Data access for tenant schemas
│   │   ├── schemas/       # Pydantic request/response models
│   │   ├── services/      # Business logic (grouped by domain)
│   │   └── ws/            # WebSocket handlers
│   ├── migrations/
│   │   ├── shared/        # Shared schema SQL migrations
│   │   └── tenant/        # Tenant schema template migrations
│   ├── scripts/           # Admin and provisioning helpers
│   └── tests/
├── frontend/              # React application
│   └── src/
│       ├── app/           # App bootstrap and router
│       ├── components/    # Shared UI primitives
│       ├── context/       # Simple React contexts
│       ├── features/      # Domain feature modules
│       ├── layouts/       # Shell layouts
│       ├── lib/           # API client, auth-api, admin-api, branding-api
│       ├── pages/         # Route pages
│       ├── providers/     # Query, auth, tenant, and app providers
│       ├── routes/        # Route definitions and guards
│       └── types/         # Shared frontend types
├── docs/                  # Sprint plans and evolving project docs
├── docker/                # Dockerfiles and container support assets
├── V1 Docs/               # Foundational architecture reference set
├── docker-compose.yml     # Local development stack
├── AGENTS.md              # Project-wide coding and architecture rules
├── package.json           # Root workspace scripts
└── .env.example           # Environment template

Architecture Summary

TrackStack v2 uses schema-per-tenant isolation:

  • The shared public schema stores platform-wide records such as users, tenants, memberships, and auth sessions.
  • Each tenant gets its own tenant_<uuid_prefix> schema for business data such as projects, materials, assets, vendors, transfers, and notifications.
  • Tenant-scoped API requests require X-Tenant-Id, and backend membership checks must happen before setting the database search_path.

The frontend is organized into four surfaces:

  • Public marketing/auth routes
  • Client dashboard shell
  • Vendor portal shell
  • Superadmin shell

Documentation

Document Purpose
V1 Docs/00-architecture-overview.md Architecture overview and core decisions
V1 Docs/01-glossary.md Canonical vocabulary and naming rules
V1 Docs/02-multi-tenant-architecture.md Schema-per-tenant design
V1 Docs/03-authentication.md JWT auth and refresh token design
V1 Docs/04-authorization-rbac.md RBAC layers and authorization rules
V1 Docs/05-database-schema.md Shared and tenant schema design
V1 Docs/06-backend-architecture.md Backend layering and conventions
V1 Docs/07-api-specification.md API contracts and endpoint conventions
V1 Docs/08-frontend-architecture.md Frontend shell, state, and routing design
V1 Docs/09-vendor-portal.md Vendor access model and portal behavior
V1 Docs/10-infrastructure.md Local infrastructure and deployment guidance
V1 Docs/11-migration-guide.md Legacy migration and phased rollout notes
V1 Docs/milestones/ Milestone-by-milestone implementation plan