This is the backend part of the Template App, which is developed using Node.js and Express.js. The main purpose of this application is to provide a RESTful API for the frontend part of the application, which is built using Flutter.
- Features
- Folder Structure
- Folder/File Explanations
- Technologies Used
- Run Locally
- Environment Variables
- API Endpoints
- npm Packages
- License
- JWT authentication
- Passport.js authentication
- Redis token storage
- Containerization using Docker
- Swagger API documentation generation
- MongoDB database connection handling
- Error handling
- Dynamic pagination
- File upload handling
- Request validation
- Cloud storage integration
- Email sending handling
- WebSocket communication handling
- API response formatting
- Request body schema
- Authentication
- Register a new user
- Verify a user's account
- User login
- User social media login
- Refresh an access token
- User logout
- Shop
- Add a shop to favorites
- Remove a shop from favorites
- Get shop details
- Get services by type
- Search for shops
- Get shop coupons
- Search for a coupon code
- Rate a shop
- Update a rating
- Remove a rating
- Search for all shops
- Get shops by service type
- Search with filters
- User
- Update user information
- Update user password
- Add an address
- Delete an address
- Get user addresses
- Add a payment card
- Delete a payment card
- Get user payment cards
- Get user notifications
- Get user favorite shops
- Get home information
- Reservation (in progress)
π config
π config.js
π mongoose.js
π passport.js
π redis.js
π controllers
π auth.controller.js
π shop.controller.js
π user.controller.js
π healthcheck
π healthcheck.js
π helpers
π helper.js
π jwt.js
π mailer.js
π middlewares
π authenticate.js
π errorHandler.js
π pagination.js
π uploadMedia.js
π validate.js
π models
π address.model.js
π coupon.model.js
π notification.model.js
π offeredService.model.js
π payment.model.js
π rating.model.js
π reservation.model.js
π servicePackage.model.js
π serviceType.model.js
π shop.model.js
π user.model.js
π routes
π v1
π auth.routes.js
π index.js
π shop.routes.js
π user.routes.js
π index.js
π services
π cloudinary.js
π error.js
π utils
π apiResponse.js
π socket.js
π validations
π auth.schema.js
π shop.schema.js
π user.schema.js
π .env
π docker-compose.yaml
π Dockerfile
π openapi.json
π server.js
π swagger.js
π config This folder contains configuration files for the application, including
- π config.js, which sets up environment variables and loads other configuration files,
- π mongoose.js for connecting to a MongoDB database,
- π passport.js for authentication using the Passport.js library,
- π redis.js for connecting to a Redis server.
π controllers This folder contains controller files, which handle incoming requests and send back responses.
π healthcheck This folder contains a single file named healthcheck.js, which is responsible for checking the health of the application and returning a response indicating whether the application is running properly.
π helpers This folder contains helper files, which contain utility functions that are used throughout the application. There are three helper files in this folder:
- π helper.js, which contains general-purpose utility functions,
- π jwt.js, which handles JWT (JSON Web Token) authentication,
- π mailer.js, which handles sending emails.
π middlewares This folder contains middleware files, which are functions that can modify the request or response objects or terminate the request-response cycle. There are five middleware files in this folder:
- π authenticate.js, which handles authentication middleware,
- π errorHandler.js, which handles error handling middleware,
- π pagination.js, which handles pagination middleware,
- π uploadMedia.js, which handles multer media upload middleware,
- π validate.js, which handles request validation middleware.
π models This folder contains model files, which define the structure and behavior of data stored in a database.
π routes This folder contains route files, which define the application's API routes and their associated controller functions. There are two files in this folder:
- π index.js, which imports and exports all route files,
- π v1, which is a subfolder containing route files for version 1 of the API. These files include v1 routes.
π services This folder contains service files, which contain code that is responsible for interacting with external services or APIs. There are two service files in this folder:
- π cloudinary.js, which handles media storage using the Cloudinary service,
- π error.js, which handles error response.
π utils This folder contains utility files, which contain miscellaneous utility functions. There are two utility files in this folder:
- π apiResponse.js, which handles API response formatting,
- π socket.js, which handles WebSocket communication.
π validations This folder contains schema files, which define the schema for request body validations.
π .env This file contains environment variables used by the application, such as database connection strings and API keys.
π docker-compose.yaml This file defines the services that are needed to run the application using Docker Compose.
π Dockerfile This file defines the Docker image that the application runs on.
π openapi.json This file contains an OpenAPI API Specification document, which defines the API endpoints and their associated parameters and responses.
π server.js This file contains the main code for the application, including setting up the Express.js server and connecting to the database and other services.
π swagger.js This file generates a Swagger UI documentation page based on the OpenAPI Specification document.
- A JavaScript runtime. It allows developers to run JavaScript code outside of a web browser.
- To install Node.js, go to the official Node.js website, download the installer for your operating system, and follow the installation instructions.
- A popular Node.js framework for building web applications and APIs. It provides a robust set of features for handling HTTP requests, routing, and middleware.
- To install Express.js, open a terminal window, navigate to your project directory, and run the following command:
npm install express.
- A popular NoSQL document-oriented database that stores data in JSON-like documents.
- To install MongoDB, go to the official MongoDB website, download the installer for your operating system, and follow the installation instructions.
- A tool for documenting and testing APIs using the OpenAPI Specification.
- To install Swagger, you can use the npm package swagger-ui-express. Run the following command in your terminal:
npm install swagger-ui-express.
- An in-memory data store that can be used as a database, cache, and message broker.
- To install Redis, go to the official Redis website, download the installer for your operating system, and follow the installation instructions.
- A JavaScript library that enables real-time, bidirectional communication between clients and servers.
- To install Socket.IO, run the following command in your terminal:
npm install socket.io.
- A distributed version control system for tracking changes in source code during software development.
- To install Git, go to the official Git website, download the installer for your operating system, and follow the installation instructions.
Clone the project using the following command in your terminal:
git clone https://github.com/gurkanfikretgunak/template_app_backend.gitNavigate to the project directory:
cd template_app_backendInstall the dependencies using the following command:
npm installStart the server using the following command:
npm startAlternatively, you can run the server using Docker by running the following command:
Navigate to the project directory:
cd template_app_backend docker-compose up -d --buildThis will build the Docker image and start the container for the application. You can then access the application by navigating to http://localhost:3000/api in your web browser.
Fill up the .env.example file with your environment variables. Also, don't forget to remove the .example extension from the file name and rename it to just .env before running the application.
REDIS_HOST environment variable to 127.0.0.1. If you are running it on a Docker container, set the REDIS_HOST environment variable to redis.
You can access the Swagger documentation for this project by navigating to http://localhost:3000/api-docs in your browser. From there, you can view and test the available API endpoints.
| Package Name | Version | Link |
|---|---|---|
| bcrypt-nodejs (will switch to bcrypt or bcryptjs soon) | ^0.0.3 | npm |
| body-parser | ^1.20.2 | npm |
| cloudinary | ^1.35.0 | npm |
| cors | ^2.8.5 | npm |
| dotenv | ^16.0.3 | npm |
| express | ^4.18.2 | npm |
| helmet | ^6.0.1 | npm |
| http | ^0.0.1-security | npm |
| joi | ^17.8.3 | npm |
| jsonwebtoken | ^9.0.0 | npm |
| mongoose | ^7.0.0 | npm |
| multer | ^1.4.5-lts.1 | npm |
| nodemailer | ^6.9.1 | npm |
| passport | ^0.6.0 | npm |
| passport-facebook | ^3.0.0 | npm |
| passport-google-oauth20 | ^2.0.0 | npm |
| passport-twitter | ^0.1.5 | npm |
| redis | ^3.1.2 | npm |
| socket.io | ^4.6.1 | npm |
| swagger-autogen | ^2.23.1 | npm |
| swagger-ui-express | ^4.6.2 | npm |
This project is licensed under the MIT License. Feel free to contribute to this project by opening issues and pull requests.
