This project is the revised Topcoder Lookup API, migrated from its original Express/DynamoDB/Elasticsearch stack to a modern, simplified, and more maintainable architecture using NestJS, TypeScript, Prisma, and PostgreSQL.
The new architecture eliminates the complexity of the dual-datastore system, simplifies local development, and provides a robust foundation for future development by retaining all original functionality.
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Package Manager: pnpm
- Node.js (v20 or later recommended)
- pnpm
- Docker and Docker Compose
git clone <repository-url>
cd lookups-api-v6
This project uses pnpm as the package manager. Ensure you have it installed, then run:
pnpm install
The PostgreSQL database is managed using Docker Compose for easy local setup.
docker compose up -d
This command will start a PostgreSQL container running on port 5432.
Create a .env
file in the root of the project. You can copy the example structure below. The default values are configured to work with the local Docker setup.
# .env
# PostgreSQL Database URL for Prisma
# This is used by Prisma to connect to your local PostgreSQL instance.
DATABASE_URL="postgresql://user:password@localhost:5432/lookups?schema=public"
# ---------------------------------------------------
# JWT Authentication Secrets
# These are used by tc-core-library-js for validating JWTs.
# ---------------------------------------------------
# The secret key used to sign and verify JWTs.
AUTH_SECRET="mysecret"
# A JSON array string of valid token issuers.
VALID_ISSUERS='["https://topcoder-dev.auth0.com/","https://api.topcoder.com"]'
# ---------------------------------------------------
# M2M/Auth0 Configuration
# These values are required by tc-core-library-js for M2M authentication.
# ---------------------------------------------------
# The audience identifier for your Auth0 M2M application.
AUTH0_AUDIENCE="<auth0-audience>"
# The URL for obtaining an M2M token from Auth0.
AUTH0_URL="<auth0-url>"
# The Client ID of your Auth0 M2M application.
AUTH0_CLIENT_ID="<auth0-client-id>"
# The Client Secret of your Auth0 M2M application.
AUTH0_CLIENT_SECRET="<auth0-client-secret>"
# Optional: A proxy server URL for Auth0 requests.
AUTH0_PROXY_SERVER_URL=
Prisma manages the database schema and seed data.
-
Apply Migrations: This command will create the necessary tables in your PostgreSQL database based on the
prisma/schema.prisma
file.pnpm prisma migrate dev
-
Generate Prisma Client: After any change to
schema.prisma
, you should regenerate the Prisma Client. It's also good practice to run it after installing dependencies.pnpm prisma generate
-
Seed the Database: This command will populate the database with the initial lookup data from the
.json
files located in theprisma/seed-data/
directory.pnpm prisma db seed
To run the application in development mode with hot-reloading:
pnpm run start:dev
The application will be available at http://localhost:3000.
Once the application is running, interactive API documentation (Swagger UI) is available at:
http://localhost:3000/api-docs
This project includes a comprehensive suite of end-to-end (E2E) tests to ensure all functionality is working correctly. The tests run against the database and will clean up after themselves.
pnpm run test:e2e
The migration from the legacy stack to the new NestJS/Prisma/PostgreSQL stack was achieved through the following process:
- Technology Stack Selection: A modern stack was chosen to simplify the architecture and improve maintainability, eliminating the dual-datastore complexity of DynamoDB and Elasticsearch.
- Schema Definition: The data models from the original application were consolidated into a single
prisma/schema.prisma
file, which serves as the source of truth for the database schema. - Data Population: A seed script (
prisma/seed.ts
) was created to parse the original data (provided as NDJSON files) and populate the new PostgreSQL database. This replaces the oldloadData.js
andmigrateData.js
scripts. - API Implementation: The original Express routes and controllers were re-implemented as NestJS modules, controllers, and services, ensuring all endpoints and functionalities were retained.
- Authentication & Authorization: JWT validation and permission logic were re-created using NestJS Guards, preserving the original role- and scope-based access control.
- Validation: A full suite of E2E tests was created to validate that the new API's behavior matches the original, ensuring a seamless transition.
src/
: Contains the application source code.auth/
: Authentication and authorization logic (Guards, Strategies, Decorators).common/
: Shared utilities, such as the Prisma exception filter, response middleware.modules/
: Contains the business logic for each resource (countries, devices, etc.).prisma/
: Prisma service for database interaction.
prisma/
: Contains the Prisma schema, migrations, and seed script.seed-data/
: The source.json
files for seeding the database.
test/
: Contains the E2E test files (*.e2e-spec.ts
).Dockerfile
: For building a production-ready Docker image.docker-compose.yml
: For running the local PostgreSQL database.