High-level Architecture
Bagisto Native provides a complete ecosystem for building native mobile applications using web technologies. The architecture consists of four main layers that work together seamlessly.
Architecture Overview
Architecture Layers
1. Backend Layer: Bagisto Backend
- Technology: Laravel-based e-commerce platform
- Role: Provides core business logic, database management, and APIs
- Responsibilities:
- Product catalog management
- Order processing
- User authentication and authorization
- Payment gateway integration
- Inventory management
- API endpoints for frontend consumption
2. Frontend Layer: Bagisto Headless
- Technology: Next.js-based headless commerce storefront
- Role: Renders the user interface and handles client-side logic
- Responsibilities:
- Server-side rendering (SSR) and static generation
- SEO optimization
- UI/UX presentation
- Client-side routing
- API integration with backend
- Integration of Bagisto Native Framework components
3. Bridge Layer: Bagisto Native Framework
- Technology: TypeScript/JavaScript modules
- Components:
@bagisto-native/core: Core web components and utilities@bagisto-native/react: React wrappers for web componentsbundle.js: Minified Hotwire web components bundle
- Role: Creates a communication bridge between web and native layers
- Responsibilities:
- Provides Web Components for native interactions
- Manages bidirectional communication
- Exposes utility functions and event triggers
- Handles native feature integration (toast, location, search, etc.)
4. Native Layer: Mobile Applications
- Technology:
- iOS: Swift + Turbo Native iOS
- Android: Kotlin + Turbo Native Android
- Role: Native mobile app shell that wraps the web application
- Responsibilities:
- WebView management
- Native UI components (navigation, toolbars)
- Platform-specific features (camera, location, notifications)
- App store distribution
- Native performance optimization
Data Flow
Request Flow (User Action → Backend)
- User interacts with the mobile app (iOS/Android)
- Native app loads web content via Turbo Native WebView
- Bagisto Headless (Next.js) renders the UI
- User action triggers API call to Bagisto Backend
- Backend processes request and returns response
- Headless updates UI accordingly
- Native app reflects the changes
Native Feature Flow (Web → Native)
- Web application uses Bagisto Native components
- Component triggers event via
bundle.jsbridge - Turbo Native intercepts the event
- Native code executes platform-specific functionality
- Native sends result back via bridge
- Web application receives and processes the result
Key Architectural Principles
Separation of Concerns
Each layer has a distinct responsibility:
- Backend handles business logic
- Headless manages presentation
- Native Framework provides the bridge
- Native apps deliver platform integration
Progressive Enhancement
The application works as a web app first, then enhances with native features when available.
Reusability
The same Bagisto Headless codebase serves:
- Web browsers
- iOS native app
- Android native app
Performance
- SSR/SSG from Next.js for fast initial loads
- Native navigation for app-like experience
- Optimized bridge communication for smooth interactions
Communication Mechanisms
Web to Native
- Custom events dispatched by Web Components
- Hotwire bridge intercepts events
- Native listeners execute corresponding actions
Native to Web
- Native components dispatch custom events
- JavaScript event listeners in web application
- React components react to state changes
Technology Stack Summary
| Layer | Primary Technology | Supporting Technologies |
|---|---|---|
| Backend | Laravel | MySQL/PostgreSQL, Redis, PHP |
| Headless | Next.js | React, TypeScript, Tailwind CSS |
| Bridge | Hotwire | Web Components, Custom Events |
| iOS | Swift | Turbo Native iOS, WebKit |
| Android | Kotlin | Turbo Native Android, WebView |
Benefits of This Architecture
- Code Reusability: Write once (web), deploy everywhere (web, iOS, Android)
- Rapid Development: Leverage web development speed with native app benefits
- Easy Updates: Update web content without app store submissions
- Native Performance: Critical features use native code for best performance
- Maintainability: Clear separation makes each layer easier to maintain
- Scalability: Each layer can scale independently based on needs
Next Steps
- Understand the Web ↔ Native Communication Flow
- Learn about Roles of Components
- Explore Hotwire & Turbo Native
