Architecting a hybrid app in a monorepo environment is a powerful way to manage multiple platforms (iOS, Android, Web, Desktop) while sharing code, enforcing consistency, and improving developer velocity. But it comes with complexity — especially in dependency management, build pipelines, and platform-specific logic.
Here’s a battle-tested architecture and strategy guide, combining lessons from projects like Expo, Capacitor, React Native, Flutter, and Bazel-inspired toolchains.
🧱 1. Define Your App Architecture First (Cross-Platform)
Before worrying about monorepo structure, decide how your application logic will be shared:
✅ Recommended Architecture Layers
+---------------------+
| UI Layer | ← Platform-specific (React Native, Flutter, SwiftUI)
+---------------------+
| Shared UI Components| ← Shared across platforms (buttons, modals)
+---------------------+
| Business Logic | ← Shared logic (auth, payments, navigation)
+---------------------+
| Data Access Layer | ← Shared APIs (REST, GraphQL, DB access)
+---------------------+
| Platform Adapters | ← Platform-specific integrations (camera, file system)
+---------------------+
This abstraction lets you isolate platform-specific code while maximizing reuse.
🗂️ 2. Monorepo Structure (Tool-Agnostic Template)
A hybrid monorepo should support:
- Multiple platforms (Web, Mobile, Desktop)
- Shared code
- Platform-specific overrides
- Parallel development
📁 Recommended Folder Structure:
apps/
├── web/ # React/Web (Next.js, Vite, CRA)
├── mobile/ # React Native / Flutter / Capacitor
├── desktop/ # Electron / Tauri / Flutter Desktop
libs/
├── ui/ # Shared UI components (e.g., buttons, navbars)
├── core/ # Shared business logic (auth, user, config)
├── data/ # Shared API layers (axios, GraphQL client)
├── device/ # Platform-abstracted device features (camera, sensors)
├── adapters/
│ ├── android/ # Platform-specific code (Java/Kotlin)
│ ├── ios/ # Swift/Objective-C
│ └── web/ # JS polyfills or fallbacks
scripts/ # Build/test/lint scripts
tools/ # Codegen, linting, formatting, bundlers
💡 You can use TurboRepo (for JS/TS), Nx, Bazel, or Pants for managing dependencies and caching builds across packages.
🔧 3. Choose a Monorepo Toolchain
| Tool | Best For | Highlights |
|---|
| Nx | Multi-language (JS, TS, Java, C++) | Strong dependency graph, task runners, workspace caching |
| Turborepo | JavaScript/TypeScript-first | Fast caching, incremental builds, used by Vercel |
| Yarn Workspaces / PNPM Workspaces | Lightweight | Great for pure JS/TS monorepos |
| Bazel | Large-scale, high-performance builds | Used by Google, Uber, Figma (steep learning curve) |
For a React Native + Web hybrid, Turborepo + Yarn/PNPM workspaces is a sweet spot.
🧩 4. Sharing Code Across Platforms
✅ Shared Libraries (Libs/)
- Use TypeScript for type safety and shared typings.
- Use peerDependencies for shared libs to avoid duplication.
- Use conditional exports (e.g.,
exports in package.json) to allow platform-specific behavior.
Example:
// libs/device/useCamera.ts
export * from './web/useCamera.web';
export * from './native/useCamera.native';
✅ Platform Abstractions
- Create a unified API interface (e.g.,
CameraService) with platform-specific implementations.
- Use dependency injection (DI) or runtime resolution to swap implementations per platform.
📦 5. Dependency Management Tips
- Use workspaces to link local packages (no need to publish to npm).
- Avoid circular dependencies (especially between
core and ui).
- Version your internal packages (even locally) using
changesets or lerna.
- Use patch-package or workspace overlays to patch upstream dependencies.
🚀 6. Build & CI/CD Strategy
🔄 Build Automation
- Use TurboTasks or Nx targets to define reusable build/test/lint/deploy tasks.
- Example:
turbo run build --filter=app.mobile or nx run-many --target=build --all.
🧪 Testing
- Centralize test runners (
jest, playwright, detox, flutter_test).
- Use workspace-level caching to speed up tests.
📲 CI/CD Pipeline
- Run platform-specific pipelines (e.g.,
mobile runs detox/e2e tests).
- Use Fastlane for app store deployment.
- Bundle shared libraries separately (or inline with apps if small).
🧪 7. Testing & Quality
| Area | Tools |
|---|
| Unit Testing | Jest, Vitest |
| UI Testing | Detox (mobile), Playwright (web) |
| Linting | ESLint + Prettier |
| Formatting | Prettier or clang-format (for native) |
| Type Checking | tsc, eslint --ext .ts |
🛠️ 8. Platform-Specific Integrations
Use capacitor, react-native, or flutter plugins to bridge native functionality.
- Group plugins per platform in
libs/adapters/ios, libs/adapters/android.
- Use custom native modules only when absolutely necessary.
- For Flutter: use
platform_channels + shared Dart services.
🧭 9. Documentation & Developer Experience
- Use
README.md per package to explain usage and dependencies.
- Automate onboarding scripts (
yarn setup, devcontainer, nx init).
- Enforce conventional commits and changelog generation.
- Consider Storybook for shared UI components.
🧠 10. Pro Tips
- Start small: Begin with a few shared libraries (e.g.,
ui, core) and grow.
- Avoid premature optimization: Don’t over-engineer DI or abstraction layers early.
- Treat shared libraries as products: version, document, and test them independently.
- Align with your team’s strengths: If your team is mostly web-focused, favor React Native + Web-first.
✅ Summary Checklist
| Step | Done? |
|---|
| Chosen a shared architecture (UI, Core, Device, Adapter) | ✅ |
| Set up a monorepo with workspaces / Nx / Turborepo | ✅ |
| Structured folders cleanly by domain/function | ✅ |
| Abstracted platform-specific code behind interfaces | ✅ |
| Automated builds/tests with caching | ✅ |
| Defined CI/CD pipeline per platform | ✅ |
| Documented libraries and onboarding process | ✅ |
🔚 Final Thoughts
A well-architected hybrid monorepo can scale from MVP to enterprise-grade apps. It promotes code reuse, reduces duplication, and accelerates cross-platform delivery. But it requires upfront investment in clean boundaries, strong conventions, and developer tooling.
🎯 Start with shared logic and UI, isolate platform specifics, and automate everything.
Need a template to start from? Check out:
Happy coding! 🚀