Backwave is a web application designed to help individuals improve their self-awareness by collecting anonymous feedback from their peers. This repository contains both the backend API implemented using Flask and MongoDB, and the frontend implemented in Vue.js.
- Create surveys with customizable questions
- Collect anonymous responses
- Calculate deviations and aggregated results
- Export survey data
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/codevalley/percept.git cd percept
-
Create a
.env
file in the project root and add your MongoDB URI:MONGO_URI=mongodb://mongo:27017/percept
-
Build and start the Docker containers:
docker-compose up --build
This command will build the images for the backend, frontend, and set up the MongoDB database. It will then start all the services.
-
The application will be available at:
- Frontend: http://localhost
- Backend API: http://localhost/api
-
Backend changes:
- Modify the Flask app files as needed.
- Rebuild and restart the containers:
docker-compose down docker-compose up --build
-
Frontend changes:
- Modify the Vue.js app files in the
webapp
directory. - Rebuild and restart the containers:
docker-compose down docker-compose up --build
- Modify the Vue.js app files in the
-
To run the containers in detached mode:
docker-compose up -d
-
To view logs:
docker-compose logs
Or for a specific service:
docker-compose logs backend
To run the unit tests:
docker-compose run --rm backend python -m unittest test_survey_results.py
Here are some example curl commands to interact with the API:
-
Create a new survey:
curl -X POST http://localhost/api/v1/surveys \ -H "Content-Type: application/json" \ -d '{ "title": "My Survey", "questions": [ { "text": "How do you feel?", "response_type": "scale", "response_scale_max": 5, "creator_answer": 4 } ] }'
Response:
{ "survey_id": 1719295638748, "share_link": "/surveys/1719295638748", "user_code": 1719295638749, "questions": [ {"id": 1, "text": "How do you feel?"} ] }
-
Retrieve a survey (replace {survey_id} with the ID from the create response):
curl -X GET http://localhost/api/v1/surveys/{survey_id}
-
Submit answers to a survey:
curl -X POST http://localhost/api/v1/surveys/{survey_id}/answers \ -H "Content-Type: application/json" \ -d '{ "answers": [ { "question_id": 1, "answer": 4 } ] }'
Replace {survey_id}
with the actual survey ID from your created survey.
For detailed API documentation, refer to the api_endpoints.md file.
After creating your app in DigitalOcean App Platform:
- Go to the App Platform dashboard and select your app.
- Click on the "Settings" tab.
- Scroll down to the "Environment Variables" section.
- Click "Edit" and then "Add Variable".
- Add a new variable:
- Key: MONGO_URI
- Value: Your MongoDB connection string (e.g., mongodb+srv://username:password@cluster.mongodb.net/database?retryWrites=true&w=majority)
- Click "Save".
The ${backend.INTERNAL_URL} and ${backend.PORT} variables are automatically set by DigitalOcean App Platform, so you don't need to configure them manually.
-
If you encounter CORS issues:
- Check the CORS configuration in
app.py
and ensure it matches your frontend URL. - Verify that the Nginx configuration in
nginx.conf
is correctly set up to handle CORS headers.
- Check the CORS configuration in
-
If services fail to start:
- Check the Docker logs for each service:
docker-compose logs [service_name]
- Ensure all required environment variables are set in the
.env
file.
- Check the Docker logs for each service:
-
If changes are not reflecting:
- Ensure you've rebuilt the Docker images after making changes:
docker-compose down docker-compose up --build
- Ensure you've rebuilt the Docker images after making changes:
-
If you're experiencing database connection issues:
- Verify that the MongoDB container is running:
docker-compose ps
- Check the MongoDB logs:
docker-compose logs mongo
- Ensure the
MONGO_URI
in the.env
file is correct.
- Verify that the MongoDB container is running:
-
To reset the entire setup:
docker-compose down -v docker-compose up --build
Note: This will remove all data in the MongoDB volume.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.