Developer guide
๐ฎ๐ฉ Bahasa Indonesia
Architecture
Browser โโโบ web app (React, Vite) artifacts/learnspace static files in production
โ uses generated hooks from lib/api-client-react
โโโ/apiโโโบ API (Express 5, Node 24) artifacts/api-server one process, also runs background jobs
โโ Clerk (sign-in; proxied at /api/__clerk in production)
โโ PostgreSQL via Drizzle lib/db
โโ Midtrans ยท Resend ยท SMTP ยท Discord (optional)
โโ Replit App Storage (uploads; optional)
- One contract:
lib/api-spec/openapi.yamlis the source of truth.pnpm --filter @workspace/api-spec run codegen(Orval) generates the React Query hooks (lib/api-client-react) and Zod validators (lib/api-zod) that the server uses to validate requests and responses. Never editgenerated/folders by hand. - One identity file:
lib/site-config/site.config.ts, imported by both apps. - Auth: Clerk sessions (cookies). Middleware
clerkAuthMiddleware.tsresolves the Clerk user to a localusersrow (created on first request), withrequireAuth,requireContentAdmin,requirePlatformAdminguards. Roles are re-checked inside write transactions. - Access to course content is decided on the server (
lib/course-access.ts): the API returns full, partial (locked modules with syllabus only) or preview content. Never rely on hiding things in the browser. - Payments:
lib/midtrans.ts(Snap transaction, signature check, live status),lib/learning-pass-payments.tsandlib/workshop-payments.ts(orders, idempotent state changes),lib/payment-reconciliation.ts(sweep + email outbox).
Repository map
| Path | What |
|---|---|
artifacts/learnspace/src/pages/ | One file per route (see App.tsx); creator/ and admin/ for the workspace |
artifacts/learnspace/src/components/ | Shared UI; ui/ is shadcn/ui (Radix + Tailwind) |
artifacts/learnspace/src/i18n/ | t(), formatters, locale files |
artifacts/learnspace/src/hooks/ | Progress sync, access checks, feature flags |
artifacts/api-server/src/routes/ | Express routers, mounted under /api in routes/index.ts |
artifacts/api-server/src/lib/ | Business logic, integrations, schedulers, i18n.ts |
lib/db/src/schema/ | Drizzle tables, one file per area |
scripts/ | dev.mjs, with-env.mjs, check-all.sh, src/seed-example-course.ts |
.agents/memory/ | Design notes and pitfalls from building the original site (useful for humans and the Replit Agent) |
Common tasks
Add an API endpoint
- Describe it in
openapi.yaml(request/response schemas). Usetype: number+multipleOf: 1for integers and avoidformat: uri(see.agents/memory/openapi-*.md). pnpm --filter @workspace/api-spec run codegen.- Implement the route in
artifacts/api-server/src/routes/, validating with the generated Zod schema; register it inroutes/index.ts. - Use the generated hook (
useYourOperation) in the web app. - Add a test next to the route (
*.test.ts) and atest:<name>script inartifacts/api-server/package.json.
Change the database Edit lib/db/src/schema/*.ts, then pnpm db:push. Drizzle compares and applies the difference (there are no migration files; review what it proposes before confirming on a database with real data, and back up first).
Add a page Create src/pages/<name>.tsx, add a <Route> (or <ProtectedRoute>) in App.tsx, put its text in a locale area, link it from components/navbar.tsx or footer.tsx.
Tests
docker run -d --name course-test-db -e POSTGRES_PASSWORD=postgres -p 55432:5432 postgres:16 # once
pnpm check
scripts/check-all.sh runs the typecheck, pushes the schema to the test database (TEST_DATABASE_URL, default localhost:55432; it never reads .env), the web tests (Vitest + Testing Library, jsdom) and every API test script (Nodeโs test runner on an esbuild bundle, with placeholder Clerk/Midtrans keys). The API tests create and delete rows, so never point them at a real database.
End-to-end browser tests: pnpm test:e2e against a running site (e2e/README.md); they create temporary Clerk users.
Conventions
- No visible text in code: use
t()/m(). - Money is integers in Rupiah; amounts are always computed on the server.
- Lesson HTML is sanitised on save (server) and on display (
lib/sanitize-html.ts). - Secrets only in environment variables;
site.config.tsis public.