Skip to content

ileopoldes/poplin-code-challenge

Repository files navigation

PokéAPI Proxy

1. Project Summary

The PokéAPI Proxy is a backend application built in TypeScript to fetch, cache, and persist data from the PokéAPI. Designed for performance, scalability, and reliability, it simplifies and optimizes responses for client applications.

1.1. Time Spent on Project

  • Approximately 8 hours were spent designing, implementing, and testing the project.
  • The work was not carried out entirely in one day, as due to personal issues linked to end-of-year commitments.
  • Time was allocated as follows:
    • Planning and API investigation: 2 hours
    • Setup and Infrastructure: 2 hours
    • Core Implementation: 3 hours
    • Testing and Error Handling: 1 hours
    • Optimization: 0 hours

2. Features and Status

Below is a summary of what was implemented and what is planned for future development.

Feature Status
Fetch Pokémon data by name or ID 🟢 Implemented
Fetch Pokémon by type 🟢 Implemented
Fetch Pokémon by ability 🟢 Implemented
Fetch Pokémon species 🟢 Implemented
Redis caching for external API 🟢 Implemented
MongoDB persistence 🟢 Implemented
JWT Authentication ⚫ Future Work
Cluster support for Node.js ⚫ Future Work
Rate limiting ⚫ Future Work
API documentation with Swagger ⚫ Future Work
Integration tests ⚫ Future Work
Static data updates via cron job ⚫ Future Work
Load balancing and Node clustering ⚫ Future Work

3. Technologies Used

Component Technology/Tool
Backend Framework Express.js + TypeScript
Caching Redis
Database MongoDB
Authentication JWT
Testing Jest
Scalability Node.js Clustering, Docker
Task Scheduling node-cron
Rate Limiting express-rate-limit

Note: chatGPT and Copilot were used during all the project stages


4. Project Structure

The project follows a clean, modular structure inspired by Domain-Driven Design (DDD):

src/
├── controllers/      # Route handlers
├── services/         # Business logic
├── repositories/     # Database access layer
├── models/           # Data models
├── middlewares/      # JWT auth, logging, error handling
├── utils/            # Helper functions
├── config/           # Environment variables
├── routes/           # API routes
├── tests/            # Unit and integration tests

5. Endpoints Implemented

Endpoint Description Example
/pokemon/:nameOrId Fetch Pokémon by name or ID GET /pokemon/bulbasaur
/type/:type Fetch Pokémon by type GET /type/grass
/ability/:ability Fetch Pokémon by ability GET /ability/overgrow
/pokemon-species/:species Fetch Pokémon species details GET /pokemon-species/bulbasaur

6. Setup Instructions

Prerequisites

  • Node.js (v20+)
  • Docker and Docker Compose
  • Redis and MongoDB

Steps to Run the Application

  1. Clone the Repository:

    git clone https://github.com/your-repo/pokeapi-proxy.git
    cd pokeapi-proxy
  2. Install Dependencies:

    npm install
  3. Environment Setup:

    • Create a .env file in the root directory with the following variables:
      PORT=3000
      REDIS_HOST=localhost
      REDIS_PORT=6379
      MONGODB_URI=mongodb://localhost:27017/pokeapi
      JWT_SECRET=your_secret_key
      POKEAPI_URL=https://pokeapi.co/api/v2
  4. Run the Application:

    • Development mode:
      npm run docker:dev
    • Production mode:
      npm run docker:prod
  5. Run Tests:

    npm run test

How to Test the API Using Postman

There is a directory called doc in the root path where you can find a Postman collection.


7. Design Decisions

Caching

  • Redis is used for caching frequently accessed data to minimize redundant external API calls.

Persistence

  • MongoDB stores semi-static data fetched from PokéAPI, reducing dependency on the external service for critical endpoints.

Error Handling

  • Custom error classes handle HTTP status codes (e.g., 404, 500).
  • A global middleware ensures consistent error responses.

Authentication

  • Stateless authentication would be implemented via JWT.

Scalability

  • Node.js clustering could be enabled for multi-core utilization.
  • Containerized services are ready for deployment using Docker.

8. Next Steps

The following features can be implemented to improve the project further:

  1. Integration Tests: Use Supertest to validate the end-to-end behavior of routes.
  2. Rate Limiting: Prevent API abuse with express-rate-limit.
  3. Load Balancing: Use tools like NGINX or AWS ELB to distribute traffic efficiently.
  4. Node.js Clustering: Enable multi-core utilization for performance gains.
  5. Static Data Updates: Schedule cron jobs for daily updates of cached or persisted data.
  6. API Documentation: Integrate Swagger for interactive API documentation.
  7. CI/CD: Set up continuous integration and continuous deployment pipelines using tools like GitHub Actions. This would automate testing, building, and deployment processes, ensuring code quality and facilitating rapid delivery of new features and bug fixes.

9. Author

Name Email GitHub
Paulo Bender leopoldes@gmail.com ileopoldes

10. Repository

The source code for this project can be found at: GitHub Repository

About

Code challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors