Building a Scalable Monorepo Architecture
How we built a six-app ecosystem with shared packages
Executive summary
A deep dive into how we architected and built the VietProHub ecosystem - a monorepo containing six Next.js applications with shared components,.
The Challenge
We needed to build multiple applications (public-facing and private) that shared code and design patterns while allowing independent deployment and scaling. The applications had different access levels, user bases, and requirements, but needed to maintain consistency.
Key problems
- 1Managing code sharing across 7 different applications
- 2Maintaining consistency in UI/UX across all apps
- 3Implementing different access control levels (public, private, role-based)
- 4Ensuring independent deployability while sharing dependencies
Constraints
- !Limited development team (3-5 developers)
- !Tight timeline (12 months for MVP)
- !Budget constraints for infrastructure
- !Need for rapid iteration and deployment
Our Solution
We implemented a Turborepo-based monorepo architecture with shared packages for common functionality. Each application is independently deployable but shares UI components, utilities, types, and business logic.
Monorepo Structure
Used Turborepo for efficient build caching and task orchestration. Organized code into apps/ and packages/ directories with clear separation of concerns.
- six applications in apps/ directory
- 10 shared packages in packages/ directory
- Shared UI component library (@vietprohub/ui)
- Common utilities and hooks (@vietprohub/lib, @vietprohub/hooks)
- Shared TypeScript types (@vietprohub/types)
- Centralized configuration
Shared Component Library
Built a shared UI component library with 50 reusable components, keeping the apps visually consistent.
- 50 accessible, responsive components
- Dark mode support built-in
- Storybook stories for the shared components
- TypeScript for type safety
- Tailwind CSS for styling
- Framer Motion for animations
Authentication & Authorization
Implemented Firebase Authentication with custom claims for role-based access control across all applications.
- Single sign-on (SSO) across all apps
- Role-based access control (RBAC)
- Custom claims for fine-grained permissions
- Session management with automatic refresh
- Secure middleware for protected routes
Infrastructure & Deployment
Each app is built as a static export and served from Firebase Hosting, with GitHub Actions running the checks and deploys.
- Firebase Hosting for static hosting and CDN
- Firebase for authentication, database, and storage
- GitHub Actions for CI/CD
- Lint, type-check and test gates before a deploy
- Manual deploy workflow with production and staging targets
- Production monitoring with Sentry
Key technical decisions
Turborepo over Nx
Simpler configuration, better caching, and excellent Next.js integration
Firebase over custom backend
Faster development, built-in real-time features, and excellent scalability
Tailwind CSS over CSS-in-JS
Better performance, smaller bundle sizes, and easier theming
TypeScript everywhere
Type safety, better developer experience, and fewer runtime errors
Implementation Details
Project timeline
Phase 1: Foundation (Months 1-3)
- Set up monorepo structure with Turborepo
- Create shared UI component library
- Implement authentication system
- Build first two applications (Main, Blog)
Phase 2: Expansion (Months 4-6)
- Add Family and Kids applications
- Implement real-time features
- Create admin dashboard
- Set up CI/CD pipeline
Phase 3: Polish (Months 7-9)
- Add Work and Product applications
- Implement cross-app features
- Performance optimization
- Automated test suites
Phase 4: Launch (Months 10-12)
- Security hardening
- Load testing and optimization
- Documentation
- Production launch
Implementation challenges
Dependency Management
Solution: Used pnpm workspaces for efficient dependency management and deduplication
Build Performance
Solution: Leveraged Turborepo's task graph so unchanged packages are cached and only affected apps rebuild
Type Safety Across Packages
Solution: Created shared types package and used TypeScript project references
Consistent Styling
Solution: Built design system with Tailwind CSS and documented in Storybook
Results & Impact
Key achievements
Business impact
Lessons Learned
Start with a solid foundation
Investing time in proper architecture and tooling upfront pays dividends later. Our monorepo structure has made adding new applications much faster.
Shared components are crucial
Building the shared component library early kept the apps visually consistent and avoided re-implementing the same UI six times.
Type safety matters
TypeScript caught countless bugs before they reached production. The initial learning curve was worth it.
Automate everything
Our CI/CD pipeline and automated testing have prevented numerous issues and enabled confident deployments.
Monitor proactively
Setting up monitoring and alerting early helped us catch issues before users noticed.
What we’d do differently
- Earlier implementation of E2E testing
- More documentation from the start
- Better performance monitoring and optimization tools
- More structured approach to feature flags
Technologies used
In pictures




The project
See the full project
More details, screenshots, and information about VietProHub Ecosystem.
View project