Now we’ll explore advanced code organization patterns and Tailwind CSS configuration strategies that will elevate your development workflow to production standards.
What You’ll Learn
Advanced libs folder architecture and conventions
Feature-based development patterns with shared components
Cross-platform Tailwind CSS implementation
TypeScript path mapping and ESLint configuration
Production-ready code structure recommendations
Recommended Code Structure Conventions
As outlined in our previous article, the foundational folder structure follows this pattern:
monorepo-heaven/├── apps/│ ├── web/ # Next.js web application│ ├── api/ # NestJS backend API│ └── mobile/ # Expo mobile application├── libs/ # Shared libraries (empty for now)├── tools/ # Custom scripts and configurations├── nx.json # NX workspace configuration├── package.json # Root package management└── tsconfig.base.json # Base TypeScript configuration
Let’s examine the libs folder structure in detail, which serves as the core logic container for your entire application.
The Import-Only Pattern for Apps
We strongly recommend importing ready-to-use components and pages into your apps folder rather than implementing logic directly within applications. This approach promotes code reusability and maintainability:
// apps/web/src/app/page.tsxexport { default } from "@frontend/feature-home/web/pages/page"
This pattern ensures your application layers remain thin while business logic is properly organized in feature-specific libraries.
Comprehensive Libs Folder Architecture
Each feature should be generated as a separate library using the NX generator command for consistency and proper configuration:
nx g lib feature-name
The recommended libs structure follows this hierarchical organization:
The shared folder is essential for preventing circular dependencies within your NX application. Consider this scenario: you have a backend feature-auth folder and a frontend feature-auth folder. If you import functions from backend to frontend, and subsequently import from frontend to backend, NX will generate a circular dependency error.
The shared folder serves as a neutral zone for storing variables, helpers, and utilities that require bidirectional imports between frontend and backend modules. This architectural decision becomes crucial as your application scales.
Top tip
Always place shared constants, utilities, and type definitions in the shared folder to avoid circular dependency issues. This pattern becomes increasingly important as your monorepo grows in complexity.
Backend Folder Organization
Our application utilizes NestJS for backend development. Each backend feature contains resolvers, services, modules, and supporting utilities. This modular approach enables seamless inclusion or exclusion of features within your app.module, facilitating rapid feature deployment.
Here’s an example structure for the feature-auth module:
This structure provides optimal development scalability and maintainability through clear separation of concerns:
Architectural Layer Responsibilities
Pages: Exclusively handle server-side data fetching and return section components
Sections: Accept server-side data as props and contain all business logic, state management, data manipulation, and client-side queries
Components: Contain pure UI implementations and accept props exclusively from sections
This architecture enables efficient debugging and development:
Data-related issues: Check sections
Missing data: Verify page fetch requests
UI styling problems: Examine components
Top tip
Maintain the one-page-one-section rule to preserve clear architectural boundaries. For complex scenarios requiring multiple sections, compose them at the page level rather than nesting sections within sections.
Advanced Section Composition
For edge cases requiring multiple sections (such as location search with results display), implement composition patterns:
We’ll create separate configurations for web and mobile applications, as color schemes may align but spacing requirements will inevitably differ between platforms.
Web Application Tailwind Configuration
Configure Tailwind CSS for your Next.js web application:
Important: Since UI logic resides in libs folders, you must add this declaration file to every relevant library and include it in each library’s tsconfig.json to prevent TypeScript compilation errors.
This comprehensive architecture establishes a robust foundation for scalable, cross-platform development within the NX ecosystem. The combination of feature-based library organization, clear separation of concerns through the pages-sections-components pattern, and unified Tailwind CSS configuration across platforms provides the infrastructure necessary for enterprise-level application development.
The architectural decisions outlined in this guide—particularly the shared folder strategy and platform-specific implementations—will prove invaluable as your team scales and your application requirements evolve. By adhering to these conventions from the outset, you ensure maintainable, testable, and performant code across your entire monorepo.