feat(#1): Set up monorepo scaffold with pnpm workspaces + TurboRepo

Implements the foundational project structure including:
- pnpm workspaces configuration
- TurboRepo for build orchestration
- NestJS 11.1.12 API (apps/api)
- Next.js 16.1.6 web app (apps/web)
- Shared packages (config, shared, ui)
- TypeScript strict mode configuration
- ESLint + Prettier setup
- Vitest for unit testing (19 passing tests)

Fixes #1

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-01-28 13:31:33 -06:00
commit 92e20b1686
109 changed files with 8320 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import prettierConfig from "eslint-config-prettier";
import prettierPlugin from "eslint-plugin-prettier";
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
prettierConfig,
{
plugins: {
prettier: prettierPlugin,
},
rules: {
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/consistent-type-imports": [
"error",
{ prefer: "type-imports" },
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
},
},
{
ignores: ["**/node_modules/**", "**/dist/**", "**/.next/**", "**/coverage/**"],
}
);

View File

@@ -0,0 +1,12 @@
import baseConfig from "./base.js";
export default [
...baseConfig,
{
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
},
},
];

View File

@@ -0,0 +1,17 @@
import baseConfig from "./base.js";
export default [
...baseConfig,
{
rules: {
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
},
},
],
},
},
];

View File

@@ -0,0 +1,29 @@
{
"name": "@mosaic/config",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
"./typescript/base": "./typescript/base.json",
"./typescript/nextjs": "./typescript/nextjs.json",
"./typescript/nestjs": "./typescript/nestjs.json",
"./typescript/library": "./typescript/library.json",
"./eslint/base": "./eslint/base.js",
"./eslint/nextjs": "./eslint/nextjs.js",
"./eslint/nestjs": "./eslint/nestjs.js",
"./prettier": "./prettier/index.js"
},
"dependencies": {
"@eslint/js": "^9.21.0",
"@typescript-eslint/eslint-plugin": "^8.26.0",
"@typescript-eslint/parser": "^8.26.0",
"eslint": "^9.21.0",
"eslint-config-prettier": "^10.1.0",
"eslint-plugin-prettier": "^5.2.3",
"prettier": "^3.5.3",
"typescript-eslint": "^8.26.0"
},
"devDependencies": {
"typescript": "^5.8.2"
}
}

View File

@@ -0,0 +1,13 @@
/** @type {import("prettier").Config} */
const config = {
semi: true,
singleQuote: false,
tabWidth: 2,
trailingComma: "es5",
printWidth: 100,
bracketSpacing: true,
arrowParens: "always",
endOfLine: "lf",
};
export default config;

View File

@@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022"]
}
}

View File

@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"composite": true
}
}

View File

@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"incremental": true,
"target": "ES2022"
}
}

View File

@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"jsx": "preserve",
"module": "ESNext",
"moduleResolution": "bundler",
"allowJs": true,
"noEmit": true,
"incremental": true,
"plugins": [
{
"name": "next"
}
]
}
}

View File

@@ -0,0 +1,40 @@
{
"name": "@mosaic/shared",
"version": "0.0.1",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.js"
},
"./types": {
"types": "./dist/types/index.d.ts",
"require": "./dist/types/index.js",
"import": "./dist/types/index.js"
},
"./utils": {
"types": "./dist/utils/index.d.ts",
"require": "./dist/utils/index.js",
"import": "./dist/utils/index.js"
}
},
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"@mosaic/config": "workspace:*",
"typescript": "^5.8.2",
"vitest": "^3.0.8"
}
}

View File

@@ -0,0 +1,2 @@
export * from "./types/index";
export * from "./utils/index";

View File

@@ -0,0 +1,38 @@
/**
* Base entity type with common fields
*/
export interface BaseEntity {
id: string;
createdAt: Date;
updatedAt: Date;
}
/**
* API response wrapper
*/
export interface ApiResponse<T> {
data: T;
success: boolean;
message?: string;
}
/**
* Pagination parameters
*/
export interface PaginationParams {
page: number;
limit: number;
sortBy?: string;
sortOrder?: "asc" | "desc";
}
/**
* Paginated response
*/
export interface PaginatedResponse<T> {
data: T[];
total: number;
page: number;
limit: number;
totalPages: number;
}

View File

@@ -0,0 +1,61 @@
import { describe, expect, it } from "vitest";
import { isDefined, parseDate, sleep, slugify } from "./index.js";
describe("parseDate", () => {
it("should return undefined for null or undefined", () => {
expect(parseDate(null)).toBeUndefined();
expect(parseDate(undefined)).toBeUndefined();
});
it("should return the same Date object if passed a Date", () => {
const date = new Date("2024-01-15");
expect(parseDate(date)).toBe(date);
});
it("should parse valid date strings", () => {
const result = parseDate("2024-01-15");
expect(result).toBeInstanceOf(Date);
expect(result?.toISOString()).toContain("2024-01-15");
});
it("should return undefined for invalid date strings", () => {
expect(parseDate("not-a-date")).toBeUndefined();
});
});
describe("slugify", () => {
it("should convert text to lowercase slug", () => {
expect(slugify("Hello World")).toBe("hello-world");
});
it("should handle special characters", () => {
expect(slugify("Hello, World!")).toBe("hello-world");
});
it("should trim leading and trailing hyphens", () => {
expect(slugify(" Hello World ")).toBe("hello-world");
});
});
describe("sleep", () => {
it("should resolve after the specified time", async () => {
const start = Date.now();
await sleep(50);
const elapsed = Date.now() - start;
expect(elapsed).toBeGreaterThanOrEqual(45);
});
});
describe("isDefined", () => {
it("should return false for null and undefined", () => {
expect(isDefined(null)).toBe(false);
expect(isDefined(undefined)).toBe(false);
});
it("should return true for defined values", () => {
expect(isDefined(0)).toBe(true);
expect(isDefined("")).toBe(true);
expect(isDefined(false)).toBe(true);
expect(isDefined({})).toBe(true);
});
});

View File

@@ -0,0 +1,35 @@
/**
* Safely parse a date string or return undefined
*/
export function parseDate(value: string | Date | undefined | null): Date | undefined {
if (!value) return undefined;
if (value instanceof Date) return value;
const parsed = new Date(value);
return isNaN(parsed.getTime()) ? undefined : parsed;
}
/**
* Generate a simple slug from a string
*/
export function slugify(text: string): string {
return text
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, "")
.replace(/[\s_-]+/g, "-")
.replace(/^-+|-+$/g, "");
}
/**
* Sleep for a given number of milliseconds
*/
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Check if a value is defined (not null or undefined)
*/
export function isDefined<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}

View File

@@ -0,0 +1,12 @@
{
"extends": "@mosaic/config/typescript/library",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"module": "CommonJS",
"moduleResolution": "node",
"lib": ["ES2022", "DOM"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}

View File

@@ -0,0 +1,14 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: false,
environment: "node",
include: ["src/**/*.test.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: ["node_modules/", "dist/"],
},
},
});

42
packages/ui/package.json Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "@mosaic/ui",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./components/*": {
"types": "./dist/components/*.d.ts",
"import": "./dist/components/*.js"
}
},
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"react": "^19.0.0"
},
"devDependencies": {
"@mosaic/config": "workspace:*",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@types/react": "^19.0.8",
"jsdom": "^26.0.0",
"typescript": "^5.8.2",
"vitest": "^3.0.8"
},
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0"
}
}

View File

@@ -0,0 +1,31 @@
import { describe, expect, it, afterEach } from "vitest";
import { render, screen, cleanup } from "@testing-library/react";
import { Button } from "./Button.js";
afterEach(() => {
cleanup();
});
describe("Button", () => {
it("should render children", () => {
render(<Button>Click me</Button>);
expect(screen.getByRole("button")).toHaveTextContent("Click me");
});
it("should apply variant styles", () => {
render(<Button variant="danger">Delete</Button>);
const button = screen.getByRole("button");
expect(button.className).toContain("bg-red-600");
});
it("should apply size styles", () => {
render(<Button size="lg">Large Button</Button>);
const button = screen.getByRole("button");
expect(button.className).toContain("px-6");
});
it("should pass through additional props", () => {
render(<Button disabled>Disabled</Button>);
expect(screen.getByRole("button")).toBeDisabled();
});
});

View File

@@ -0,0 +1,39 @@
import type { ButtonHTMLAttributes, ReactNode } from "react";
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: "primary" | "secondary" | "danger";
size?: "sm" | "md" | "lg";
children: ReactNode;
}
export function Button({
variant = "primary",
size = "md",
children,
className = "",
...props
}: ButtonProps) {
const baseStyles = "inline-flex items-center justify-center font-medium rounded-md";
const variantStyles = {
primary: "bg-blue-600 text-white hover:bg-blue-700",
secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300",
danger: "bg-red-600 text-white hover:bg-red-700",
};
const sizeStyles = {
sm: "px-3 py-1.5 text-sm",
md: "px-4 py-2 text-base",
lg: "px-6 py-3 text-lg",
};
const combinedClassName = [baseStyles, variantStyles[variant], sizeStyles[size], className]
.filter(Boolean)
.join(" ");
return (
<button className={combinedClassName} {...props}>
{children}
</button>
);
}

2
packages/ui/src/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export { Button } from "./components/Button.js";
export type { ButtonProps } from "./components/Button.js";

11
packages/ui/tsconfig.json Normal file
View File

@@ -0,0 +1,11 @@
{
"extends": "@mosaic/config/typescript/library",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"jsx": "react-jsx",
"lib": ["DOM", "DOM.Iterable", "ES2022"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.tsx"]
}

View File

@@ -0,0 +1,15 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: false,
environment: "jsdom",
include: ["src/**/*.test.tsx", "src/**/*.test.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: ["node_modules/", "dist/"],
},
setupFiles: ["./vitest.setup.ts"],
},
});

View File

@@ -0,0 +1 @@
import "@testing-library/jest-dom/vitest";