From eebd6a400b82e8b523b8653b68c9e5dfb568a9c8 Mon Sep 17 00:00:00 2001 From: Wallace Osmar Date: Tue, 29 Jul 2025 13:38:28 -0300 Subject: [PATCH] feat: add environment configuration and database setup; implement root layout and page components --- apps/web/package.json | 14 +++-- apps/web/{ => src}/app/favicon.ico | Bin apps/web/{ => src}/app/layout.tsx | 0 apps/web/{ => src}/app/page.tsx | 5 +- apps/web/{ => src}/components/.gitkeep | 0 apps/web/{ => src}/components/providers.tsx | 0 apps/web/src/env.ts | 30 ++++++++++ apps/web/{ => src}/hooks/.gitkeep | 0 apps/web/{ => src}/lib/.gitkeep | 0 apps/web/tsconfig.json | 5 +- docker-compose.yaml | 15 +++++ packages/db/package.json | 2 +- pnpm-lock.yaml | 60 +++++++++++++++++++- pnpm-workspace.yaml | 1 + turbo.json | 4 ++ 15 files changed, 126 insertions(+), 10 deletions(-) rename apps/web/{ => src}/app/favicon.ico (100%) rename apps/web/{ => src}/app/layout.tsx (100%) rename apps/web/{ => src}/app/page.tsx (69%) rename apps/web/{ => src}/components/.gitkeep (100%) rename apps/web/{ => src}/components/providers.tsx (100%) create mode 100644 apps/web/src/env.ts rename apps/web/{ => src}/hooks/.gitkeep (100%) rename apps/web/{ => src}/lib/.gitkeep (100%) create mode 100644 docker-compose.yaml diff --git a/apps/web/package.json b/apps/web/package.json index 7bb502f..0dc131f 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -4,21 +4,24 @@ "type": "module", "private": true, "scripts": { - "dev": "next dev --turbopack", - "build": "next build", + "dev": "pnpm with-env next dev --turbopack", + "build": "pnpm with-env next build", "start": "next start", "lint": "next lint", "lint:fix": "next lint --fix", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "with-env": "dotenv -e ../../.env --" }, "dependencies": { - "@workspace/ui": "workspace:*", + "@t3-oss/env-nextjs": "^0.13.8", "@workspace/db": "workspace:*", + "@workspace/ui": "workspace:*", "lucide-react": "^0.475.0", "next": "^15.2.3", "next-themes": "^0.4.4", "react": "^19.0.0", - "react-dom": "^19.0.0" + "react-dom": "^19.0.0", + "zod": "catalog:" }, "devDependencies": { "@types/node": "^20", @@ -26,6 +29,7 @@ "@types/react-dom": "^19", "@workspace/eslint-config": "workspace:^", "@workspace/typescript-config": "workspace:*", + "dotenv-cli": "catalog:", "typescript": "catalog:" } } \ No newline at end of file diff --git a/apps/web/app/favicon.ico b/apps/web/src/app/favicon.ico similarity index 100% rename from apps/web/app/favicon.ico rename to apps/web/src/app/favicon.ico diff --git a/apps/web/app/layout.tsx b/apps/web/src/app/layout.tsx similarity index 100% rename from apps/web/app/layout.tsx rename to apps/web/src/app/layout.tsx diff --git a/apps/web/app/page.tsx b/apps/web/src/app/page.tsx similarity index 69% rename from apps/web/app/page.tsx rename to apps/web/src/app/page.tsx index e4f893a..e55179b 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -1,6 +1,9 @@ +import { db } from "@workspace/db" import { Button } from "@workspace/ui/components/button" -export default function Page() { +export default async function Page() { + const genres = await db.query.Genre.findMany({}); + console.log(genres) return (
diff --git a/apps/web/components/.gitkeep b/apps/web/src/components/.gitkeep similarity index 100% rename from apps/web/components/.gitkeep rename to apps/web/src/components/.gitkeep diff --git a/apps/web/components/providers.tsx b/apps/web/src/components/providers.tsx similarity index 100% rename from apps/web/components/providers.tsx rename to apps/web/src/components/providers.tsx diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts new file mode 100644 index 0000000..29802fb --- /dev/null +++ b/apps/web/src/env.ts @@ -0,0 +1,30 @@ +import { createEnv } from "@t3-oss/env-nextjs"; +import { z } from "zod/v4"; + +export const env = createEnv({ + /** + * Specify your server-side environment variables schema here. + * This way you can ensure the app isn't built with invalid env vars. + */ + server: { + DATABASE_URL: z.url(), + }, + + /** + * Specify your client-side environment variables schema here. + * For them to be exposed to the client, prefix them with `NEXT_PUBLIC_`. + */ + client: { + // NEXT_PUBLIC_CLIENTVAR: z.string(), + }, + /** + * Destructure all variables from `process.env` to make sure they aren't tree-shaken away. + */ + experimental__runtimeEnv: { + NODE_ENV: process.env.NODE_ENV, + + // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, + }, + skipValidation: + !!process.env.CI || process.env.npm_lifecycle_event === "lint", +}); \ No newline at end of file diff --git a/apps/web/hooks/.gitkeep b/apps/web/src/hooks/.gitkeep similarity index 100% rename from apps/web/hooks/.gitkeep rename to apps/web/src/hooks/.gitkeep diff --git a/apps/web/lib/.gitkeep b/apps/web/src/lib/.gitkeep similarity index 100% rename from apps/web/lib/.gitkeep rename to apps/web/src/lib/.gitkeep diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 8d6f25e..0c7ed94 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -3,8 +3,9 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@/*": ["./*"], - "@workspace/ui/*": ["../../packages/ui/src/*"] + "@/*": ["./src/*"], + "@workspace/ui/*": ["../../packages/ui/src/*"], + "@workspace/db/*": ["../../packages/db/src/*"] }, "plugins": [ { diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..3ce6388 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,15 @@ +services: + db: + image: postgres:17-alpine + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: webnovelfever + ports: + - 5432:5432 + volumes: + - db_data:/var/lib/postgresql/data + +volumes: + db_data: diff --git a/packages/db/package.json b/packages/db/package.json index 16967d4..baaee3e 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -26,7 +26,7 @@ "@types/pg": "^8.15.4", "@workspace/eslint-config": "workspace:*", "@workspace/typescript-config": "workspace:*", - "dotenv-cli": "^9.0.0", + "dotenv-cli": "catalog:", "drizzle-kit": "^0.31.4", "eslint": "^9.20.1", "tsup": "^8.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8594c3c..bac35dd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,9 @@ settings: catalogs: default: + dotenv-cli: + specifier: ^9.0.0 + version: 9.0.0 typescript: specifier: ^5.7.3 version: 5.7.3 @@ -35,6 +38,9 @@ importers: apps/web: dependencies: + '@t3-oss/env-nextjs': + specifier: ^0.13.8 + version: 0.13.8(typescript@5.7.3)(zod@3.25.76) '@workspace/db': specifier: workspace:* version: link:../../packages/db @@ -56,6 +62,9 @@ importers: react-dom: specifier: ^19.0.0 version: 19.0.0(react@19.0.0) + zod: + specifier: 'catalog:' + version: 3.25.76 devDependencies: '@types/node': specifier: ^20 @@ -72,6 +81,9 @@ importers: '@workspace/typescript-config': specifier: workspace:* version: link:../../packages/typescript-config + dotenv-cli: + specifier: 'catalog:' + version: 9.0.0 typescript: specifier: 'catalog:' version: 5.7.3 @@ -101,7 +113,7 @@ importers: specifier: workspace:* version: link:../typescript-config dotenv-cli: - specifier: ^9.0.0 + specifier: 'catalog:' version: 9.0.0 drizzle-kit: specifier: ^0.31.4 @@ -914,6 +926,40 @@ packages: '@swc/helpers@0.5.15': resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==} + '@t3-oss/env-core@0.13.8': + resolution: {integrity: sha512-L1inmpzLQyYu4+Q1DyrXsGJYCXbtXjC4cICw1uAKv0ppYPQv656lhZPU91Qd1VS6SO/bou1/q5ufVzBGbNsUpw==} + peerDependencies: + arktype: ^2.1.0 + typescript: '>=5.0.0' + valibot: ^1.0.0-beta.7 || ^1.0.0 + zod: ^3.24.0 || ^4.0.0-beta.0 + peerDependenciesMeta: + arktype: + optional: true + typescript: + optional: true + valibot: + optional: true + zod: + optional: true + + '@t3-oss/env-nextjs@0.13.8': + resolution: {integrity: sha512-QmTLnsdQJ8BiQad2W2nvV6oUpH4oMZMqnFEjhVpzU0h3sI9hn8zb8crjWJ1Amq453mGZs6A4v4ihIeBFDOrLeQ==} + peerDependencies: + arktype: ^2.1.0 + typescript: '>=5.0.0' + valibot: ^1.0.0-beta.7 || ^1.0.0 + zod: ^3.24.0 || ^4.0.0-beta.0 + peerDependenciesMeta: + arktype: + optional: true + typescript: + optional: true + valibot: + optional: true + zod: + optional: true + '@tailwindcss/node@4.0.8': resolution: {integrity: sha512-FKArQpbrbwv08TNT0k7ejYXpF+R8knZFAatNc0acOxbgeqLzwb86r+P3LGOjIeI3Idqe9CVkZrh4GlsJLJKkkw==} @@ -3696,6 +3742,18 @@ snapshots: dependencies: tslib: 2.8.1 + '@t3-oss/env-core@0.13.8(typescript@5.7.3)(zod@3.25.76)': + optionalDependencies: + typescript: 5.7.3 + zod: 3.25.76 + + '@t3-oss/env-nextjs@0.13.8(typescript@5.7.3)(zod@3.25.76)': + dependencies: + '@t3-oss/env-core': 0.13.8(typescript@5.7.3)(zod@3.25.76) + optionalDependencies: + typescript: 5.7.3 + zod: 3.25.76 + '@tailwindcss/node@4.0.8': dependencies: enhanced-resolve: 5.18.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b75bf05..e13b860 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -4,3 +4,4 @@ packages: catalog: typescript: ^5.7.3 zod: ^3.25.1 + dotenv-cli: ^9.0.0 diff --git a/turbo.json b/turbo.json index 2a73d78..3feb7af 100644 --- a/turbo.json +++ b/turbo.json @@ -32,6 +32,10 @@ "studio": { "cache": false, "persistent": true + }, + "push": { + "cache": false, + "persistent": true } } } \ No newline at end of file