Inspiration
The inspiration for Safir came from observing small to medium-sized businesses in Algeria struggling with fragmented tools—managing inventory in spreadsheets, taking orders through WhatsApp or Telegram manually, and juggling service requests across multiple platforms. We envisioned a unified solution that brings everything together: product catalogs, order management, service scheduling, and intelligent AI-powered customer interactions, all accessible through familiar messaging apps. Safir aims to empower local businesses by simplifying operations and enhancing customer experiences.
What it does
Safir is an all-in-one B2B platform that centralizes shop and service management. It allows business owners to:
- Catalog & manage products and services with real-time stock tracking and pricing
- Process orders and service requests seamlessly from a single dashboard
- Deploy intelligent Telegram bots that interact with customers, answer questions, and autonomously create orders or schedule service appointments
- Leverage AI automation powered by Google Gemini or OpenAI to handle customer inquiries, route conversations, and execute transactions
- Configure keyword-based responses for instant automated replies
- Track analytics including order volumes, service requests, response times, and bot activity
- Support multi-project workspaces where each project can have its own Telegram bot, product catalog, and service offerings
- Handle Algerian-specific requirements with built-in support for wilaya-based locations and local phone formats
How we built it
Safir is built using modern web technologies optimized for performance and developer experience:
- Frontend: Next.js 16 (App Router) with React 19, TailwindCSS 4, and Radix UI components for a polished, responsive interface
- Backend: Next.js API routes with server actions for type-safe client-server communication
- Database: PostgreSQL with Prisma ORM for robust data modeling and migrations
- AI Integration: Vercel AI SDK with support for both Google Gemini and OpenAI models, featuring function calling for automated order and service request creation
- Messaging: GramIO for Telegram bot integration with webhook support via ngrok (development) and Vercel (production)
- Authentication: Custom OTP-based passwordless authentication with secure session management
- Development Tools: Bun runtime, Biome for formatting/linting, TypeScript for type safety, and Husky for git hooks
- Infrastructure: Designed for Vercel deployment with environment-based configuration
The architecture emphasizes modularity—AI agents, Telegram bots, and business logic are cleanly separated, making it easy to extend and maintain.
Challenges we ran into
- AI function calling reliability: Ensuring the AI correctly invoked order and service request tools with proper validation while maintaining natural conversational flow required extensive prompt engineering and error handling
- Telegram webhook management: Synchronizing bot lifecycles with project creation/deletion and handling webhook registration across development (ngrok) and production (Vercel) environments
- Stock management complexity: Implementing safe concurrent order processing with stock validation without overselling inventory
- Multi-tenant bot architecture: Managing multiple Telegram bots per project with isolated conversations and state management
- Algerian localization: Handling wilaya data, phone number formats, and ensuring the system works seamlessly for local businesses
- Chat history management: Implementing efficient message history cleanup to keep AI context windows manageable while preserving conversation continuity
- Type safety across boundaries: Maintaining end-to-end type safety from database schemas through server actions to client components
Accomplishments that we're proud of
- Seamless AI-powered ordering: Customers can place complete orders through natural conversation with Telegram bots—the AI collects details, validates inventory, and creates orders autonomously
- Production-ready architecture: Built with enterprise patterns including proper error handling, validation, soft deletes, and database migrations
- Developer experience: Achieved excellent DX with type safety throughout the stack, hot reloading, and clean separation of concerns
- Real-world applicability: Designed specifically for Algerian businesses with practical features like wilaya-based locations and Arabic/French support considerations
- Extensible AI system: Created a flexible AI agent system that can easily support new tools and capabilities beyond orders and service requests
- Complete workflow coverage: Built end-to-end flows from user authentication through onboarding to customer interactions and business analytics
What we learned
- AI agent design patterns: Learned how to structure prompts, handle tool calling, and manage conversation state for reliable AI automation
- Webhook orchestration: Gained deep understanding of webhook lifecycle management, especially when dealing with multiple dynamic bot instances
- Database schema evolution: Mastered Prisma migrations and learned to design schemas that balance normalization with query performance
- Real-time validation trade-offs: Discovered when to validate synchronously vs. asynchronously, especially for inventory checks
- Type-safe full-stack development: Appreciated how TypeScript, Zod, and Prisma work together to create bulletproof data flows
- Telegram bot best practices: Learned message chunking, rate limiting considerations, and error recovery strategies
- Multi-provider AI integration: Understood the nuances of working with different AI providers (OpenAI vs. Google) and abstracting provider differences
What's next for Safir
- WhatsApp Business API integration to reach customers on their preferred platform
- Advanced analytics dashboard with revenue tracking, customer insights, and predictive analytics
- Multi-language support with full Arabic and French translations
- Payment gateway integration for online payment processing (CIB, Edahabia, Flexy)
- Mobile apps for iOS and Android with push notifications for order updates
- Inventory forecasting using AI to predict stock needs and suggest reorder points
- Customer CRM features including order history, loyalty programs, and targeted promotions
- Team collaboration tools with role-based permissions and staff management
- API marketplace allowing third-party integrations and custom extensions
- Advanced service scheduling with calendar views, recurring appointments, and staff assignments
- Multi-warehouse support for businesses with multiple locations
- Automated invoice generation and financial reporting
Built With
- bun
- nextjs
- node.js
- prisma
- shadcn
- typescript