Core Principles
This monorepo follows a clean, scalable architecture designed for server-first development using Next.js App Router, TypeScript, XState, and Yup. It establishes standards for:- Separation of Concerns: Clearly delineating responsibilities across layers (UI, Actions, Machines, Services) following principles of Layered Architecture.
- Microfrontend support: Enabling independent development and deployment of distinct business domain applications using a Microfrontend Architecture approach.
- Code reuse: Maximizing code sharing across applications via centralized packages.
- Server state orchestration: Utilizing typed XState machines (State Pattern) to manage complex server-side business processes, orchestrating calls to the Service Layer.
- Structured Service Layer: Employing a domain-driven structure (Strategy Pattern, Factory Method/Service Locator) for defining service abstractions (interfaces, method DTOs) separately from concrete implementations, invoked by state machines.
Monorepo Structure
The project is organized intoapps (deployable units/microfrontends) and packages (shared code).
Project Root Structure
mappnext/ds-tw library, installed as a dependency.
Commands & Setup
Standard commands executed from the root of the monorepo:Common Development Commands
Shared Package Roles (packages/)
Shared functionality is organized into dedicated packages. UI components come from an external library.
| Package | Description | Standard Usage Example |
|---|---|---|
@core | Central hub for domain logic: actions, machines (State Pattern), services (following Strategy/Factory patterns with distinct domain/impl), core types (entities, common, machine), validation schemas. | import { createUserAction } from '@core/actions'; |
@hooks | Reusable React hooks for cross-cutting concerns or complex UI logic. | import { useFormValidation } from '@hooks/forms'; |
@config | Access to environment variables, runtime configuration, feature flags. | import { isBetaFeatureEnabled } from '@config'; |
mappnext/ds-tw/* | Mandatory UI Library (External). Provides all standard UI components. | import { Button } from 'mappnext/ds-tw/atoms/Button'; |
Package aliases (
@core, @hooks, @config) are configured in the root tsconfig.json under paths. These aliases must be used for importing shared code from packages/. UI components must be imported directly from mappnext/ds-tw/*.Tech Stack
The core technologies mandated by this architecture:| Tool | Purpose | Key Location / Usage Area |
|---|---|---|
| Next.js | Full-stack React framework | apps/* (App Router, Server Components, Server Actions) |
| TypeScript | Static typing | Entire codebase (.ts, .tsx) |
| XState | State machines & workflows | packages/core/machines/ (invoked by Actions, call Services) |
| Yup | Schema definition & validation | packages/core/validation/ (used by actions) |
| Turborepo | Monorepo build system/orchestrator | turbo.json, Root commands |
| pnpm | Efficient package manager | Root package.json, workspaces |
| React | Frontend UI library | apps/*, packages/hooks |
mappnext/ds-tw | Standard UI Component Library | External Dependency, Imported in apps/* |
| TailwindCSS | Utility-first CSS framework | Used by mappnext/ds-tw and potentially apps/* |