OpenLearn API
  • TypeScript 88%
  • Python 11.4%
  • JavaScript 0.4%
  • Dockerfile 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Sandro Alves 827519ed54 test(api): fix type errors in spec mocks
The husky pre-commit hook was never installed, so tsc --noEmit never
ran on the test files and ~20 type errors accumulated in the spec
mocks. Fix them: literal course levels, mockResolvedValue arguments,
ApiPrincipal roles/username, Prisma delegate casts in the seed memory
client, a non-circular LockCallback type for withStatsLock, and
Promise-returning operation mocks.
2026-08-22 03:17:14 +01:00
.husky feat(api): rate limiting, atomic gameplay, refresh tokens and hardening 2026-08-13 23:31:34 +01:00
.yarn/releases chore(api): drop railway scripts and untrack install-state 2026-08-22 03:02:10 +01:00
docs docs(api): document security hardening and refresh test counts 2026-08-22 03:02:54 +01:00
prisma feat(api): protect admins from removing their own access 2026-08-16 03:38:06 +01:00
scripts refactor(scripts): consolidate python tooling 2026-08-19 17:46:45 +01:00
src test(api): fix type errors in spec mocks 2026-08-22 03:17:14 +01:00
test refactor(api): remove dead code and deduplicate shared helpers 2026-08-14 00:49:54 +01:00
.dockerignore feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
.env.example docs(api): document security hardening and refresh test counts 2026-08-22 03:02:54 +01:00
.gitignore refactor(scripts): consolidate python tooling 2026-08-19 17:46:45 +01:00
.node-version feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
.oxlintrc.json feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
.prettierrc feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
.yarnrc.yml style: format yaml config files 2026-08-18 00:18:39 +01:00
commitlint.config.ts feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
docker-compose.yml style: format yaml config files 2026-08-18 00:18:39 +01:00
Dockerfile chore(api): run container as non-root user 2026-08-22 03:02:51 +01:00
eslint.config.mjs feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
LICENSE feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
nest-cli.json refactor(api): Go-like layout with cmd/ entrypoints and flat internal domains 2026-08-14 00:45:53 +01:00
openapi.json chore(api): regenerate openapi spec with password endpoint 2026-08-22 03:16:36 +01:00
package.json chore(api): drop railway scripts and untrack install-state 2026-08-22 03:02:10 +01:00
prisma.config.ts feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
README.md docs(api): document security hardening and refresh test counts 2026-08-22 03:02:54 +01:00
tsconfig.build.json feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
tsconfig.json feat(auth): rotate admin password on every startup 2026-08-12 16:58:32 +01:00
yarn.lock feat(api): rate limiting, atomic gameplay, refresh tokens and hardening 2026-08-13 23:31:34 +01:00

Platform API

NestJS REST API for OpenLearn. It serves PostgreSQL data through Zod-validated endpoints, protects them with rate limiting and refresh-token auth, and documents everything in Swagger.

Full documentation lives in docs/ — architecture, setup, scripts, testing and operations.

Quick start

yarn install
docker compose up -d postgres
cp .env.example .env
yarn prisma:generate && yarn prisma:migrate && yarn prisma:seed
yarn start:dev

The API listens on http://localhost:4000. Swagger docs are at http://localhost:4000/api/docs.

Stack

Layer Technology
Runtime Node.js 24 + NestJS 11
Language TypeScript
Database PostgreSQL via Prisma ORM
Validation Zod + nestjs-zod
Auth JWT access + rotating refresh tokens
Docs Swagger at /api/docs
Linting oxlint, then ESLint
Formatting Prettier
License AGPL-3.0-or-later

Environment variables

Variable Description
DATABASE_URL PostgreSQL connection string
PORT HTTP port (default 4000)
AUTH_SECRET Secret for signing JWTs (min 32 characters)
FRONTEND_URL Allowed CORS origin
ADMIN_EMAIL Admin account email
ACCESS_TOKEN_TTL Access token lifetime (default 900)
REFRESH_TOKEN_TTL Refresh token lifetime (default 30 days)
APP_TIMEZONE Timezone for streak calculations
SWAGGER_ENABLED Force Swagger UI on/off (off in production by default)
API_KEY_ENCRYPTION_SECRET Master key for BYOA API keys at rest (AES-256-GCM)

The full reference, including rate limits and AI settings, lives in .env.example.

Scripts

yarn start:dev             # Dev server with watch
yarn build                 # Compile to dist/
yarn start:prod            # Run the compiled server (dist/cmd/server/main)
yarn lint                  # oxlint + ESLint
yarn test                  # Unit tests
yarn test:e2e              # E2E tests
yarn openapi:check         # Regenerate + validate the OpenAPI spec
yarn prisma:migrate        # Run pending migrations
yarn prisma:migrate:deploy # Apply migrations in deployed environments
yarn prisma:seed           # Upsert the canonical learning content
yarn prisma:studio         # Open Prisma Studio

Python helper scripts (API tests, diagnostics, installs, backups, credential collection) are summarized in docs/scripts.md; the full usage reference lives in scripts/README.md.

Project structure

src/
  cmd/                      # Entrypoints (Go-style)
    server/                 # main.ts + swagger-config.ts
    openapi/                # generate-openapi.ts (tooling)
  internal/                 # Application code
    app/                    # app.module.ts (composition root)
    <domain>/               # auth, users, courses, ai, admin, health
      <domain>.controller.ts
      <domain>.service.ts
      <domain>.repository.ts
      <domain>.schemas.ts   # request + response Zod schemas
      <domain>.constants.ts
      swagger.decorators.ts
      *.spec.ts             # co-located tests
    shared/                 # HTTP error helpers, seed helpers
    infra/prisma/           # PrismaModule (global), PrismaService

See docs/architecture.md for the full layout and conventions.