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.
- 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
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 |
| 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 |
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
| 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 |
- Node.js (v20+)
- Docker and Docker Compose
- Redis and MongoDB
-
Clone the Repository:
git clone https://github.com/your-repo/pokeapi-proxy.git cd pokeapi-proxy -
Install Dependencies:
npm install
-
Environment Setup:
- Create a
.envfile 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
- Create a
-
Run the Application:
- Development mode:
npm run docker:dev
- Production mode:
npm run docker:prod
- Development mode:
-
Run Tests:
npm run test
There is a directory called doc in the root path where you can find a Postman collection.
- Redis is used for caching frequently accessed data to minimize redundant external API calls.
- MongoDB stores semi-static data fetched from PokéAPI, reducing dependency on the external service for critical endpoints.
- Custom error classes handle HTTP status codes (e.g.,
404,500). - A global middleware ensures consistent error responses.
- Stateless authentication would be implemented via JWT.
- Node.js clustering could be enabled for multi-core utilization.
- Containerized services are ready for deployment using Docker.
The following features can be implemented to improve the project further:
- Integration Tests: Use Supertest to validate the end-to-end behavior of routes.
- Rate Limiting: Prevent API abuse with
express-rate-limit. - Load Balancing: Use tools like NGINX or AWS ELB to distribute traffic efficiently.
- Node.js Clustering: Enable multi-core utilization for performance gains.
- Static Data Updates: Schedule cron jobs for daily updates of cached or persisted data.
- API Documentation: Integrate Swagger for interactive API documentation.
- 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.
| Name | GitHub | |
|---|---|---|
| Paulo Bender | leopoldes@gmail.com | ileopoldes |
The source code for this project can be found at: GitHub Repository