Files
trackgo-fe/.cursor/rules/web-module-architecture.mdc
T
shancheas 44b0ef0168 feat: introduce comprehensive API documentation and RBAC guidelines
- Added a new `api.md` file detailing the TrackGo HTTP API, including agent rules, authentication mechanisms, and global HTTP contracts.
- Established a new RBAC (Role-Based Access Control) framework in `web-rbac.mdc` to ensure all product modules in `apps/web` are gated by permissions from `GET /auth/me`.
- Updated security and web module architecture rules to incorporate RBAC requirements, ensuring consistent application of permissions across modules.

This commit enhances the project's API clarity and security by providing a structured approach to user permissions and interactions.
2026-08-25 19:14:39 +07:00

63 lines
2.8 KiB
Plaintext

---
description: Architecture for feature modules in apps/web (full-page pattern)
globs: apps/web/src/apps/**/*.{ts,tsx}
alwaysApply: false
---
# Web Module Architecture
Working directory: `apps/web/`.
Create authenticated features under `src/apps/main/modules/`.
Canonical sample: `example/full-page/`.
## Directory layout
```text
src/apps/main/modules/<group>/<feature>/
data/ # *RemoteDataServices
domain/
constants/ # ModuleConfigEntity
entities/ # Entity + DTO
factories/ # Wire apiClient + service + transformer
transformers/ # DTO ↔ entity
validators/ # Zod factories (forms)
presentation/
factory/index.tsx # registerModuleNamespace + EnterpriseModuleProvider + routes
pages/ # *.page.index | *.page.form | *.page.detail
components/ # Module-local UI only
store/ # Module zustand (if needed)
languages/{en,id}/ # Module dictionaries
index.tsx # Optional group router (see example/index.tsx)
```
Register: lazy route in `src/apps/main/index.tsx` + menu entry in `src/apps/main/layouts/data/menu.data.ts`.
Auth screens live under `src/apps/auth/` (separate from main modules).
## FULL_PAGE routes (sample)
`/index`, `/detail/:dataId`, `/create`, `/edit/:dataId`, `/duplicate/:dataId` — default redirect to `webUrl/index`.
| Page | Wrapper |
|---|---|
| Index | `EnterpriseIndexPageProvider` + `EnterpriseDataTable` |
| Detail | `EnterpriseDetailPageProvider` |
| Form | `EnterpriseFormPageProvider` + `FormPageType` |
Copy `example/full-page` — do not invent a third layout style.
## Required wiring
1. **Constants** — `ModuleConfigEntity`: `moduleKey`, `translationNamespace`, `apiUrl`, `webUrl`, `moduleCategory` (`FULL_PAGE` | `SINGLE_PAGE`), `moduleType` (`TRANSACTION` | `MASTER_DATA`).
2. **Presentation factory** — `registerModuleNamespace` once at module scope; wrap routes in `EnterpriseModuleProvider`.
3. **Domain factory** — singleton service via `apiClient` from `src/core/lib/api-client` (never raw axios).
4. **i18n** — `useEnterpriseModuleTranslationContext()`; module keys unprefixed; shared via `common:` / `nav:`.
5. **Navigation** — `useEnterpriseModuleNavigationContext()` helpers, not ad-hoc paths.
6. **RBAC** — `moduleKey` must match an `api.md` privilege-keys `code`; the menu leaf uses the same `moduleKey`. See `web-rbac.mdc`.
## Layer rules
- `presentation/` → `domain/` / `data/` via factories; never reverse.
- Shared/reusable across modules → `src/core/` (see web-core-placement).
- Prefer `@repo/ui/components` + `@repo/ui/foundations`; form fields via `@repo/ui/form`.
- Pages: default export, lazy-loaded from the presentation factory.