A progressive Node.js framework for building efficient and scalable server-side applications.
The secret keys in this project were intentionally exposed because it's a test project. If this were a live or real project, sensitive information such as secret keys and database credentials would not be pushed with the code. Exposing such information is a bad security practice. However, for the sake of ease and to quickly test and move forward, some things were left intentionally exposed.
I always make sure to follow the best security practices and keep my sensitive information secure in real-world projects.
Nest framework TypeScript starter repository.
This assessment is designed and developed, using NestJS. it's an e-commerce system with functionalities for managing users and products. The system will cater to three types of users: unauthenticated users, authenticated users, and admins.
- Introduction
- Technologies Used
- Getting Started
- API Endpoints
- WebSocket Integration
- Data Models
- Error Handling
- Conclusion
This API provides a simple task management system with user authentication, task CRUD operations, and real-time updates via WebSockets. The application is built using NestJS and TypeORM.
- NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
- MIkroORM: An ORM for TypeScript and JavaScript.
- Postgres: A relational database.
- JWT: JSON Web Tokens for secure user authentication.
- Node.js (v14 or higher)
- npm (v6 or higher)
- A code editor (e.g., VSCode)
- postgres database
- mikroorm
- database explorer (pgAdmin, DBeaver, or similar)
- Clone the repository:
git clone <repository-url> cd basic-ecommerce
$ yarn install# development
$ yarn run start
# watch mode
$ yarn run start:dev
# production mode
$ yarn run start:prod# unit tests
$ yarn run test
# e2e tests
$ yarn run test:e2e
# test coverage
$ yarn run test:covThe application will be running at http://localhost:3000.:
🔗 API Endpoints Documentation can be found http://localhost:3000/v1/docs#/
to call an api endpoint http://localhost:3000/v1/{endpoints}
id: number (primary key)email: string (unique)firstname: stringlastname: stringpassword: stringlastlogin: Daterole: string [Admin, User]isBanned: boolean
id: number (primary key)name: stringprice: stringquantity: stringdescription: stringstatus: stringdeleted: boolean (default:false)user: User (many-to-one relationship)
To ensure the database schema is up-to-date, you need to run the database migrations. Follow these steps:
- Generate Migration: If you make changes to the entities, generate a new migration.
npx run mikro-orm migration:create
- Run Migration: Apply the migrations to the database.
npx run mikro-orm migration:up
By default, the project is configured to use PostgreSQL. Ensure your PostgreSQL server is running and the connection details in the .env file are correct.
The API uses standard HTTP status codes to indicate the success or failure of an API request. Here are some common status codes you might encounter:
- 200 OK: The request was successful.
- 201 Created: The resource was successfully created.
- 400 Bad Request: The request was invalid.
- 401 Unauthorized: Authentication failed.
- 404 Not Found: The requested resource was not found.
- 500 Internal Server Error: An error occurred on the server.
While this project is a take home assessment also time limited and not phasing live users in large quantity the project follows the KISS (Keep It Simple, Stupid) principle to ensure clarity and simplicity, there are several enhancements that could be made to improve the functionality, scalability, and robustness of the system:
- 🛡️ Enhanced Security: Implement additional security measures such as rate limiting.
- 📈 Scalability: Use a more robust database management consider implementing database sharding or partitioning to handle larger datasets and high traffic.
- ⚡ Caching: Integrating caching mechanisms using Redis or similar in-memory storage to optimize frequent API calls and reduce database load.
- 🔍 Advanced Filtering and Searching: Add more advanced filtering, searching, and sorting capabilities to the product management endpoints to improve usability, especially for users with many products.
- 🔍 Indexing: Adding database indexing on frequently queried fields such as email, name, and status to improve query performance.
- 📄 Pagination: Adding more advanced filtering, searching, and sorting capabilities to the product management endpoints to improve usability, especially for users with many products or spooling large number of data.
- 🐳 Dockerizing: Containerize the application using Docker to simplify deployment and ensure consistency across different environments in other to ease time to run or even test the project.
These improvements could significantly enhance the functionality and user experience of a more robust ecommerce System. However, for the scope of this project, i have prioritized simplicity and core functionality to adhere to the KISS principle.
If there had been more time available, I would have written tests to ensure the code's reliability and maintainability. I believe in Test-Driven Development (TDD), which emphasizes writing tests before the code itself. This approach helps to identify issues early and ensures that the code meets the required specifications.
- DB_HOST=localhost
- DB_PORT=5432
- DB_USER=postgres
- DB_PASSWORD=server
- DB_NAME=basicecommerce
- API_VERSION=v1
- ADMIN_EMAIL=admin@test.com
- ADMIN_PASSWORD=admin123
- DATABASE_URL=postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
- JWT_SECRET=ekw4jR34ARZJzDAbhP2speQVVbhK2Hun6wfHyERMRXmXcZey2hAqmpZz8Fjn5B8v
Thank you for using the Basic E-Commerce System API! I hope this documentation has provided you with all the information you need to get started and effectively use the API. If you have any questions or need further assistance, feel free to reach out.
Happy coding and testing! 🎉🚀