Skip to content

Commit 090db2c

Browse files
authored
feat: improvements (#1)
* chore: refactor * feat: filters & pagination * ci: drastically improve build speeds ((hopefully)) ((in theory)) almost 50% improvement on my machine, if i tested correclty that is now this i call blazingly fast * fix: formatter wtf * feat: api docs button * fix: pnpm store path * fix: public folder existance * fix: what was fixable * fix: title :)
1 parent 9bc1ea5 commit 090db2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1505
-2564
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ Dockerfile*
5858
# Logs
5959
logs
6060
*.log
61+
62+
.buildx-cache/

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ polinet.cc is a specialized URL shortener for the polinetwork.org domain ecosyst
1616
- Uses PostgreSQL with raw SQL queries (no ORM)
1717
- Connection pooling via `pg.Pool` singleton in `src/lib/db.ts`
1818
- Database schema auto-initializes on startup
19-
- All database types are Zod schemas exported from `src/lib/db.ts`
19+
- All database types are Zod schemas exported from `src/lib/schemas.ts`
2020
- Service layer in `src/lib/url-service.ts` handles all database operations
2121

2222
### URL Generation & Redirection
@@ -65,7 +65,7 @@ urls (id SERIAL, original_url TEXT, short_code VARCHAR(10) UNIQUE,
6565

6666
- Environment: `DATABASE_URL` for PostgreSQL connection
6767
- Port: Always use 6111 for development
68-
- Short codes: Always 8 characters, generated with nanoid
68+
- Short codes: Automatically generated 8 characters with nanoid, otherwise user set
6969
- Error responses: `{ error: string }` format
7070
- File organization: `/lib` for business logic, `/components` for UI, `/app` for routes
7171
- API base path: `/api` (configured in ts-rest handler)

.github/workflows/build.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ jobs:
2222
- name: Checkout code
2323
uses: actions/checkout@v4
2424

25+
- name: Setup pnpm
26+
uses: pnpm/action-setup@v4
27+
28+
- name: Resolve pnpm store path
29+
id: pnpm-store-path
30+
run: |
31+
echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
32+
2533
- name: Setup Docker Buildx
34+
id: setup-buildx
2635
uses: docker/setup-buildx-action@v3
2736

2837
- name: Log in to Container Registry
@@ -46,12 +55,34 @@ jobs:
4655
type=semver,pattern={{major}}
4756
type=raw,value=latest,enable={{is_default_branch}}
4857
58+
- uses: actions/cache@v4
59+
with:
60+
path: |
61+
${{ steps.pnpm-store-path.outputs.PNPM_STORE_PATH }}
62+
${{ github.workspace }}/.next/cache
63+
# Generate a new cache whenever packages or source files change.
64+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
65+
# If source files changed but packages didn't, rebuild from a prior cache.
66+
restore-keys: |
67+
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.json') }}-
68+
69+
- name: Restore Docker cache mounts
70+
uses: reproducible-containers/buildkit-cache-dance@v3
71+
with:
72+
builder: ${{ steps.setup-buildx.outputs.name }}
73+
dockerfile: Dockerfile
74+
cache-map: |
75+
{
76+
"${{ steps.pnpm-store-path.outputs.PNPM_STORE_PATH }}": "/pnpm/store",
77+
"${{ github.workspace }}/.next/cache": "${{ github.workspace }}/.next/cache"
78+
}
79+
4980
- name: Build and push container image
5081
id: push
51-
uses: docker/build-push-action@v5
82+
uses: docker/build-push-action@v6
5283
with:
5384
context: .
54-
platforms: linux/amd64,linux/arm64
85+
platforms: linux/amd64
5586
push: ${{ github.event_name != 'pull_request' }}
5687
tags: ${{ steps.meta.outputs.tags }}
5788
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/test.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Test
22

33
on:
44
push:
5-
branches: [main, develop]
6-
pull_request:
7-
branches: [main, develop]
85

96
jobs:
107
test:
@@ -25,6 +22,18 @@ jobs:
2522
node-version: "24"
2623
cache: "pnpm"
2724

25+
- name: Setup pnpm + Next.js cache
26+
uses: actions/cache@v4
27+
with:
28+
path: |
29+
/pnpm/store
30+
${{ github.workspace }}/.next/cache
31+
# Generate a new cache whenever packages or source files change.
32+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
33+
# If source files changed but packages didn't, rebuild from a prior cache.
34+
restore-keys: |
35+
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.json') }}-
36+
2837
- name: Install dependencies
2938
run: pnpm install --frozen-lockfile
3039

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
43+
.buildx-cache/

Dockerfile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
# Use the official Node.js 24 Alpine image for smaller size
22
FROM node:24-alpine AS base
3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable pnpm
6+
WORKDIR /app
7+
8+
COPY package.json ./
9+
10+
# Fetch the correct pnpm version without installing deps
11+
# This reads the "packageManager" field and downloads that pnpm version
12+
RUN corepack prepare --activate $(node -p "require('./package.json').packageManager")
13+
RUN pnpm --version
314

415
# Install dependencies only when needed
516
FROM base AS deps
6-
WORKDIR /app
7-
RUN corepack enable pnpm
817

918
# Copy package files
1019
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
11-
RUN pnpm install --frozen-lockfile
20+
RUN --mount=type=cache,id=pnpm,target=./pnpm/store pnpm install --frozen-lockfile
1221

1322
# Rebuild the source code only when needed
1423
FROM base AS builder
15-
WORKDIR /app
16-
RUN corepack enable pnpm
1724

1825
COPY --from=deps /app/node_modules ./node_modules
1926
COPY . .
@@ -24,18 +31,17 @@ COPY . .
2431
ENV NEXT_TELEMETRY_DISABLED=1
2532
ENV SKIP_ENV_VALIDATION=1
2633

27-
RUN pnpm build
34+
RUN --mount=type=cache,id=next,target=./.next/cache pnpm build
2835

2936
# Production image, copy all the files and run next
3037
FROM base AS runner
31-
WORKDIR /app
3238

3339
ENV NODE_ENV=production
3440
# Uncomment the following line in case you want to disable telemetry during runtime.
3541
ENV NEXT_TELEMETRY_DISABLED=1
3642

3743
# Copy the public folder from the project as it's not included in the build output
38-
COPY --from=builder /app/public ./public
44+
COPY --from=builder /app/public* ./public
3945

4046
# Automatically leverage output traces to reduce image size
4147
# https://nextjs.org/docs/advanced-features/output-file-tracing

biome.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"!.next",
1414
"!dist",
1515
"!build",
16-
"!src/app/globals.css" // modified by shadcn
16+
"!src/app/globals.css", // modified by shadcn
17+
"!src/components/ui/*" // modified by shadcn
1718
]
1819
},
1920
"formatter": {

next.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import bundleAnalyzer from "@next/bundle-analyzer"
12
import type { NextConfig } from "next"
23

4+
const ANALYZE_AND_PROFILE = !!process.env.ANALYZE
5+
const withBundleAnalyzer = bundleAnalyzer({ enabled: ANALYZE_AND_PROFILE })
6+
37
const nextConfig: NextConfig = {
48
output: "standalone",
59
transpilePackages: ["@t3-oss/env-nextjs", "@t3-oss/env-core"],
10+
experimental: { swcTraceProfiling: ANALYZE_AND_PROFILE },
611
}
712

8-
export default nextConfig
13+
export default withBundleAnalyzer(nextConfig)

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"name": "tmsu.cc",
2+
"name": "polinet.cc",
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbopack -p 6111",
77
"build": "next build --turbopack",
8+
"build:analyze": "ANALYZE=true SKIP_ENV_VALIDATION=true next build",
89
"start": "next start",
910
"lint": "biome check",
1011
"format": "biome format --write",
@@ -17,12 +18,16 @@
1718
},
1819
"dependencies": {
1920
"@hookform/resolvers": "^5.2.1",
21+
"@next/bundle-analyzer": "^16.0.1",
2022
"@openapi-contrib/json-schema-to-openapi-schema": "^4.2.0",
2123
"@radix-ui/react-dialog": "^1.1.15",
2224
"@radix-ui/react-label": "^2.1.7",
25+
"@radix-ui/react-select": "^2.2.6",
2326
"@radix-ui/react-slot": "^1.2.3",
24-
"@scalar/api-reference-react": "^0.7.42",
27+
"@radix-ui/react-toggle": "^1.1.10",
28+
"@scalar/nextjs-api-reference": "^0.8.23",
2529
"@t3-oss/env-nextjs": "^0.13.8",
30+
"@tanstack/react-query": "^5.90.5",
2631
"@ts-rest/core": "3.52.1",
2732
"@ts-rest/next": "3.52.1",
2833
"@ts-rest/open-api": "3.52.1",
@@ -41,6 +46,7 @@
4146
"react-hook-form": "^7.62.0",
4247
"sonner": "^2.0.7",
4348
"tailwind-merge": "^3.3.1",
49+
"use-debounce": "^10.0.6",
4450
"zod": "^3.24.1"
4551
},
4652
"devDependencies": {

0 commit comments

Comments
 (0)