|
| 1 | +# SNAP-UI Project Architecture |
| 2 | + |
| 3 | +## Core Architecture |
| 4 | + |
| 5 | +**Monorepo Structure**: Turborepo with pnpm workspaces |
| 6 | +- `packages/ui` (@snap-ui): Component library (React 19, TypeScript) |
| 7 | +- `packages/stylish` (@snapverse/stylish): Styling system (empty/WIP) |
| 8 | +- `apps/docs`: Next.js 15 demo app (port 3001) |
| 9 | +- `apps/web`: Next.js 15 app (port 3000) |
| 10 | + |
| 11 | +## Critical Patterns |
| 12 | + |
| 13 | +### Component Architecture |
| 14 | +- **Namespace Pattern**: Components use compound pattern (e.g., `Accordion.Root`, `Accordion.Item`) |
| 15 | +- **Export Structure**: `src/{component}/index.ts` → `namespace.ts` → `{component}.tsx` |
| 16 | +- Each component folder exports via namespace pattern for cleaner API |
| 17 | + |
| 18 | +### Type System |
| 19 | +- Global types in `packages/ui/types/index.d.ts` under `SnapUI` namespace |
| 20 | +- Import types via path alias: `import SnapUI from "#types"` |
| 21 | +- `ComponentProps` extends HTMLDivElement attributes + React.ReactNode |
| 22 | +- `Merge<Left, Right>` utility type prioritizes right side over left |
| 23 | + |
| 24 | +### Component Pattern Example |
| 25 | +```tsx |
| 26 | +// {component}.tsx |
| 27 | +export const ComponentRoot = forwardRef<HTMLDivElement, Props>(...) |
| 28 | +export const ComponentItem = forwardRef<HTMLDivElement, Props>(...) |
| 29 | + |
| 30 | +// namespace.ts |
| 31 | +import { ComponentRoot as Root, ComponentItem as Item } from "./{component}" |
| 32 | +const Component = { Root, Item } |
| 33 | +export default Component |
| 34 | +``` |
| 35 | + |
| 36 | +### Package Exports |
| 37 | +UI package uses wildcard exports: `./*` maps to `./src/*/index.ts` |
| 38 | +- Consumers import: `import Accordion from "@snap-ui/accordion"` |
| 39 | + |
| 40 | +### Code Generation |
| 41 | +Turbo generator at `packages/ui/turbo/generators/config.ts`: |
| 42 | +- Run: `pnpm --filter @snap-ui generate:component` |
| 43 | +- Uses Handlebars template with kebabCase/pascalCase helpers |
| 44 | +- Auto-appends export to package.json |
| 45 | + |
| 46 | +### Build System |
| 47 | +- Turbo tasks: build depends on `^build` (topological) |
| 48 | +- UI package compiles TS → `dist/` (no bundler, just tsc) |
| 49 | +- Next.js apps use Turbopack in dev mode |
| 50 | +- `dev` task is persistent, non-cacheable |
| 51 | + |
| 52 | +### TypeScript Config |
| 53 | +- Base: NodeNext modules, strict mode, ES2022 |
| 54 | +- React libs extend base + add `jsx: "react-jsx"` |
| 55 | +- Path alias `#types` → `./types/index.d.ts` |
| 56 | + |
| 57 | +### Display Names |
| 58 | +All components use `@snapverse/{ComponentName}` for React DevTools |
| 59 | + |
| 60 | +## Key Constraints |
| 61 | +- Node.js >=22 required |
| 62 | +- React 19.1.0 (latest) |
| 63 | +- pnpm@9.0.0 package manager |
| 64 | +- All workspace packages use `workspace:*` protocol |
| 65 | +- ESLint max warnings = 0 (strict) |
| 66 | +- Components are forwardRef wrappers using createElement (not JSX) |
| 67 | + |
| 68 | +## Development Preferences |
| 69 | + |
| 70 | +**CRITICAL**: |
| 71 | +- **Native-first**: Prefer vanilla JS/TS, native Web APIs, and built-in React features over external libraries |
| 72 | +- Only add dependencies when absolutely necessary or explicitly requested |
| 73 | +- **Never run builds**: Only modify code when requested. Building is the user's responsibility |
| 74 | +- Don't suggest `pnpm build` or `npm build` unless explicitly asked |
| 75 | + |
| 76 | +## Development Flow |
| 77 | +1. Generate component: `pnpm --filter @snap-ui generate:component` |
| 78 | +2. Edit in `packages/ui/src/{component}/` |
| 79 | +3. Export via namespace pattern in `namespace.ts` |
| 80 | +4. Apps auto-reload via turborepo watch mode |
| 81 | +5. Type checking: `pnpm check-types` |
| 82 | + |
| 83 | +## Empty/Placeholder Packages |
| 84 | +- `packages/stylish`: Has structure but empty implementation files |
| 85 | +- `packages/ui/src/box`: Empty index.ts |
0 commit comments