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.yaml is 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 edit generated/ folders by hand.
  • One identity file: lib/site-config/site.config.ts, imported by both apps.
  • Auth: Clerk sessions (cookies). Middleware clerkAuthMiddleware.ts resolves the Clerk user to a local users row (created on first request), with requireAuth, requireContentAdmin, requirePlatformAdmin guards. 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.ts and lib/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

  1. Describe it in openapi.yaml (request/response schemas). Use type: number + multipleOf: 1 for integers and avoid format: uri (see .agents/memory/openapi-*.md).
  2. pnpm --filter @workspace/api-spec run codegen.
  3. Implement the route in artifacts/api-server/src/routes/, validating with the generated Zod schema; register it in routes/index.ts.
  4. Use the generated hook (useYourOperation) in the web app.
  5. Add a test next to the route (*.test.ts) and a test:<name> script in artifacts/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.ts is public.