Micro Frontends Architecture with Module Federation · درس

Monorepos أم Polyrepos

قارن بين استراتيجيات المستودعات المختلفة لإدارة عدة Micro Frontends والشيفرة المشتركة بينها

الدرس 1 من 412 خطوة

Monorepos أم Polyrepos درس مجاني في Micro Frontends Architecture with Module Federation على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Micro Frontends Architecture with Module Federation، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Micro Frontends Architecture with Module Federation 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Repository Choices for MFEs

When building Micro Frontends, how you structure your code repositories is a crucial decision. It impacts development workflows, deployment, and team collaboration.

There are two primary strategies: Monorepos and Polyrepos. Let's explore each one and understand their implications for your federated applications.

Understanding Monorepos

A Monorepo (monolithic repository) is a single version-controlled repository that contains multiple distinct projects. These projects can be related or unrelated.

For Micro Frontends, this means all your host applications, remote applications, and shared libraries live in one place.

Monorepo: A Single Home

Here's a common structure for a Monorepo housing Micro Frontends. Notice how applications and shared components reside under one root:

my-mfe-monorepo/
├── apps/
│   ├── host-main-app/    // The shell application
│   ├── remote-dashboard/ // A federated remote app
│   └── remote-profile/   // Another federated remote app
└── packages/
    ├── ui-components/    // Shared UI library
    └── shared-utils/     // Shared utility functions

Monorepo Benefits for MFEs

Monorepos offer several advantages for Micro Frontend development:

  • Simplified Shared Code: Easier to share common components, styles, and utilities across MFEs.
  • Atomic Changes: A single commit can update multiple related Micro Frontends and shared libraries simultaneously.
  • Centralized Configuration: Common build tools and linting rules can be managed centrally.
  • Easier Discovery: All related projects are visible and discoverable in one place.

Monorepo Hurdles

While beneficial, Monorepos come with challenges:

  • Tooling Complexity: Requires sophisticated tools (e.g., Lerna, Nx) to manage dependencies, builds, and tests efficiently.
  • Longer Build Times: A full build can take longer due to the large codebase, though incremental builds help.
  • Access Control: Managing permissions for different teams on parts of the repo can be complex.
  • Git History Noise: The commit history can become very large and busy, making it harder to track changes for specific projects.

Understanding Polyrepos

A Polyrepo (polylithic repository) strategy involves managing each distinct project in its own separate repository. Each Micro Frontend, host application, or shared library gets its own dedicated repo.

This is a more traditional approach, often seen in large organizations with many independent teams.

Polyrepo: Independent Spaces

In a Polyrepo setup, each Micro Frontend or shared component lives in its own independent Git repository:

host-main-app-repo/         // Repo for the main host application
├── src/
└── package.json

remote-dashboard-repo/       // Repo for the dashboard MFE
├── src/
└── package.json

shared-ui-components-repo/   // Repo for a shared UI library
├── src/
└── package.json

Polyrepo Benefits for MFEs

Polyrepos offer distinct advantages, especially for large, distributed teams:

  • Independent Deployments: Each MFE can be deployed independently, reducing coordination overhead.
  • Clear Ownership: Teams have full control over their specific repository and codebase.
  • Simpler CI/CD: Build pipelines are typically simpler as they only focus on one project.
  • Smaller Codebases: Each repository is smaller, making it faster to clone, build, and test locally.

Polyrepo Hurdles

Consider these challenges with Polyrepos:

  • Shared Code Duplication: Without careful management, common code can be duplicated across repositories.
  • Dependency Management: Synchronizing versions of shared libraries across many repos can be complex.
  • Cross-Repo Communication: Changes requiring updates in multiple repos demand more coordination.
  • Discovery & Consistency: Finding shared components or ensuring consistent practices can be harder.

Picking the Right Repository

The choice between Monorepo and Polyrepo depends on your specific context. There's no single best answer.

  • Consider team size: Smaller teams might find Monorepos simpler.
  • Deployment frequency: Polyrepos excel at independent, high-frequency deployments.
  • Shared code needs: If you have many shared components, Monorepos can streamline management.
  • Tooling expertise: Monorepos often require more advanced tooling knowledge.

Evaluate these factors to align your repository strategy with your organizational structure and project goals.

Repository Strategy Check

Which of the following statements are generally TRUE regarding repository strategies for Micro Frontends?

Recap & Next Steps

In this lesson, we explored the Monorepo and Polyrepo strategies for managing Micro Frontend projects.

  • Monorepos offer benefits like simplified shared code and atomic changes, but come with tooling and build time challenges.
  • Polyrepos provide independent deployments and clear ownership, but require careful management of shared dependencies and potential code duplication.

The best choice depends on your team, project complexity, and desired deployment flexibility. Understanding these trade-offs is key to a successful Micro Frontend architecture.

البدء مجانًا

تعلم JavaScript مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «Monorepos أم Polyrepos» مجاني؟

نعم — نص درس «Monorepos أم Polyrepos» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Micro Frontends Architecture with Module Federation، انتقل إلى CoddyKit PRO. تتضمن دورة Micro Frontends Architecture with Module Federation 4 دروس في المجموع.

ماذا ستتعلم في «Monorepos أم Polyrepos»؟

قارن بين استراتيجيات المستودعات المختلفة لإدارة عدة Micro Frontends والشيفرة المشتركة بينها تتمرن على Micro Frontends Architecture with Module Federation مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Micro Frontends Architecture with Module Federation؟

لا تُشترط خبرة سابقة. Micro Frontends Architecture with Module Federation على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «Monorepos أم Polyrepos»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Micro Frontends Architecture with Module Federation هذا؟

نعم. كل درس في Micro Frontends Architecture with Module Federation يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. Monorepos أم Polyrepos
  2. التحديات التنظيمية والحلول
  3. مستقبل Micro Frontends وFederation
  4. التبعيات المشتركة وإدارة الإصدارات
← العودة إلى Micro Frontends Architecture with Module Federation