{"id":20452795,"url":"https://github.com/s0fft/device-cloud-hub","last_synced_at":"2026-04-12T19:52:25.919Z","repository":{"id":249683349,"uuid":"832180550","full_name":"S0fft/Device-Cloud-Hub","owner":"S0fft","description":"Devices-API-Storage — IoT Asynchronous-Project on Aiohttp [GMA]","archived":false,"fork":false,"pushed_at":"2024-11-01T12:57:57.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-15T23:12:25.639Z","etag":null,"topics":["aiohttp","api-rest","docker","iot","peewee","postgresql","postman","pytest","python3"],"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/S0fft.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}},"created_at":"2024-07-22T13:41:12.000Z","updated_at":"2024-11-01T12:58:00.000Z","dependencies_parsed_at":"2024-11-15T11:11:46.475Z","dependency_job_id":"c771481a-0fe6-4e61-8576-7f314ad7991e","html_url":"https://github.com/S0fft/Device-Cloud-Hub","commit_stats":null,"previous_names":["s0fft/global-mind-associated-task","s0fft/device-cloud-hub"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S0fft%2FDevice-Cloud-Hub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S0fft%2FDevice-Cloud-Hub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S0fft%2FDevice-Cloud-Hub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S0fft%2FDevice-Cloud-Hub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/S0fft","download_url":"https://codeload.github.com/S0fft/Device-Cloud-Hub/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242005730,"owners_count":20056431,"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":["aiohttp","api-rest","docker","iot","peewee","postgresql","postman","pytest","python3"],"created_at":"2024-11-15T11:10:23.183Z","updated_at":"2025-12-31T01:03:07.253Z","avatar_url":"https://github.com/S0fft.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Device-Cloud-Hub\n#### Devices-API-Storage — IoT Project on Aiohttp [GMA]\n\nThe application provides a cloud-based solution for managing IoT devices, offering a reliable and scalable API for interacting with these devices. This project includes CRUD functionality for device management, enabling users to add, update, retrieve, and delete devices, thus supporting their entire lifecycle. The application is deployed with Docker, ensuring ease of installation and portability, as well as a stable environment for interacting with the PostgreSQL database.\n\n#### Stack:\n - Python\n - Aiohttp\n - PostgreSQL\n - Peewee\n - Docker\n - Pytest\n\nAdditional libraries are specified in the `requirements.txt` file.\n\n## Project Setup with Docker\nIn this section, we will deploy the project on PC using Docker and Docker Compose.\n\n### - Cloning a Project from GitHub\nCreate a root directory on your computer, then open it in your code editor or terminal.\n\u003cbr\u003e\nNext, write this command into the command line:\n```powershell\ngit clone https://github.com/S0fft/Device-Cloud-Hub.git .\n```\nYou will see the project files appear in your directory.\n\n### - Running Docker Desktop and Docker Compose\nAfterwards, launch the already installed Docker Desktop. Next, while it is running, you can return to the editor or terminal and enter the following command in the terminal:\n```powershell\ndocker-compose up --build\n```\nThis command \"collects and runs all the code\", allowing you to interact with the project through a browser.\n\n### - Check by Port\nNow the project is already running on your computer, and is available on port 8000.\nGo to this address to open it:\n```powershell\nhttp://localhost:8000/\n```\nThus, we have run the project locally on computer.\n\n### - Functionality Overview\nNext, let's look at the functionality of this small project. Implemented CRUD keeping REST architecture in mind.\nThe goal of the assignment was to implement CRUD for Devices, which was done.\n\u003cbr\u003e\nBelow are the routes of this service and what request methods they support:\n\n#### Create, Read (GET / POST)\n```powershell\nhttp://localhost:8000/devices/\n```\nThis route supports: GET (All Devices) and POST (the request body must contain a new object that matches the validator, otherwise there will be an error)\n\n#### Read, Update, Delete (GET / PUT / PATCH / DELETE)\n```powershell\nhttp://localhost:8000/devices/{id}/\n```\nThis route supports: GET (by ID) to get the item, PUT for major update, PATCH for minor update, DELETE - to completely remove the item.\nThe routes follow REST architecture.\n\n***Important Note: After deploying a project on a computer, the database is empty, therefore, to retrieve devices via the API, you must create them using the POST method, respecting all database fields. Otherwise, you will receive empty JSON!***\n\n#### Example of a POST Request\n```json\n{\n    \"name\": \"Smart Thermostat\",\n    \"device_type\": \"Thermostat\",\n    \"login\": \"thermo_01\",\n    \"password\": \"securePassword123\",\n    \"location_id\": 2,\n    \"api_user_id\": 1\n}\n```\n\n### - Working With Postman\n\nYou can use all of the above addresses in Postman (or other similar tools) by sending requests with different methods (GET, POST, PUT, PATCH, DELETE). This gives you a full opportunity to test the API. \u003cbr\u003e\n\nAs mentioned before, you can run this project in the browser, but in this case, you will not be able to make POST, PUT, PATCH and DELETE requests. This is because a standard browser, without plugins, does not provide such capabilities when working with Aiohttp. \u003cbr\u003e\n\nTherefore, it is highly recommended to use Postman.\n\n### - Recommendations For Improvement\nThis Aiohttp based API is asynchronous, but it does not take full advantage of it's capabilities due to the synchronous use of the Peewee ORM. To take full advantage of asynchrony, we must use an asynchronous ORM such as Tortoise-ORM or GINO. \u003cbr\u003e\n\nEven though all functions in the code are defined as asynchronous (async def), they call synchronous Peewee ORM methods to work with the database. This blocks the main thread of execution while the database executes queries, which violates the core principle of asynchronous programming - not to block the thread of execution. \u003cbr\u003e\n\nTo improve our code, we can use an asynchronous ORM such as Tortoise-ORM, which fully supports asynchronous operations.\n\n---\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch3\u003e Project Setup Without Docker \u003c/h3\u003e\u003c/summary\u003e\nThese commands will help you deploy the project locally. \u003cbr\u003e\n\u003cbr\u003e\n \n ***Important Note: The project is configured to work with Docker. If you use this deployment approach, you need to change the configuration in the .env and app.py files before starting the server. Specifically, you should: Uncomment the necessary commands that are already commented out and replace mutually exclusive lines as needed. These lines are marked in the code. \u003cbr\u003e Otherwise, you will receive an error!*** \u003cbr\u003e\n\n### - Example of Lines of Code That Need to Be Changed (as shown below)\napp.py:\n```python\nif __name__ == '__main__':\n    db.connect()\n    db_setup()\n    # web.run_app(app, host=\"0.0.0.0\", port=8080)  # Docker - MUST BE COMMENTED\n    web.run_app(app, host='127.0.0.1', port=8080)  # Local - MUST BE UNCOMMENTED\n```\n\n.env:\n```python\nDB_NAME=gma_task\nDB_USER=postgres\nDB_PASSWORD=admin\n# DB_HOST=db # Docker - MUST BE COMMENTED\nDB_HOST=localhost # Local - MUST BE UNCOMMENTED\nDB_PORT=5432\n```\n### - Routes in Local Development Without Docker\nIn this approach, the service routes are different, they are listed below.\n\u003cbr\u003e\n#### Create, Read (GET / POST)\n```powershell\nhttp://127.0.0.1:8080/devices/\n```\n#### Read, Update, Delete (GET / PUT / PATCH / DELETE)\n```powershell\nhttp://127.0.0.1:8080/devices/{id}/\n```\nThe functionality is the same, the HOST and PORT of the service are just different.\n\n## \u003cp align=\"center\"\u003eWindows\u003c/p\u003e\n\n### - Installing the Stack\nTo begin, install: [Python](https://www.python.org/downloads/) | [PostgreSQL](https://www.postgresql.org/) \u003cbr\u003e Links are provided to the latest versions of the tools.\n\u003cbr\u003e\n\n### - Cloning a Project From GitHub\nAll the same, сreate a root directory on your computer, then open it in your code editor or terminal.\n\u003cbr\u003e\nNext, write this command into the command line:\n```powershell\ngit clone https://github.com/S0fft/Device-Cloud-Hub.git .\n```\nYou will see the project files appear in your directory. After, continue to enter the following commands.\n\n### - Creating a Virtual Environment\nCreate a virtual environment:\n```powershell\npython -m venv .venv\n```\n\nAnd activate it:\n\n```powershell\n.venv\\Scripts\\Activate\n```\n\n### - Installing the Requirements\nNext, install packages:\n\n```powershell\npython.exe -m pip install --upgrade pip\n```\n```powershell\npip install -r requirements.txt\n```\n\n\u003c!-- ### Fixtures\nLoad data from fixture for devices\n```powershell\ncode\n``` --\u003e\n\n### - Running the Server\nThen, run server:\n```powershell\npython app.py\n```\n\u003cbr\u003e\n\n\u003c!-- ---------------------------------------------- --\u003e\n\n## \u003cp align=\"center\"\u003eUNIX Systems\u003c/p\u003e\nThese commands do the same thing as described above, only on UNIX systems. \u003cbr\u003e Before this, the code must be modified as indicated in the note above!\n\u003cbr\u003e\n\n### - Virtual a Environment\n```bash\npython3 -m venv ../venv\n```\n\n```bash\nsource ../venv/bin/activate\n```\n\n### - Installing the Requirements\n```bash\npip3 install --upgrade pip\n```\n```bash\npip3 install -r requirements.txt\n```\n\n\u003c!-- ### Fixtures\n```bash\ncode\n``` --\u003e\n\n### - Running the Server\n```bash\npython3 app.py\n```\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0fft%2Fdevice-cloud-hub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs0fft%2Fdevice-cloud-hub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0fft%2Fdevice-cloud-hub/lists"}