{"id":15984194,"url":"https://github.com/lecibur-13/minimalist-express","last_synced_at":"2025-03-17T15:32:06.027Z","repository":{"id":257029236,"uuid":"856616168","full_name":"Lecibur-13/Minimalist-Express","owner":"Lecibur-13","description":" Minimalist-Express is a minimalist framework for building RESTful APIs with Node.js and Express. It supports multiple databases and offers a modular and scalable structure for backend projects.","archived":false,"fork":false,"pushed_at":"2024-10-11T17:16:00.000Z","size":43,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-15T02:24:27.641Z","etag":null,"topics":["express","expressjs","framework","node","node-js","nodejs","rest","rest-api","restful-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lecibur-13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-12T22:20:00.000Z","updated_at":"2024-10-11T17:16:04.000Z","dependencies_parsed_at":"2024-09-14T12:44:47.655Z","dependency_job_id":null,"html_url":"https://github.com/Lecibur-13/Minimalist-Express","commit_stats":null,"previous_names":["lecibur-13/minimalist-express"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecibur-13%2FMinimalist-Express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecibur-13%2FMinimalist-Express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecibur-13%2FMinimalist-Express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecibur-13%2FMinimalist-Express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lecibur-13","download_url":"https://codeload.github.com/Lecibur-13/Minimalist-Express/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221696108,"owners_count":16865359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","expressjs","framework","node","node-js","nodejs","rest","rest-api","restful-api"],"created_at":"2024-10-08T02:04:56.633Z","updated_at":"2024-10-27T15:13:29.252Z","avatar_url":"https://github.com/Lecibur-13.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimalist-Express\n\nMinimalist-Express is a minimalist backend framework based on Node.js and Express, designed to create RESTful APIs quickly and efficiently. It provides a modular, scalable, and flexible structure, with support for multiple databases and easy environment variable configuration.\n\n## Features\n\n- **Modular architecture**: Clear and easy-to-scale structure for projects of any size.\n- **Multi-database support**: Integrated connectors for PostgreSQL, MongoDB, MySQL, and Oracle.\n- **Express.js**: Uses one of the most popular frameworks for Node.js.\n- **Environment variable management**: Easily configure the environment with `dotenv`.\n- **Basic security**: Includes basic security middlewares.\n\n## Prerequisites\n\n- [Node.js](https://nodejs.org/) v14 or higher\n- [NPM](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com/)\n- Supported database (PostgreSQL, MongoDB, MySQL, or Oracle)\n\n## Installation\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/Lecibur-13/Minimalist-Express.git\n    cd Minimalist-Express\n    ```\n\n2. Install the dependencies:\n\n    ```bash\n    npm install\n    ```\n\n3. Configure the environment variables. Create a `.env` file in the root of the project with the following variables:\n\n    ```plaintext\n    # Database configuration\n    DB_TYPE=postgres   # postgres, mysql, mongodb, oracle\n    PG_DB_USER=your_pg_user\n    PG_DB_PASSWORD=your_pg_password\n    PG_DB_HOST=localhost\n    PG_DB_PORT=5432\n    PG_DB_DATABASE=your_database_name\n\n    MONGO_DB_URI=mongodb://localhost:27017\n    MONGO_DB_NAME=your_mongo_db_name\n    ```\n\n    Adjust these values according to the type of database you are using.\n\n## Usage\n\n1. Start the server:\n\n    ```bash\n    node server.js\n    ```\n\n2. Access the API at `http://localhost:3000`.\n\n## Project Structure\n\n```\nMinimalist-Express/\n│\n├── Config/                 # Configuration files\n│   └── database.config.js  # Database configuration\n│\n├── Core/\n│   └── Database/           # Database clients (PostgreSQL, MongoDB, etc.)\n│\n├── Routes/                 # Route definitions and controllers\n│\n├── .env                    # Environment configuration file\n├── package.json            # NPM dependencies and scripts\n├── server.js               # Application entry point\n└── README.md               # Project documentation\n```\n\n## Middlewares\n\n### HMAC Authentication Middleware\n\nThe HMAC authentication middleware ensures that requests to the server are properly signed using a shared secret key. This helps verify the authenticity and integrity of the data, protecting it from tampering or unauthorized access.\n\n#### How Does It Work?\n\n1. **Client**: The client creates a message (payload) and signs it using an HMAC (Hash-based Message Authentication Code). This HMAC is generated using a shared secret key and additional parameters such as `nonce` and `timestamp`.\n\n2. **Server**: Upon receiving the request, the server takes the message and generates its own version of the HMAC using the same secret key and parameters. If the client's HMAC matches the one generated by the server, the request is accepted. Otherwise, it is rejected with an authentication error.\n\n### Middleware Implementation\n\nBelow is the code to implement this middleware in your application:\n\n```javascript\nimport dotenv from 'dotenv';\nimport crypto from 'crypto';\n\ndotenv.config();\n\nexport default function authenticateHmac(req, res, next) {\n  const { body } = req;\n  const { message, hmac, nonce, timestamp } = body;\n  \n  const serverHmac = generateHmac(message, nonce, timestamp);\n  \n  if (serverHmac === hmac) {\n    next();\n  } else {\n    res.status(401).send({\n      status: 'fail',\n      message: 'Unauthorized Signature'\n    });\n  }\n};\n\nfunction generateHmac(data, nonce, timestamp) {\n  const toSign = `${data}:${timestamp}:${nonce}`;\n\n  return crypto\n    .createHmac('sha256', process.env.API_TOKEN_HASH)\n    .update(toSign)\n    .digest('hex');\n}\n```\n\n### Using the Middleware\n\n1. **Secret Key**: Make sure to define the secret key that the server will use to generate HMACs in your `.env` file:\n\n    ```plaintext\n    API_TOKEN_HASH=your_secret_key\n    ```\n\n2. **Adding the Middleware to a Route**: You can add this middleware to routes that need HMAC authentication as follows:\n\n    ```javascript\n    import express from 'express';\n    import authenticateHmac from './middlewares/authenticateHmac.js'; // Ensure the correct path to the middleware\n\n    const app = express();\n\n    app.use(express.json());\n\n    // Route protected by HMAC middleware\n    app.post('/api/test', authenticateHmac, (req, res) =\u003e {\n      res.status(200).send({\n        status: 'success',\n        message: 'Valid signature'\n      });\n    });\n\n    app.listen(3000, () =\u003e {\n      console.log('Server running on port 3000');\n    });\n    ```\n\n3. **Client Example**: Here is an example of how the client might send a request with an HMAC-signed message:\n\n    ```javascript\n    const crypto = require('crypto');\n    const axios = require('axios');\n\n    const secretKey = 'API-private-key'; // Use the same secret key as the server\n    const timestamp = Date.now();\n    const nonce = crypto.randomBytes(16).toString('hex');\n    const message = {\n      \"folio\": \"R223-81-233-002\",\n      \"identifier\": \"ID_01\"\n    };\n\n    const toSign = `${message}:${timestamp}:${nonce}`;\n    const hmacA = crypto\n      .createHmac('sha256', secretKey)\n      .update(toSign)\n      .digest('hex');\n\n    axios.post('http://localhost:3000/api/test', {\n      hmac: hmacA,\n      timestamp,\n      message,\n      nonce,\n    })\n    .then(response =\u003e {\n      console.log('Server response:', response.data);\n    })\n    .catch(error =\u003e {\n      console.error('Error:', error.message);\n    });\n    ```\n\nWith this middleware, each request to the API protected by HMAC will verify whether the signature provided by the client matches the one generated by the server. If the signatures match, the request is authorized and processed; otherwise, a `401 Unauthorized` error is returned.\n\n## Contributing\n\nIf you wish to contribute to this project, please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch for your changes (`git checkout -b feature-new-functionality`).\n3. Make your changes and commit them (`git commit -m 'Add new functionality'`).\n4. Push your changes (`git push origin feature-new-functionality`).\n5. Open a Pull Request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecibur-13%2Fminimalist-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flecibur-13%2Fminimalist-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecibur-13%2Fminimalist-express/lists"}