Phase 00: Foundation & Prerequisites
Duration: 2-3 days (reduced from 1 week) Goal: Scaffold Legacy ERP WMS app and development environment
Update (Jan 2026): Framework M Phases 1-6 are now substantially complete. Phase 00 is primarily about app scaffolding.
1. Framework M Status β
Section titled β1. Framework M Status β βCompleted
Section titled βCompletedβ| Phase | Status | Notes |
|---|---|---|
| Phase 1: Core Kernel | β Complete | Hexagonal architecture, DI |
| Phase 2: DocType Engine | β Complete | Pydantic models, SQLAlchemy mapping |
| Phase 3: API & Authorization | β Complete | Auto-CRUD, RBAC, RLS |
| Phase 4: Jobs & Events | β Complete | Taskiq + NATS, Event Bus |
| Phase 5: CLI Tools | β Complete | m start, m migrate, m new:app |
| Phase 6: Built-in DocTypes | β Complete | User, Session, File, APIKey, Auth |
Available for Legacy ERP WMS
Section titled βAvailable for Legacy ERP WMSβ- User DocType with password hashing (argon2)
- Session management (Redis/DB backends)
- JWT authentication
- API Key authentication
- OAuth2/OIDC support
- File upload/download (Local + S3)
- Permission system (RBAC + Citadel/Cedar ready)
2. Legacy ERP App Scaffolding
Section titled β2. Legacy ERP App Scaffoldingβ2.1 Create Legacy ERP App Package
Section titled β2.1 Create Legacy ERP App Packageβm new:app legacy_erp_wmsStructure:
apps/legacy_erp_wms/βββ pyproject.tomlβββ src/legacy_erp_wms/β βββ __init__.pyβ βββ doctypes/β β βββ __init__.pyβ β βββ item.pyβ β βββ warehouse.pyβ βββ controllers/β βββ services/βββ tests/2.2 App Configuration
Section titled β2.2 App Configurationβ- Define
legacy_erp_wmsentry point inpyproject.toml - Register with Framework M app registry
- Configure database connection (PostgreSQL)
3. Development Environment
Section titled β3. Development Environmentβ3.1 Local Setup
Section titled β3.1 Local Setupβ- PostgreSQL 15+ (Docker or native)
- Redis 7+
- Python 3.12+ environment
3.2 Docker Compose (Dev)
Section titled β3.2 Docker Compose (Dev)βservices: db: image: postgres:15 environment: POSTGRES_DB: legacy_erp_wms POSTGRES_USER: legacy_erp POSTGRES_PASSWORD: dev_password ports: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data
redis: image: redis:7-alpine ports: - "6379:6379"
volumes: pgdata:3.3 Environment Variables
Section titled β3.3 Environment VariablesβDATABASE_URL=postgresql+asyncpg://legacy_erp:dev_password@localhost:5432/legacy_erp_wmsREDIS_URL=redis://localhost:6379SECRET_KEY=dev-secret-key-change-in-prodDEBUG=true4. Database Setup
Section titled β4. Database Setupβ4.1 Initial Migration
Section titled β4.1 Initial Migrationβ- Generate initial migration:
m migrate create "initial" --autogenerate - Run migration:
m migrate
4.2 Seed Data
Section titled β4.2 Seed Dataβ- Create admin user
- Basic permission setup
5. Verification Checklist
Section titled β5. Verification Checklistβ-
m startruns without errors -
POST /api/v1/auth/loginworks - Database migrations apply cleanly
- Docker build succeeds
- Basic test suite passes
6. Citadel Identity Integration
Section titled β6. Citadel Identity IntegrationβCitadel IAM is an abstraction layer over upstream OIDC-compatible IdPs. It handles user onboarding (admin invite, self-service) and normalizes identity from any IdP.
6.1 Architecture
Section titled β6.1 Architectureββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Upstream IdP (configurable) ββ ββββββββββββ ββββββββββββ ββββββββββββ ββ β Keycloak β β Citadel β β Any OIDC β ββ ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ ββ βββββββββββββββΌββββββββββββββ ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ β OIDC Token βΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Citadel IAM ββ β’ Validates token with upstream IdP ββ β’ Enriches request with X-* headers: ββ X-User-Id, X-User-Attributes, X-User-Roles, etc. ββ β’ If headers too large β adds X-Profile-Lookup header ββ β’ Publishes user events to NATS ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ β X-* Headers (enriched) βΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ WMS App (Framework M) ββ β’ Reads X-User-Id, X-User-Roles from headers ββ β’ If X-Attributes-Truncated=true set β calls Citadel /profile API ββ β’ Maps roles β WMS permissions βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ6.2 Onboarding Methods
Section titled β6.2 Onboarding Methodsβ| User Type | Method | Citadel Config |
|---|---|---|
| HQ Staff | Admin invite (email) | invite_only: true |
| Depot Staff | Admin invite (email) | invite_only: true |
| Outlet Operators | Self-service (phone OTP) | self_service: phone |
| Suppliers | Self-service (email + GSTIN) | self_service: email |
| Beneficiaries | External app (Smart Card) | custom_flow: smart_card |
6.3 Environment Configuration
Section titled β6.3 Environment Configurationβ# .env - Upstream IdP (tokens come from here)OIDC_ISSUER=https://auth.example.com/realms/legacy_erp # Keycloak/ZitadelOIDC_CLIENT_ID=wms-appOIDC_CLIENT_SECRET=<from-idp-admin>
# Citadel IAM API (for onboarding/user management)CITADEL_API_URL=https://citadel.castlecraft.in/apiCITADEL_API_KEY=<from-citadel-admin>6.4 Role Mapping
Section titled β6.4 Role Mappingβ# WMS maps IdP roles (normalized by Citadel) to permissionsROLE_MAPPING = { "wms_admin": ["*:*"], # Full access "ho_staff": ["Item:*", "Supplier:*", "Warehouse:read"], "depot_staff": ["StockEntry:*", "SupplyOrder:*", "Warehouse:read"], "outlet_operator": ["Order:create", "Stock:read"], "supplier": ["SupplierPortal:*"],}6.5 Tasks
Section titled β6.5 Tasksβ- Deploy upstream IdP (Keycloak/Zitadel) or use existing
- Deploy Citadel IAM (or use citadel.castlecraft.in)
- Configure Citadel to use upstream IdP
- Set up onboarding flows (admin invite, self-service)
- Create WMS client in IdP
- Set env variables in WMS
- Test login + onboarding end-to-end
7. Time Estimate
Section titled β7. Time Estimateβ| Task | Duration |
|---|---|
| App scaffolding | 2 hours |
| Dev environment | 2 hours |
| Database setup | 1 hour |
| Citadel IAM setup | 2 hours |
| Verification | 1 hour |
| Total | ~1 day |