The Image to Code Converter is an innovative web application designed to transform design images into corresponding HTML, CSS, and React code snippets, along with support for other programming languages. This project aims to bridge the gap between designers and developers, enabling a seamless workflow by automating the conversion process. The backend is built using Node.js, Express.js, and MongoDB with Mongoose, with secure authentication via JWT tokens.
The backend handles all the core functionalities of the Design Image to Any Code, including:
User Authentication & Authorization:
Upload Image and Get Code:
Clone the repository:
git clone https://github.com/AliHasnM/design-image-to-any-code.git
Install dependencies:
npm install
Set up environment variables:
Create a .env
file in the root directory with the following variables:
PORT=8000
MONGODB_URI=your_mongodb_connection_url
CORS_ORIGIN=set_cors_origin (*, url, etc.)
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=your_access_token_expiry
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=your_refresh_token_expiry
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_apiKey
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
OPENAI_API_KEY=your-apiKey-of-chatgpt
Run the MongoDB database:
npm run dev
backend-design-image-to-any-code/
│
├── public/
│ ├── temp/
│ │ ├── .gitkeep
├── src/
│ ├── controllers/
│ │ ├── code.controllers.js
│ │ ├── dashboard.controllers.js
│ │ ├── healthcheck.controllers.js
│ │ ├── user.controllers.js
│ ├── db/
│ │ ├── index.js
│ ├── middlewares/
│ │ ├── auth.middleware.js
│ │ ├── multer.middleware.js
│ ├── models/
│ │ ├── code.model.js
│ │ ├── user.model.js
│ ├── routes/
│ │ ├── code.routes.js
│ │ ├── dashboard.routes.js
│ │ ├── healthcheck.routes.js
│ │ ├── user.routes.js
│ ├── utils/
│ │ ├── ApiError.js
│ │ ├── ApiResponse.js
│ │ ├── asyncHandler.js
│ │ ├── cloudinary.js
│ │ ├── openai.js
│ ├── app.js
│ └── constant.js
│ └── index.js
│
├── .env
├── package.json
└── README.md
Register and Login Routes:
POST /api/v1/users/register
- Register a new user with file upload for avatar
.POST /api/v1/users/login
- user login.POST /api/v1/users/logout
- user logout.Token and Password Management:
POST /api/v1/users/refresh-token
- Refresh JWT token for user.POST /api/v1/users/change-password
- Change password for user (requires authentication).Profile Management:
GET /api/v1/users/
- Get user profile.PATCH /api/v1/users/update
- Update user profile.PATCH /api/v1/users/avatar
- Update user profile with file avatar.PATCH /api/v1/users/cover-image
- Update user profile with file cover-image.GET /api/v1/users/image-history
- Get User History.POST /api/v1/codes/
- Upload design image for code and select code type in which you want to get code (requires authentication).GET /api/v1/codes/
- Get design image code details.GET /api/v1/codes/:id
- Get details of a specific design image.DELETE /api/v1/codes/:id
- Delete a design image code (requires authentication).User Routes (/api/v1/users/
)
POST /register
- Register user.POST /login
- Login user.POST /logout
- Logout user.POST /refresh-token
- Refresh token.POST /change-password
- Change password.GET /
- Get user profile.PATCH /update
- Update user profile.PATCH /image-history
- Check image history.PATCH /avatar
- Update user avatar.PATCH /cover-image
- Update user cover-image.Design Image to Any Code (/api/v1/codes/
)
POST /
- Upload design image and select code type.GET /
- Get all design image code details.GET /:id
- Get specific design image code details.DELETE /:id
- Delete design image code details.