{"id":49907246,"url":"https://github.com/e-choness/user-questionaire-backend","last_synced_at":"2026-05-16T11:11:25.019Z","repository":{"id":162093232,"uuid":"383817651","full_name":"e-choness/user-questionaire-backend","owner":"e-choness","description":"This project is the backend service for a questionnaire application. It handles questionnaire creation, submission, data storage, and analysis.","archived":false,"fork":false,"pushed_at":"2025-06-06T00:39:17.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-07T08:29:30.033Z","etag":null,"topics":["flask","python3","web-backend"],"latest_commit_sha":null,"homepage":"","language":"Python","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/e-choness.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-07-07T14:00:23.000Z","updated_at":"2025-06-06T00:39:19.000Z","dependencies_parsed_at":"2025-06-06T19:46:37.167Z","dependency_job_id":null,"html_url":"https://github.com/e-choness/user-questionaire-backend","commit_stats":null,"previous_names":["e-choness/user-questionaire-backend","e-choness/flask_backend_user_authentication"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/e-choness/user-questionaire-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-choness%2Fuser-questionaire-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-choness%2Fuser-questionaire-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-choness%2Fuser-questionaire-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-choness%2Fuser-questionaire-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-choness","download_url":"https://codeload.github.com/e-choness/user-questionaire-backend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-choness%2Fuser-questionaire-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33100361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["flask","python3","web-backend"],"created_at":"2026-05-16T11:11:20.192Z","updated_at":"2026-05-16T11:11:25.014Z","avatar_url":"https://github.com/e-choness.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# User Questionnaire Backend\n\n## Overview\n\nThis project is the backend service for a questionnaire application. It handles questionnaire creation, submission, data storage, and analysis.\n\n## Server-side\n\n- **Database**: The backend uses **MongoDB**, a NoSQL database. While MySQL is also a viable option, MongoDB was chosen for its flexibility in data insertion.\n- **Data Handling**: For questionnaire submissions, data insertion into MongoDB is straightforward. However, for robustness, data format validation should be considered. If using MySQL with JSON fields, handling would also be manageable.\n- **Data Statistics**:\n- **Current Approach**: The project currently calculates statistics by querying the database directly upon API request. This is acceptable for small-scale personal projects.\n- **Scalability Concerns**: For larger datasets or questionnaires with many questions, this direct query and computation method can be time-consuming.\n- **Proposed Improvements**:\n  1. **Redis Caching**: After a user submits a form and the server responds with a 200 status, the backend could asynchronously recalculate the form's statistical information. This data would then be stored in both Redis and the database. When a questionnaire publisher requests data analysis, statistics can be quickly retrieved from Redis.\n  2. **Dedicated Statistics Table**: An alternative to Redis could be a separate table for storing aggregated statistics. Each time a user submits a form, this table would be updated. This avoids querying multiple tables for calculations. However, maintaining data consistency could be challenging. For instance, if a questionnaire publisher modifies or deletes a question or changes option order, the statistics table would need complex updates.\n\n## Front-end\n\n- **Future Enhancements**:\n  - Develop a **form editor component** based on the current frontend. By defining a clear data structure, this editor could support not only questionnaires but also exams, business form processing, and more.\n  - Plan to adopt **Vue 3** and **TypeScript**.\n\n## Project Structure\n\n```bash\nuser-questionaire-backend/\n├── app/                # Contains the main application logic\n├── config/             # Configuration files for the project\n├── database/           # Database-related files and migrations\n├── static/             # Static assets like CSS, JS, and images\n├── templates/          # HTML templates for rendering views\n├── tests/              # Unit tests and integration tests\n├── venv/               # Virtual environment for Python dependencies\n├── docker/             # Docker-related files (e.g., Dockerfile, docker-compose)\n├── logs/               # Log files for debugging and monitoring\n├── README.md            # Documentation for the project, including setup, features, and deployment instructions.\n├── requirements.txt     # Lists Python dependencies required for the project.\n├── Dockerfile           # Defines the instructions to build a Docker image for the project.\n├── gunicorn.py          # Configuration file for Gunicorn, the Python WSGI HTTP server.\n├── manage.py            # Entry point for managing the Flask application (e.g., running the server, migrations).\n```\n\n## Installation (Development Environment)\n\n### Clone the Project\n\n```bash\ngit clone https://github.com/e-choness/user-questionaire-backend.git\n```\n\n### Navigate to Project Directory\n\n```bash\ncd /user-questionnaire-backend # e.g., or your customized root directory\n```\n\n### Create a Virtual Environment\n\n```bash\nvirtualenv venv\n```\n\n### Activate the Virtual Environment\n\n```bash\nsource venv/bin/activate\n```\n\n### Install Dependencies\n\n```bash\npip install -r requirements.txt\n```\n\n## Common Issues\n\n- If Flask's debug mode is enabled in the development environment, scheduled tasks might not run.\n\n## Features\n\n- **User Management**: Login, registration, email verification, and other basic user operations.\n- **Questionnaire Creation**: Create questionnaires for data collection (Supported question types: single choice, multiple choice, fill-in-the-blank, dropdown).\n- **Questionnaire Management**: CRUD operations for your questionnaires; supports generating questionnaires from templates.\n- **Questionnaire Publishing**: Basic publish/unpublish functions, set questionnaire passwords, restrict access by IP or device to prevent repeat submissions.\n- **Data Analysis**: Visualize and analyze data collected from questionnaires.\n\n## Deploying on Docker\n\n### Install Docker\n\n```bash\nsudo yum install docker\n```\n\n### Build the Image\n\nBuild an image from the local Dockerfile. Navigate to the project's root directory and execute:\n\n```bash\ndocker build -t questionnaire:1.0\n```\n\nHere, `questionnaire` is the image name, and `1.0` is the version number. You can customize these.\n\n### Run the Container\n\n```bash\ndocker run -p 8080:5001 questionnaire:1.0\n```\n\nThis command maps port 5001 (exposed by the container) to port 8080 on your host server.\n\n### Test Deployment\n\nAccess port 8080 on your server. If you receive the following JSON response, the deployment is successful:\n\n```json\n{\n  \"errorCode\": 0,\n  \"message\": \"Your project is running successfully!\"\n}\n```\n\n## Dockerfile\n\nThe following Dockerfile is located in the project root directory. It's used to package the project into an image and generally does not need modification:\n\n```dockerfile\nFROM python:3.8\nCOPY . .\nWORKDIR .\nRUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \\\n    \u0026\u0026 pip install gunicorn -i https://pypi.tuna.tsinghua.edu.cn/simple\nCMD [\"gunicorn\", \"-c\", \"gunicorn.py\", \"manage:app\"]\nEXPOSE 5001\n```\n\n## Gunicorn Configuration\n\nThe Gunicorn configuration file (`gunicorn.py`) is located in the project root directory:\n\n```python\nbind = '127.0.0.1:5001'  # Bind IP and port number\n\nworkers = 1  # Number of worker processes\nthreads = 2  # Number of threads per worker process\nloglevel = 'debug'  # Log level (for error logs; access log level cannot be set here)\naccesslog = \"/home/ubuntu/questionnaire/log/gunicorn_access.log\"  # Access log file\nerrorlog = \"/home/ubuntu/questionnaire/log/gunicorn_error.log\"  # Error log file\n```\n\n## Nginx Forwarding\n\nAfter the steps above, the project is deployed in a Docker container on port 5001, which is then mapped to the server's port 8080. You can use Nginx for reverse proxying.\n\n### Create an Nginx Configuration File\n\nCreate an Nginx configuration file (e.g., `questionnaire.conf`) in your project's root directory or `/etc/nginx/sites-available/`:\n\n```nginx\nserver {\n    listen       80;\n    server_name  api.yourdomain.com; # Replace with your domain\n    location / {\n        proxy_pass http://127.0.0.1:8080; # Or 5001 if not remapped by Docker run command\n        proxy_redirect off;\n        proxy_set_header Host $host; # If using port 80, $host:80 is not needed\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    }\n}\n```\n\n### Modify Nginx Configuration\n\nFind your Nginx installation directory and modify `nginx.conf`. Locate the `http` block and add an `include` statement for your site configuration:\n\n```nginx\nhttp {\n    # ... other configurations ...\n\n    ##\n    # Virtual Host Configs\n    ##\n\n    include /etc/nginx/conf.d/*.conf;\n    include /etc/nginx/sites-enabled/*;\n    # Add the line below, pointing to your project's Nginx config file\n    # For example, if you placed questionnaire.conf in /etc/nginx/sites-enabled/\n    # and created a symlink from /etc/nginx/sites-available/\n    # include /etc/nginx/sites-enabled/questionnaire.conf;\n    # Or, if you placed it directly:\n    # include /home/ubuntu/questionnaire/questionnaire.conf;\n}\n```\n\n### Reload Nginx\n\nRemember to reload or restart Nginx for changes to take effect:\n\n```bash\nsudo systemctl reload nginx\n```\n\n## Contributing\n\nFeel free to contribute to this project by submitting issues or pull requests.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Contact\n\nFor questions or support, contact [here](mailto:echoybl1123@gmail.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-choness%2Fuser-questionaire-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe-choness%2Fuser-questionaire-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-choness%2Fuser-questionaire-backend/lists"}