MineSync Docs
MineSync Docs
MineSync Documentation
API ReferenceRoles and Permissions
Reference

API Reference

Technical reference for MineSync's tRPC API routers and procedures.

Overview

MineSync uses tRPC for all client-server communication. There are no REST endpoints for core application features. The API is type-safe end-to-end, with input validation via Zod schemas and automatic TypeScript type inference on the client.

All API calls go through the tRPC handler at /api/trpc. Client-side hooks are generated from src/trpc/react.tsx and used as api.<router>.<procedure>.useQuery(...) or api.<router>.<procedure>.useMutation(...).

Authentication and Authorization

Procedure Types

ProcedureAuth RequiredTenant ScopedDescription
publicProcedureNoNoHealth checks and unauthenticated endpoints.
protectedProcedureYesNoRequires a valid session. Guarantees ctx.session.user is non-null.
tenantProcedureYesYesExtends protectedProcedure. Requires an x-tenant-slug header, verifies tenant existence and user membership. Adds ctx.tenantId and ctx.membership.

Role-Based Access

Procedures that require specific roles use the requireRole middleware:

.use(requireRole(["ADMIN"]))

See Roles and Permissions for the full role matrix.

Tenant Slug

All tenant-scoped API calls include the tenant slug via the x-tenant-slug HTTP header, which is automatically set by the tRPC client based on the current route (/t/[slug]/...).

API Routers

Core Fleet

RouterKeyProcedures
VehiclesvehiclesList, get, create, update, delete fleet vehicles.
FleetfleetFleet-wide queries and statistics.
MetersmetersRecord and query meter readings (SMU/hours).
Maintenance LogsmaintenanceLogsComponent change-out and maintenance event history.

Lifecycle Management

RouterKeyProcedures
DashboarddashboardDashboard summary statistics and charts.
ProfilesprofilesAsset lifecycle profiles and event configuration.
Profile TemplatesprofileTemplatesReusable profile templates.
Work OrdersworkOrdersFull work order CRUD, status transitions, assignment.
TCOtcoTotal cost of ownership calculations and scenarios.

Parts Management

RouterKeyProcedures
PartspartsParts catalog and inventory.
BOMbomBill of materials for vehicles.
Standard JobsstandardJobsReusable job templates with parts and labor.

Benchmark

RouterKeyProcedures
Benchmark DatabenchmarkDataCRUD for failure data, lifecycle stats, Weibull analysis, fleet comparison, risk scoring, cost impact, seasonal analysis, site comparison, and component hierarchy.

Scheduler

RouterKeyProcedures
SchedulerschedulerSchedule scenarios, tasks, and Gantt chart data.
Scheduler ResourcesschedulerResourcesBay, crew, and resource management.
Scheduler ConfigschedulerConfigScheduler settings and constraint rules.
Scheduler ApprovalsschedulerApprovalsMulti-level approval workflows.

AI

RouterKeyProcedures
AIaiAI settings, model discovery, provider checks, conversation CRUD, and message persistence.

Master Data

RouterKeyProcedures
OEMsoemsEquipment manufacturer catalog.
ModelsmodelsEquipment model catalog.
Machine FamiliesmachineFamiliesMachine family groupings.
Component CatalogcomponentCatalogComponent type catalog with hierarchy.
Machine PositionsmachinePositionsPhysical positions on machines.
Work ActivitiesworkActivitiesMaintenance work activity definitions.
Component CategoriescomponentCategoriesComponent grouping categories.
Location CategorieslocationCategoriesSite location categories.

Administration

RouterKeyProcedures
SitessitesMine site management.
CompaniescompaniesCompany / tenant information.
MembersmembersTenant membership and role management.
SettingssettingsTenant-level feature flags and configuration.
AccountaccountUser account and profile management.
NotificationsnotificationsUser notification preferences and delivery.
BillingbillingSubscription and billing information.
AuditauditAudit trail queries.
ThemesthemesUI theme preferences.
BackupbackupDatabase backup and selective restore.
UpdateupdateApplication update checking.
SQLsqlDirect SQL query execution (admin only).

Search

RouterKeyProcedures
SearchsearchGlobal search across entities (Cmd+K).

Input Validation

All procedure inputs are validated with Zod schemas before execution. Invalid inputs return a structured error with the Zod validation details in error.data.zodError.

Error Handling

tRPC errors use standard codes:

CodeMeaning
UNAUTHORIZEDNo valid session.
FORBIDDENValid session but insufficient role or no tenant membership.
NOT_FOUNDRequested resource does not exist or is not accessible.
BAD_REQUESTMissing required input (e.g., no tenant slug).

Data Serialization

MineSync uses SuperJSON as its tRPC transformer. This means Date objects, BigInt values, Maps, and Sets are automatically serialized and deserialized across the wire.

Common Questions

Can I call the API from outside the browser?

Yes, but you need a valid session token. Use pnpm test:token (with the dev server running) to get a token for testing. Include it as a cookie or authorization header.

Is there a REST API?

There are no REST endpoints for core features. The AI router includes OpenAPI metadata annotations for potential future OpenAPI generation, but all production calls go through tRPC.

How do I find the exact input schema for a procedure?

Look at the router file in src/server/api/routers/. Each procedure's .input() call contains the Zod schema with all fields, types, and validation rules.

Work Orders

Create, track, and manage maintenance work orders across your mining fleet with status tracking, priority levels, and audit logging.

Roles and Permissions

User roles in MineSync and what each role can access and modify.

On this page

OverviewAuthentication and AuthorizationProcedure TypesRole-Based AccessTenant SlugAPI RoutersCore FleetLifecycle ManagementParts ManagementBenchmarkSchedulerAIMaster DataAdministrationSearchInput ValidationError HandlingData SerializationCommon QuestionsCan I call the API from outside the browser?Is there a REST API?How do I find the exact input schema for a procedure?