- Overview
- Tech Stack
- Project Structure
- Getting Started
- API Documentation
- Docker Setup
- MongoDB Atlas Setup
- Architecture
- Contributing
This project is a RESTful API built with Express.js and TypeScript, providing endpoints for user and product management in a store application. It uses MongoDB for data storage, JWT for authentication, and Zod for input validation.
- Express.js - Fast, unopinionated, minimalist web framework for Node.js
- MongoDB - NoSQL database
- TypeScript - Typed superset of JavaScript
- Zod - TypeScript-first schema declaration and validation library
- JSON Web Token (JWT) - Secure way of transmitting information between parties as a JSON object
- Docker - Platform for developing, shipping, and running applications
- Docker Compose - Tool for defining and running multi-container Docker applications
- Jest - Tool for running unit test in node.js app
.
├── src/
│ ├── controllers/
│ ├── models/
│ ├── schemas/
│ ├── services/
│ ├── routes/
│ ├── middleware/
│ ├── config/
| ├── utils/
│ └── index.ts
├── Dockerfile
├── docker-compose.yml
├── package.json
├── tsconfig.json
└── README.md
- Node.js (v14 or later)
- npm or yarn
- Docker and Docker Compose
- MongoDB (local instance or Atlas account)
- Jest
-
Clone the repository:
git clone https://github.com/Expertech-1/mainstack.git cd your-repo-name -
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory and add the following variables:PORT=3000 MONGO_URI_ATLAS=mongodb://localhost:27017/your-database MONGO_URI_DOCKER=mongodb://localhost:27017/your-database JWT_SECRET=your-secret-key NODE_ENV="development" | "production"
-
Start the application in development mode:
npm run dev
-
Build and run the application in production mode:
npm run build npm start
For detailed API documentation, please refer to our Postman Documentation.
The API provides the following main endpoints:
/api/v1/users- User management/api/v1/products- Product management
Each endpoint supports standard CRUD operations (GET, POST, PUT, DELETE).
To run the test:
-
Make sure Jest is installed installed on your system.
-
Run the following in terminal to run test:
npm run test
To run the application using Docker:
-
Make sure Docker and Docker Compose are installed on your system.
-
Build and start the containers:
docker-compose up --build
This command will start both the API and MongoDB containers.
To stop the containers:
docker-compose downIf you prefer using MongoDB Atlas:
- Create an account on MongoDB Atlas.
- Set up a new cluster and obtain the connection string.
- Update the
MONGODB_URIin your.envfile with the Atlas connection string.
This project follows a layered architecture:
- Controllers: Handle HTTP requests and responses.
- Services: Contain business logic and interact with models.
- Models: Define data structures and interact with the database.
- Schemas: Define input validation rules using Zod.
The flow of a typical request:
Request → Route → Controller → Service → Model → Database
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request