- Project Description
- Technologies Used
- Setup Instructions
- Test Instructions
- API Endpoints
- Running with Docker
- Known Limitations & Future Improvements
This technical test is designed for Norma's Teaching Online English academy.
It involves developing a REST API application using Node.js, pnpm, and TypeScript. The API will provide endpoints to manage a list of user favorites that are obtained from a search feature.
Key features include:
- User Interaction: Allow users to search and retrieve images.
- Unsplash Integration: The search endpoint connects to Unsplash's API to fetch images.
- Favorites Management: Enable users to add or remove images from their favorites list.
- RESTful Architecture: Follows standard REST practices to create a clean, maintainable API.
- Modularity: The project is organized into distinct modules (e.g.,
UsersModule,SearchModule,FavoritesModule) to isolate functionality. - External Service Integration: Integration with the Unsplash API is managed by the
HttpPrivateServicelocated insrc/providers/http/http.service.ts, with configuration via environment variables. - Security & Password Management: Bcrypt is used for password hashing.
- Database Choice: PostgreSQL is utilized in both development and production environments with TypeORM handling entity interactions.
- Framework: NestJS v11
- Database ORM: TypeORM
- Database: PostgreSQL
- HTTP Client: Axios (wrapped via NestJS's HttpModule)
- Testing Framework: Jest for unit and integration tests
- Language: TypeScript
- Others: ESLint, Prettier, Docker (with Docker Compose configuration)
-
Clone the Repository
git clone https://github.com/JohnFScha/normas-teaching-technical-test.git cd normas-test -
Install Dependencies
The project uses pnpm (as configured in pnpm-workspace.yaml). Run:
pnpm install
-
Configure Environment Variables
Create a
.envfile at the project root with the following variables (modify values as needed):NODE_ENV=development PORT=3000 DATABASE_URL=postgres://postgres:your_postgres_password_here@localhost:5433/image_db ACCESS_KEY=your_access_key_here BASE_URL=https://api.unsplash.com/search/photos/ -
Database Setup
Ensure PostgreSQL is running. You can use the provided docker-compose.yaml to start a PostgreSQL container:
docker-compose up -d
-
Build the Application
Build the project using pnpm:
pnpm build
-
Run the Application
-
For development (with live reloading):
pnpm start:dev
-
For production:
pnpm start:prod
-
The project utilizes Jest for testing. To execute tests:
-
Run all tests:
pnpm test -
Run tests in watch mode:
pnpm test:watch
-
Generate a Coverage Report:
pnpm test:cov
Important
For the end to end to run correctly, be sure you start on an empty database.
-
Run the app e2e test:
pnpm test:e2e
The application exposes several endpoints to interact with users, favorites, and image searches.
- GET /users: Retrieve a list of all users.
- GET /users/:id: Retrieve details of a specific user by providing the
idin the URL. - POST /users: Create a new user. The request body must include:
firstName(string)lastName(string)email(string; must be unique)password(string)- Optional:
isActive(boolean, defaults totrue) - Optional:
favorites(array)
- DELETE /users/:id: Delete an existing user by ID.
- GET /favorites: Retrieve a list of all favorites.
- POST /favorites: Create a new favorite. The request body must include:
description(string)imageUrl(string)userId(string) to link the favorite to a usercreatedAt(Date) indicating when the favorite was created
- DELETE /favorites/:id: Remove a favorite by its ID.
- GET /search: Search for images.
- Query Parameters:
query(string): The search term.page(number): The page number for paginated results.
- Query Parameters:
The /search endpoint uses an external service (e.g. the Unsplash API via the HttpPrivateService) and returns a list of images with properties such as id, width, height, urls, and description.
The application is containerized using Docker. To deploy the app using Docker:
-
Build and Start Containers
Ensure Docker is installed on your machine. Then run:
docker-compose up -d
This command builds the Docker image using the included
Dockerfile, starts the NestJS app container along with the PostgreSQL container, and maps the necessary ports. -
Verify Container Health
Check the status of the running containers with:
docker ps
You can also inspect the logs to ensure the app is running correctly:
docker-compose logs -f app
-
Stopping Containers
To stop the running containers, run:
docker-compose down
- Error Handling: Current error handling can be improved with more granular logging and detailed error responses.
- API Rate Limiting: Enhanced management of Unsplash API rate limits would be beneficial to reduce potential downtime.
- User Authorization: There is room to incorporate advanced user authorization mechanisms such as JWT and role-based access controls for better security.
- Validation Enhancements: More robust input validation can be added using advanced DTO patterns and validation libraries.
- Performance Scalability: Future iterations could optimize database queries, add caching strategies such as redis, and improve index configurations for a growing data set.
- Documentation: Augmenting documentation, for example, with in-depth JSDoc annotations for each module and integration point will help new developers onboard faster.