Skip to content

Commit 3aa2b2c

Browse files
authored
Merge pull request #242 from paroki/feat/sync
sync packages
2 parents ed09b75 + 74fa2c4 commit 3aa2b2c

113 files changed

Lines changed: 13717 additions & 209 deletions

File tree

Some content is hidden

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

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ R2_ACCESS_KEY_ID=
3333
R2_SECRET_ACCESS_KEY=
3434
R2_BUCKET_NAME=
3535
R2_PUBLIC_URL=
36+
37+
# DUK Sync
38+
SYNC_TARGET_URL=https://umat.kasri.id
39+
SYNC_USERNAME=
40+
SYNC_PASSWORD=
41+
SYNC_COOKIE_TTL=3600

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ env:
3535
CF_ACCOUNT_ID: ${{secrets.CF_ACCOUNT_ID}}
3636
WHATSAPP_TOKEN: ${{secrets.WHATSAPP_TOKEN}}
3737
SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}}
38+
SYNC_TARGET_URL: ${{ secrets.SYNC_TARGET_URL }}
39+
SYNC_USERNAME: ${{ secrets.SYNC_USERNAME }}
40+
SYNC_PASSWORD: ${{ secrets.SYNC_PASSWORD }}
41+
SYNC_COOKIE_TTL: 1500
3842

3943
jobs:
4044
check:

AGENTS.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# AGENTS.md
22

3-
This guide is intended for AI agents (Copilot, Cursor, Claude, etc.) working in the **Domus** repository.
3+
This guide is intended for AI agents (Copilot, Cursor, Claude, Gemini etc.) working in the **Domus** repository.
4+
5+
---
6+
7+
# 🛡️ Anti-Hallucination Protocol
8+
1. **Strict Scope:** Code *only* what is explicitly requested. No extra files, no unsolicited features.
9+
2. **Stop & Ask:** If anything is unclear, stop and ask. Zero assumptions.
10+
3. **Brief:** Keep explanations concise and focused.
11+
4. **Read First:** State which `AGENTS.md` section and quote the relevant issue instruction before coding.
12+
5. **Verify Imports:** Only import from paths that explicitly exist in the codebase or issue.
13+
6. **ALWAYS** follow `AGENTS.md` and focus on the current issue only.
14+
7. **Wait for Go:** Never start coding until explicitly told **"gas ngoding"**.
415

516
---
617

718
## Agent Self-Verification Checklist
819

920
**MANDATORY**: Before providing any code response, verify your implementation against this checklist.
10-
1121
- [ ] **No `any`**: Ensure no `explicit any` is used. Use `unknown`, generics, or search `@domus/core` for the correct type.
1222
- [ ] **No `shadcn` edits**: NEVER touch files in `apps/dash/src/shared/ui/shadcn/`. Perform customizations by creating wrapper components or extending styles in other directories.
1323
- [ ] **Result Pattern**: Confirm all services return `Result<T>` via `ok()`/`fail()` and never throw.
@@ -18,6 +28,7 @@ This guide is intended for AI agents (Copilot, Cursor, Claude, etc.) working in
1828
- [ ] **Auth Responsibility**: Check authentication in Proxy/Action and authorization in Service.
1929
- [ ] **Thin Exports**: Ensure route components are logic-less exports.
2030
- [ ] **Naming**: Use entity-only names for services/repositories (no `.service.ts`).
31+
- [ ] **Zod Best Practices**: Use top-level Zod functions (`z.uuid()`, `z.uuidv7()`, `z.email()`, `z.url()`) instead of chained string methods (`z.string().uuid()`, etc.) to support better tree-shaking and follow Zod 4 conventions.
2132

2233
---
2334

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ This project is managed using Turborepo with a **Just-in-Time (JIT) Packages** s
3636
```text
3737
apps/
3838
├── dash/ # Main Web Application (Next.js 16 - Feature-Sliced Design)
39-
└── cron/ # Scheduled Tasks (Cloudflare Workers)
39+
├── cron/ # Scheduled Tasks (Cloudflare Workers)
40+
└── crawler/ # Data Synchronization CLI (Dockerized for Mini PC)
4041
4142
packages/
4243
├── core/ # Business Logic, Entities, Result Pattern (Framework Agnostic)
@@ -97,6 +98,13 @@ Available commands from the root folder:
9798
- `pnpm typecheck` — Run TypeScript compiler checks.
9899
- `pnpm test` — Run unit tests.
99100

101+
## ⚙️ Crawler Deployment
102+
103+
The **Domus Crawler** is a dedicated CLI tool designed to run on a local mini PC at the parish office. It syncs data from the central DUK system to a local database.
104+
105+
For detailed deployment and usage instructions, see:
106+
👉 [apps/crawler/README.md](./apps/crawler/README.md)
107+
100108
## 📄 License
101109

102110
**domus** is released under the **MIT** license. All code and documentation are open source and can be freely used, modified, and distributed in accordance with the license terms.

apps/crawler/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

apps/crawler/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Base image
2+
FROM node:24-alpine AS base
3+
4+
# Install pnpm and essentials
5+
RUN npm install -g pnpm && apk add --no-cache libc6-compat
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy monorepo root config files
11+
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
12+
13+
# Copy internal packages and the crawler app
14+
COPY packages ./packages
15+
COPY apps/crawler ./apps/crawler
16+
17+
# Install dependencies
18+
RUN pnpm install --frozen-lockfile
19+
20+
# Build the crawler
21+
RUN pnpm --filter @domus/crawler build
22+
23+
# Deployment Stage
24+
FROM node:24-alpine AS runner
25+
WORKDIR /app
26+
27+
# Ensure pnpm is available in runner if needed, but we run with node
28+
# For simplicity, we can copy the whole node_modules from base
29+
# or use pnpm deploy in the build stage.
30+
# The instructions say: ENTRYPOINT ["node", "apps/crawler/dist/index.js"]
31+
# This implies we need the dependencies.
32+
33+
# Copy everything from base (including node_modules and source)
34+
COPY --from=base /app /app
35+
36+
# Set entry point
37+
# We use tsx via pnpm start because raw node has issues with ESM extensions in a monorepo
38+
ENTRYPOINT ["pnpm", "--filter", "@domus/crawler", "start"]
39+
CMD ["crawl"]

apps/crawler/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Domus Crawler
2+
3+
A dedicated CLI tool driven by `@domus/sync` to orchestrate data synchronization between the central DUK system and a local parish database. Designed to be deployed on a mini PC within the parish network.
4+
5+
## 🚀 Overview
6+
7+
The crawler performs four main tasks:
8+
1. **Seed**: Populates local regional data (Provinces, Regencies, Districts, Villages) from BPS sources.
9+
2. **Scrape**: Fetches reference data and parishioner records from DUK into a staging area.
10+
3. **Transform**: Processes staged data into production-ready tables in the local database.
11+
4. **Sync-Back**: Pushes local updates (made in Domus) back to the DUK system.
12+
13+
## ⚙️ Configuration
14+
15+
The crawler requires the following environment variables. Create a `.env` file in this directory or pass them to Docker.
16+
17+
| Variable | Description | Example |
18+
| :--- | :--- | :--- |
19+
| `DATABASE_URL` | Local PostgreSQL connection string. | `postgresql://user:pass@localhost:5432/domus` |
20+
| `SYNC_TARGET_URL` | Base URL of the DUK system. | `https://duk-target.com` |
21+
| `SYNC_USERNAME` | Username for DUK system login. | `parish_admin` |
22+
| `SYNC_PASSWORD` | Password for DUK system login. | `********` |
23+
24+
## 🛠️ Usage
25+
26+
### Local Development
27+
28+
Running from the monorepo root:
29+
30+
```bash
31+
# Show help
32+
pnpm --filter @domus/crawler start help
33+
34+
# Run full pipeline
35+
pnpm --filter @domus/crawler start crawl
36+
37+
# Individual commands
38+
pnpm --filter @domus/crawler start seed
39+
pnpm --filter @domus/crawler start scrape
40+
pnpm --filter @domus/crawler start transform
41+
pnpm --filter @domus/crawler start syncback
42+
```
43+
44+
### Docker Deployment
45+
46+
For production deployment on a mini PC:
47+
48+
1. **Build the image** (run from monorepo root):
49+
```bash
50+
docker build -t domus-crawler -f apps/crawler/Dockerfile .
51+
```
52+
53+
2. **Run the container**:
54+
```bash
55+
docker run --rm --env-file .env domus-crawler [command]
56+
```
57+
58+
*Example: Run full crawl*
59+
```bash
60+
docker run --rm --env-file .env domus-crawler crawl
61+
```
62+
63+
## 🏗️ Docker Details
64+
65+
The Dockerfile uses a multi-stage build:
66+
- **Base**: Installs all monorepo dependencies.
67+
- **Run**: Uses `tsx` to execute the TypeScript source directly, ensuring full compatibility with the monorepo's ESM structure without complex build-time transpilation issues.
68+
69+
---
70+
71+
Built with ❤️ for Kristus Raja Barong Tongkok Parish.

apps/crawler/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@domus/crawler",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"start": "tsx src/index.ts",
8+
"build": "tsc",
9+
"start:prod": "node dist/index.js",
10+
"typecheck": "tsc --noEmit"
11+
},
12+
"dependencies": {
13+
"@domus/sync": "workspace:*",
14+
"@domus/db": "workspace:*",
15+
"@domus/core": "workspace:*",
16+
"drizzle-orm": "^0.45.1"
17+
},
18+
"devDependencies": {
19+
"@domus/tsconfig": "workspace:*",
20+
"@types/node": "24.x",
21+
"tsx": "^4.19.3",
22+
"typescript": "^5.7.3"
23+
}
24+
}

0 commit comments

Comments
 (0)