This microservice provides access and interaction with all sorts of Challenge data.
- Production API
- Node.js 22 (use the version in
.nvmrc) - pnpm 9.15.9
- AWS S3
- Docker
- Docker Compose
The API is written in TypeScript and runs on NestJS 11 with the Express adapter. The adapter mounts the established Express middleware and route graph so existing HTTP routes, validation, authentication, response bodies, and middleware ordering remain compatible. Database access uses Prisma 7 with the PostgreSQL driver adapter. Domain events continue to be sent through the existing Bus API wrapper; this service does not connect to Kafka directly.
The API runtime client is Prisma 7. The checked-in
packages/challenge-prisma-client artifact remains on Prisma 6 for its existing
downstream consumers, so the root generation command intentionally targets only
the API client. Upgrading that shared artifact requires a coordinated downstream
release.
Configuration for the application is at config/default.js.
The following parameters can be set in config files or in env variables:
- READONLY: sets the API in read-only mode. POST/PUT/PATCH/DELETE operations will return 403 Forbidden
- LOG_LEVEL: the log level, default is 'debug'
- PORT: the server port, default is 3000
- AUTH_SECRET: The authorization secret used during token verification.
- VALID_ISSUERS: The valid issuer of tokens.
- AUTH0_URL: AUTH0 URL, used to get M2M token
- AUTH0_PROXY_SERVER_URL: AUTH0 proxy server URL, used to get M2M token
- AUTH0_AUDIENCE: AUTH0 audience, used to get M2M token
- TOKEN_CACHE_TIME: AUTH0 token cache time, used to get M2M token
- AUTH0_CLIENT_ID: AUTH0 client id, used to get M2M token
- AUTH0_CLIENT_SECRET: AUTH0 client secret, used to get M2M token
- BUSAPI_URL: Bus API URL
- KAFKA_ERROR_TOPIC: Kafka error topic used by bus API wrapper
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting.
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting.
- AMAZON.AWS_REGION: The Amazon certificate region to use when connecting.
- AMAZON.ATTACHMENT_S3_BUCKET: the AWS S3 bucket to store attachments
- FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
- MEMBERS_API_URL: member-api members base URL; used to trigger challenge submitter rating updates after a challenge is completed
- RESOURCES_API_URL: TC resources API base URL
- GROUPS_API_URL: TC groups API base URL
- PROJECTS_API_URL: TC projects API base URL
- CHALLENGE_MIGRATION_APP_URL: migration app URL
- TERMS_API_URL: TC Terms API Base URL
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
- SCOPES: the configurable M2M token scopes, refer
config/default.jsfor more details - M2M_AUDIT_HANDLE: the audit name used when perform create/update operation using M2M token
- FORUM_TITLE_LENGTH_LIMIT: the forum title length limit
- DATABASE_URL: PostgreSQL connection URL for the challenge database
- REVIEW_DB_URL: optional PostgreSQL connection URL for review data; existing deployments may continue to omit it when review-database access is not used
You can find sample .env files inside the /docs directory.
The TypeScript, NestJS, and Prisma 7 migration does not introduce or rename any
configuration parameters.
Run nvm use before pnpm commands. Make sure DATABASE_URL is set before any
database operation or application startup.
- Install dependencies and generate the Prisma client:
pnpm install - Build the API:
pnpm build - Create or update local database tables:
pnpm create-tables - Seed tables:
pnpm seed-tables - Start local supporting services:
pnpm services:up - Stop local supporting services:
pnpm services:down - Check supporting-service logs:
pnpm services:logs
- The seed data are located in
src/scripts/seed
-
Select the repository's Node 22 version with
nvm use
-
⚙ Local config In the
challenge-apiroot directory create.envfile with the next environment variables. Values for Auth0 config should be shared with you on the forum.# Auth0 config AUTH0_URL= AUTH0_PROXY_SERVER_URL= AUTH0_AUDIENCE= AUTH0_CLIENT_ID= AUTH0_CLIENT_SECRET=- Values from this file are automatically used by the application and Prisma commands.
⚠️ Never commit this file or its copy to the repository!
Please make sure database url is configured before everything.
DATABASE_URL=
Then run
pnpm install. The postinstall hook generates the Prisma 7 client. -
🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally
pnpm services:up
This command will start postgres with docker-compose.
If you are running services with docker, you can run:
docker run -d --name challengedb -p 5432:5432 \ -e POSTGRES_USER=johndoe -e POSTGRES_DB=challengedb \ -e POSTGRES_PASSWORD=mypassword \ postgres:16.8
The command to set
DATABASE_URLenvironment variable will be likeexport DATABASE_URL="postgresql://johndoe:mypassword@localhost:5432/challengedb?schema=public"
Set it before running database commands or starting the API.
-
♻ Running mock-api:
TopCoder Challenge API calls many other APIs like Terms API, Groups API, Projects API, Resources API.
Starting them all is a little complicated. Mock APIs are created in
mock-api.You can run it with
cd mock-api npm startIt will start a mock service at port
4000at default, and it works well with Challenge API.You might also need to update the API URLs in
config/default.jsLine 44~57 with environment variables. The commands are like:export RESOURCES_API_URL="http://localhost:4000/v5/resources" export PROJECTS_API_URL="http://localhost:4000/v5/projects" export TERMS_API_URL="http://localhost:4000/v5/terms" export RESOURCE_ROLES_API_URL="http://localhost:4000/v5/resource-roles"
-
♻ Create tables and setup testdata
To create database tables, you can run:
pnpm create-tables
To create test data, you can run:
pnpm seed-tables
-
Configure external integrations
Authenticated operations and event publication use the existing Auth0 and Bus API settings. Configure
AUTH0_*andBUSAPI_URLfor environments that exercise those paths. Topics disabled by the existing topic configuration are skipped exactly as before; no local Kafka connection is required. -
🚀 Start Topcoder Challenge API
pnpm start
The Topcoder Challenge API will be served on
http://localhost:3000
- TBD
Tests use config/default.js plus environment-variable overrides. The following
test parameters can be set with environment variables:
- ADMIN_TOKEN: admin token
- COPILOT_TOKEN: copilot token
- USER_TOKEN: user token
- EXPIRED_TOKEN: expired token
- INVALID_TOKEN: invalid token
- M2M_FULL_ACCESS_TOKEN: M2M full access token
- M2M_READ_ACCESS_TOKEN: M2M read access token
- M2M_UPDATE_ACCESS_TOKEN: M2M update (including 'delete') access token
- S3_ENDPOINT: endpoint of AWS S3 API, for unit and e2e test only; default to
localhost:9000
- Start Local services in docker.
- Create tables.
- Various config parameters should be properly set.
Seeding db data is not needed.
To run unit tests alone
pnpm testTo run unit tests with coverage report
pnpm test:covTo run integration tests alone
pnpm e2eTo run integration tests with coverage report
pnpm e2e:covRefer to the verification document Verification.md
-
after uploading attachments, the returned attachment ids should be used to update challenge; finally, attachments have challengeId field linking to their challenge, challenge also have attachments field linking to its attachments, this will speed up challenge CRUDS operations.
-
Topic names are defined in
app-constants.ts. Event envelopes are posted to the Bus API, which owns Kafka integration for this service.
Downstream Usage
- This service is consumed by multiple Topcoder apps. Below is a quick map of where and how it’s called to help with debugging.
platform-ui
- Admin and Review apps read challenge data and metadata via v6 endpoints:
- Search challenges:
GET /v6/challenges?{filters}. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.ts. - Fetch challenge by id:
GET /v6/challenges/{id}. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.tsandplatform-ui/src/apps/review/src/lib/services/challenges.service.ts. - Challenge types and tracks:
GET /v6/challenge-types,GET /v6/challenge-tracks. Seeplatform-ui/src/apps/admin/src/lib/services/challenge-management.service.tsandplatform-ui/src/apps/review/src/lib/services/challenges.service.ts. - Support requests:
POST /v6/challenges/support-requests. Seeplatform-ui/src/libs/shared/lib/components/contact-support-form/contact-support-functions/contact-support-store/contact-support.store.ts.
- Search challenges:
- Local dev proxy maps
/v6/challenges,/v6/challenge-types,/v6/challenge-tracks,/v6/challenge-phases, and/v6/timeline-templatesto this service on port 3000. Seeplatform-ui/src/config/environments/local.env.ts.
community-app
- Uses v6 endpoints for public challenge listing and details:
- List/search challenges for dashboards and content blocks:
GET /v6/challenges?{filters}. Seecommunity-app/src/shared/services/dashboard.jsandcommunity-app/src/shared/actions/contentful.js. - Fetch challenge details (e.g., for review opportunity details pages):
GET /v6/challenges/{id}. Seecommunity-app/src/shared/services/reviewOpportunities.js.
- List/search challenges for dashboards and content blocks:
work-manager
- Work Manager CRUD and metadata flows rely on v6 Challenge API:
- Get challenge details:
GET /v6/challenges/{id}. Seework-manager/src/services/challenges.js. - Create/update/delete challenges:
POST /v6/challenges,PUT /v6/challenges/{id},PATCH /v6/challenges/{id},DELETE /v6/challenges/{id}. Seework-manager/src/services/challenges.js. - Manage attachments:
POST /v6/challenges/{id}/attachments,DELETE /v6/challenges/{id}/attachments/{attachmentId}. Seework-manager/src/services/challenges.js. - Default reviewers:
GET /v6/challenge/default-reviewers?typeId&trackId. Seework-manager/src/services/challenges.js. - Challenge metadata:
GET /v6/challenge-types,GET /v6/challenge-tracks,GET /v6/challenge-phases,GET /v6/challenge-timelines. Seework-manager/src/services/challenges.jsand config underwork-manager/config/constants/*.
- Get challenge details:
- Challenge
metadatamay includesubmission_typeto override the community-app submission flow:zipshows the standard Topcoder zip upload page, andurlshows the Topgear URL upload page. When omitted, consumers should keep their existing default behavior. - API base configuration points to v6 in dev/local and v5 in prod (for compatibility):
- Dev:
work-manager/config/constants/development.js. - Local:
work-manager/config/constants/local.js. - Prod:
work-manager/config/constants/production.js.
- Dev: