API Standards
To ensure consistency, security, and AI-native readiness, all API development in Tonnex must follow these standards.Architecture
We use NestJS as the core logic engine, Drizzle ORM for database access, and Supabase for Auth and RLS.Service Pattern
All services must use thedb.rls pattern to ensure multi-tenancy is enforced.
Agentic Tier API Design
To be truly AI-Native, APIs must act as intelligent interfaces for autonomous agents, facilitating reasoning and self-correction.- Semantic Reasoning: Services should return enriched data including a
reasoningfield explaining why an action was taken (e.g., “Vehicle chosen via proximity algorithm”). - Actionable Feedback (Self-Correction Hints): Error responses should include a
correctionHint. Instead of just400 Bad Request, provide context like"Invalid pincode for the given city. Please correct or provide a valid pincode for [City Name]." - Static Discovery (The Agent Manual): Use deep Swagger (
@ApiOperation) instructions as a manual for AI agents to plan their actions before execution. - Standardized Response Envelope:
- Success:
{ success: true, data: T, reasoning?: string } - Error:
{ success: false, error: string, correctionHint?: string }
- Success: