How amzalfoumi/agentic-erp works
Purpose and Entry Points
AIsle is an agentic supermarket ERP for inventory and purchasing. Its core design exposes one Python domain layer through two backend entry points: FastAPI for the operator UI and MCP tools for AI-driven operations. A separate agent runtime orchestrates model conversations and MCP calls.
• backend/api/main.py
• backend/mcp_server/server.py
• agent/app.py
Shared Domain and Persistence Boundary
backend/core owns SQLAlchemy models, database setup, configuration, actors, enums, and domain exceptions. PostgreSQL is the system of record; Alembic migrations define products, purchasing, action drafts, credit memos, inventory lots, and row-level security. Services operate on this persistence layer rather than adapter-specific request objects.
• backend/core/models.py
• backend/core/database.py
• backend/alembic/versions/20260827_1448-276428c7f1dd_create_purchasing_tables.py
Framework-Free Business Services
backend/services is the primary business-logic boundary: it must not depend on HTTP or MCP. It implements product/catalog operations, inventory lots and spoilage, pricing, suppliers, and purchasing workflows. Services raise shared domain exceptions; outer adapters translate them for their protocols.
• backend/services/products.py
• backend/services/inventory.py
• backend/services/purchasing/receiving.py
HTTP API Adapter
The FastAPI layer provides thin authenticated HTTP routes and schemas for the frontend. Routes resolve dependencies, invoke services, and convert domain failures into HTTP responses. Purchasing, product, inventory, and draft endpoints are separately routed but converge on the same service layer.
• backend/api/main.py
• backend/api/routes/purchasing.py
• backend/api/deps.py
MCP Adapter and Agent Control Flow
The MCP server exposes corresponding backend capabilities as agent-callable tools, with its own authentication and error translation. The agent service manages conversations, selects a model provider, connects to MCP, gates tool execution, and persists conversations/approval state. This creates the flow: user/UI → agent → MCP tools → shared services → Postgres, with approval handling as a control boundary for consequential actions.
• backend/mcp_server/server.py
• agent/conversation.py
• agent/mcp_client.py
Operator Frontend
The Next.js frontend is an inventory-manager client, not a holder of ERP business rules. App-router pages and server actions support products, stock adjustments, spoilage, suppliers, purchasing/orders/receiving, and approvals. Its agent panel communicates through a catch-all proxy route to the agent runtime, while domain API clients communicate with backend services.
• frontend/src/app/layout.tsx
• frontend/src/app/api/agent/[...path]/route.ts
• frontend/src/components/shell/agent-panel.tsx
Runtime and Deployment Topology
Material runtimes are Python 3.12/FastAPI, MCP Python SDK, SQLAlchemy/Alembic, Next.js/TypeScript, and Postgres hosted on Supabase. Dockerfiles exist per frontend, backend, and agent. Deployment assets include Docker Compose and ThunderID identity-provider configuration; database seeding supports the AIsle-box environment.
• backend/Dockerfile
• agent/Dockerfile
• deploy/aisle-box/docker-compose.yml
Main entry points: products.py Business services · app.py Agent service · docker-compose.yml AIsle-box deployment · purchasing.py API routes
Components 18
Operator frontend
- Next.js operator app · Inventory-manager UI and server actions.
frontend/src/app/layout.tsx - Agent panel
frontend/src/components/shell/agent-panel.tsx - Agent proxy route · Catch-all route to the agent runtime.
frontend/src/app/api/agent/[...path]/route.ts
ERP backend
- FastAPI API · Authenticated operator-facing API entry point.
backend/api/main.py - API routes · Purchasing, product, inventory, and draft endpoints.
backend/api/routes/purchasing.py - API dependencies
backend/api/deps.py - MCP tool server · Agent-callable backend tools with protocol-specific auth and errors.
backend/mcp_server/server.py - Business services · Framework-free product, inventory, supplier, pricing, and purchasing workflows.
backend/services/products.py - Inventory operations · Lots, adjustments, and spoilage operations.
backend/services/inventory.py - Purchase receiving
backend/services/purchasing/receiving.py - Domain core · Shared SQLAlchemy models, actors, enums, configuration, and domain exceptions.
backend/core/models.py - Database session
backend/core/database.py
Agent runtime
- Agent service · Selects models, gates consequential tools, and persists approvals.
agent/app.py - Conversation state · Conversations and approval state.
agent/conversation.py - MCP client
agent/mcp_client.py
Data and deployment
- Supabase Postgres · ERP transactional data with row-level security.
- Purchasing migration · Defines purchasing-related tables and data controls.
backend/alembic/versions/20260827_1448-276428c7f1dd_create_purchasing_tables.py - AIsle-box deployment · Composes frontend, backend, and agent runtimes.
deploy/aisle-box/docker-compose.yml
Connections 19
- Next.js operator app → FastAPI API: domain API calls
- Agent panel → Agent proxy route: agent requests
- Agent proxy route → Agent service: forwards
- FastAPI API → API routes: mounts
- API routes → API dependencies: resolves auth and services
- API routes → Business services: invokes
- Business services → Inventory operations: coordinates
- Business services → Purchase receiving: coordinates
- Business services → Domain core: uses models and exceptions
- Domain core → Database session: persists through
- Database session → Supabase Postgres: connects
- Agent service → Conversation state: persists context and approvals
- Agent service → MCP client: orchestrates tool calls
- MCP client → MCP tool server: MCP protocol
- MCP tool server → Business services: invokes shared operations
- Purchasing migration → Supabase Postgres: defines schema
- AIsle-box deployment → Next.js operator app: deploys
- AIsle-box deployment → FastAPI API: deploys
- AIsle-box deployment → Agent service: deploys