{"id":21952031,"url":"https://github.com/systangotechnologies/hapiness-sql","last_synced_at":"2025-04-23T04:05:06.023Z","repository":{"id":31228275,"uuid":"127280993","full_name":"SystangoTechnologies/Hapiness-SQL","owner":"SystangoTechnologies","description":"SQL database based version of the Hapiness framework.","archived":false,"fork":false,"pushed_at":"2022-12-22T07:39:06.000Z","size":4799,"stargazers_count":13,"open_issues_count":26,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T04:04:59.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SystangoTechnologies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-29T11:18:01.000Z","updated_at":"2021-05-01T21:32:44.000Z","dependencies_parsed_at":"2023-01-14T18:35:51.757Z","dependency_job_id":null,"html_url":"https://github.com/SystangoTechnologies/Hapiness-SQL","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SystangoTechnologies%2FHapiness-SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SystangoTechnologies%2FHapiness-SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SystangoTechnologies%2FHapiness-SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SystangoTechnologies%2FHapiness-SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SystangoTechnologies","download_url":"https://codeload.github.com/SystangoTechnologies/Hapiness-SQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250366726,"owners_count":21418771,"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":[],"created_at":"2024-11-29T06:19:16.050Z","updated_at":"2025-04-23T04:05:06.001Z","avatar_url":"https://github.com/SystangoTechnologies.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Hapiness-SQL](https://github.com/sytango-technologies/Hapiness/blob/master/assets/images/logo2.png)\n\n## Hapiness-SQL\nProduction ready Hapi boilerplate application with sequelize.\n\n## Description\n'Hapiness' boilerplate application serves as a great starting point for all the Hapi.js developers who were looking for a platform for their production server.\n\n1) localhost:8000 - Serve web request \u003cbr /\u003e\n2) localhost:8000/api - Serve rest api request\n\nWEB and REST API both have their independent authentication mechanisms, the web application uses the cookie based authentication and the REST API uses the JWT authentication for access. The deployment and application management is done via 'Docker' \u0026 'PM2' and there are different configurations/tasks for starting the app in the development vs the production environment. This application assumes the availability of 'MYSQL' installation on the localhost where the server will run.\n\nThe app contains basic user management with login, logout, password reset, profile view.\nForgot password implementation is done using 'nodemailer' (sends an email with reset password link with a unique token that expires in 1 hour).\n\nFor production, we have used 'PM2' as the process manager which spawns 4 servers for the application and takes care of the rest of application life cycle management. All the environment variables are managed using 'dotenv' node package for development, the same will need to be configured at the host server in the production environment.\n\nIf you are using 'Chrome' for unit testing the application, you can Hapi-ly use the 'node-inspector' chrome plugin pre-configured with this app for debugging purposes.\n\n## SSL Support\nSSL support has been provided using self signed certificates. Users may replace the certificates placed at config/ssl directory with their proprietary certificates.\nThe SSL support can be suppressed by commenting out the following lines in config/manifest.js : \n```\ntls: Config.get('/tlsOptions')\n```\n\n## Requirements\n- Node : 10.15.3\n- Database : SQL database.\n\n## Nodemailer Configuration\nUser may replace their gmail credentials in the .env file for debugging purpose on local environment.\nHowever, for production the credentials should be set as environment variables.\n\n## Technology\n\n- **Hapi** - Server side framework\n- **Docker** - Docker container support\n- **Handlebar** - HTML templating engine\n- **Sequelize** - Sequelize is a promise-based ORM for Node.js v4 and up.\n- **SASS** - CSS preprocessor \n- **WebPack** - Asset pipeline\n- **Dotenv** - Environment variable emulator\n- **Good** - Logger mechanism\n- **JWT** - Authentication mechanism for APIs\n- **Config** - Configuration Handler\n- **PM2** - Production process manager for Node.js apps\n- **Nodemailer** - Module to send emails\n- **Mocha** - Unit test framework\n\n## Application Structure\n```\n├── app\n│   ├── controllers\n│   │   ├── api            // Controllers are organised by module names for rest api \n│   │   └── web            // Controllers are organised by module names for web api.\n│   ├── helpers            // Helpers methods access by both api and web controllers.\n│   ├── routes             // All app routes are defined here\n│   │   ├── mobileApi      // RESTAPI routes for multiple versions V1 \u0026 V2.\n│   │   │   ├── v1         // Routes for version1\n│   │   │   └── v2         // Routes for version2\n│   │   └── webApi         // WEB api routes.\n│   └── templates          // Server-rendered handlebar templates,partials and helpers\n├── assets                 // Contains all static resources \n│   ├── fonts              // Fonts used in application\n│   ├── images             // Images used in application\n│   ├── scripts            // Scripts used in application\n│   │   ├── js             // User defined scripts\n│   │   └── vendor         // Vendor scripts.\n│   └── styles             // All SASS stylesheets\n├──config                  // Contains all app configurations\n│   ├── assets.js          // Assets configuration file\n│   ├── config.js          // Application configuration. \n│   ├── default.json       // Configuration file.\n│   ├── manifest.js        // App manifest file listing all plugins and load order.\n│   ├── meta.js            // App metadata file.\n│   └── ssl                // Contains ssl certificates\n├── lib                    // Core application lib/plugins\n├── logs                   // Contains app log file \n├──migrations              // All migration files are defined here\n├──models                  // All sequelize models are defined here\n└── test\n    ├── testcases          // Testcases organised by module names.\n    └── test.js            // Test file.\n├──.gitignore              // standard git ignore file\n├──.babelrc                // Babel config\n├──pm2.config.js           // PM2 Configuration file\n├──webpack.config.js       // Webpack config\n├──.eslintrc               // Define eslint rules.\n├──.eslintignore           // Ignores certain files for eslint rules\n├──Dockerfile              // Standard docker file\n├──docker-compose.yml      // Standard docker compose file \n├──server.js               // Contains all app configurations\n├──package.js              // Node package file.\n├──.env                    // dotenv configuration file for environment variable \n\n```\n## Code\n\nWe're using semi-colons and comma-last. No rhyme or reason; and some of the hapi [code convention guidelines](http://hapijs.com/styleguide). All client-side js code is also in commonJS pattern packs using webpack. Check out `.eslintrc` for additional code conventions used.\n\n## Sequelize\nSequelize is a promise-based ORM for Node.js v4 and up. It supports the dialects PostgreSQL, MySQL, SQLite and MSSQL and features solid transaction support, relations,read replication and more.\n\n## Database\nAnd one of the following databases with Sequelize\n\n- npm install --save pg pg-hstore \n- npm install --save mysql2\n- npm install --save sqlite3\n- npm install --save tedious\n\n## .env Configuration\nTo simulate environment variables in Dev environment, please create .env file at the root location and define the following properties -\n\n```\nDEBUGGER=false                                      // Enable/disable debug mode\nNODE_ENV=development                                // Node Env development/production\nPORT=8000                                           // Server Port\nSERVER_HOST=0.0.0.0                                 // Hapi Server host\nCOOKIE_SECRET=This_Should_be_32_characters_long\nYAR_COOKIE_SECRET=This_Should_be_32_characters_long\nJWT_SECRET=This_Should_be_32_characters_long\nDBHOST=localhost\nDIALECT=mysql                                       // dialect for sql database.\nDATABASE=hapiness\nDB_USER=root\nDB_PASS=systango\nDB_PORT=3306\nGMAIL_ID=Sender's Gmail Id\nGMAIL_PASSWORD=Gmail password\nGMAIL_SENDEREMAIL=Display email id for sender       // Could be same or different                                                            than GMAIL_ID\nGMAIL_SENDERNAME=Sender's name to display in email\nMAIL_HOST=smtp.gmail.com                            // Mail host\nMAIL_PORT=465                                       // Mail Port\nSWAGGER_HOST=localhost:8000                         // Host Url for Swagger\n\n```\n\n## Running the server locally\n\n - Install  `node`, `npm`\n - Define env configuration\n - Run these commands\n\n```sh\n# Install deps\n$ npm install\n\n# Required only when database not exist.\n$ npm run db:create\n\n# Required only when need to run database migration.\n$ npm run db:migrate\n\n# Install webpack-cli globally\n$ npm install webpack-cli -g\n\n# Run the node server in development mode\n$ npm start\n\n# Run the node server in production mode\n$ npm run build\n$ npm run prod\n```\nThe servers should be running at: \u003cbr/\u003e [localhost:8000](https://localhost:8000)\n\n## Running the server in Docker Container\n\nPrerequisite For Docker Configuration : Docker and docker compose must be installed on the system.\n\nSteps to run app in docker container :\n  1. CD to project dir\n  2. Create build using cmd: $ docker-compose build\n  3. Start the server in daemon thread using cmd: $ docker-compose up -d  \n  4. Stop the server using cmd : $ docker-compose down\n\n## REST API Versioning\n Hapiness now supports versioning out of the box. For sample purposes, v1 and v2 folders with appropriate route handlers are shared with this boilerplate. The versioning is done at the router's level only. Services are still placed at a single place with no support for versioning.\n\n## Documentation\n\nTo view swagger API documentation\n\nVisit [localhost:8000/documentation](http://localhost:8000/documentation) to view Swagger UI.\n\n## Testing\nHapiness now supports writting unit test cases using 'Mocha' and 'Supertest' node packages.\n- To execute the test cases please run the following command -\n\n```sh\n# Test the server\n$ npm test\n\n```\n\n## Contributors\n[Arpit Khandelwal](https://www.linkedin.com/in/arpitkhandelwal1984/)\n[Vikas Patidar](https://www.linkedin.com/in/vikas-patidar-0106/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystangotechnologies%2Fhapiness-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystangotechnologies%2Fhapiness-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystangotechnologies%2Fhapiness-sql/lists"}