{"id":20751062,"url":"https://github.com/eriknguyen/friends-management","last_synced_at":"2026-04-09T07:55:06.234Z","repository":{"id":98604591,"uuid":"122757793","full_name":"eriknguyen/friends-management","owner":"eriknguyen","description":"A simple friends management API built with Flask and MySQL","archived":false,"fork":false,"pushed_at":"2018-02-26T05:46:41.000Z","size":86,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-14T20:35:20.753Z","etag":null,"topics":["api","flask","mysql","python"],"latest_commit_sha":null,"homepage":"http://sp.erikng.me/","language":"Python","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/eriknguyen.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":"2018-02-24T16:29:49.000Z","updated_at":"2023-03-10T09:48:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c7ad012-fd11-44af-9375-63ee59f33e5d","html_url":"https://github.com/eriknguyen/friends-management","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eriknguyen/friends-management","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriknguyen%2Ffriends-management","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriknguyen%2Ffriends-management/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriknguyen%2Ffriends-management/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriknguyen%2Ffriends-management/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eriknguyen","download_url":"https://codeload.github.com/eriknguyen/friends-management/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eriknguyen%2Ffriends-management/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28023091,"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","status":"online","status_checked_at":"2025-12-25T02:00:05.988Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["api","flask","mysql","python"],"created_at":"2024-11-17T08:29:59.450Z","updated_at":"2025-12-25T07:17:55.409Z","avatar_url":"https://github.com/eriknguyen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Friends Management API\n*A simple friends management API built with Flask and MySQL*\n\n## Up and Running\n#### 1. Setup\n  ```bash\n    pyvenv venv -p python3\n    # Or: virtualenv venv -p python3\n    \n    source venv/bin/activate\n    pip install -r requirements.txt\n  ```\n\n#### 1. Run app with Python\n  ```bash\n    source venv/bin/activate\n    python app.py\n  ```\n\n#### 2. Or run with `gunicorn` server\n  ```bash\n    # use start script\n    source start.sh\n\n    # or manually\n    source venv/bin/activate\n    gunicorn --bind 0.0.0.0:8000 wsgi:app\n  ```\n\n#### 3. Test  \n  Run test in virtual environment\n  ```bash\n    source venv/bin/activate\n    python test.py\n  ```\n\n\n## Overview of the designs\n### 1. Technical decisions\n  * [Python Flask](http://flask.pocoo.org/) is used for quick installation and fast deployment with high flexibility and scalability\n  * [SQLAlchemy](https://www.sqlalchemy.org/) is used and wired up with flask using `flask-sqlalchemy` for easier ORM\n  * On the server, the app is running on a WSGI `gunicorn` server for better performance, especially with the use of multiple workers for handling concurrent requests\n  * Request handling process:\n    * App getting request with view functions that are mapped to url patterns in `routes.py`\n    * View functions are imported from `middleware.py`, where the main request handling processes take place.\n    * View functions in `middleware.py` use data service methods in `store.py` for data-related operations.\n\n\n### 2. Project Structure\n  * Main application files:\n    * `app.py` contains the main `app` instance\n    * `routes.py` contains all url mapping with route functions\n    * `middleware.py` contains all route functions for handling requests and response\n    * `store.py` contains data-related methods for read/write/update database directly\n    * `model/*` is the folder contains data model created with `SQLAlchemy`\n  * Other files:\n    * `test.py` contains all test cases built with Flask test client\n    * `wsgi.py` is used for running the server with `gunicorn`\n\n### 3. Database design\n  ![alt text](/er_diagram.png \"ER Diagram\")\n\n---\n## Friends API Specifications\n### 1. `POST /api/friends/connect` - create friend connection\n  * Request data: \n    ```json\n      {\n        \"friends\": [\n          \"andy@example.com\",\n          \"john@example.com\"\n        ]\n      }\n    ```\n  * Response:\n    - Success: `{ \"success\": true }`\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### 2. `POST /api/friends` - get friend list of email\n  * Request data:\n    ```json\n      {\n        \"email\": \"andy@example.com\"\n      }\n    ```\n  * Response:\n    - Success:\n      ```json\n        {\n          \"success\": true,\n          \"friends\" : [\n            \"john@example.com\"\n          ],\n          \"count\" : 1 \n        }\n      ```\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### 3. `POST /api/friends/common` - get common friends of users\n  * Request data:\n    ```json\n      {\n        \"friends\": [\n          \"andy@example.com\",\n          \"john@example.com\"\n        ]\n      }\n    ```\n  * Response:\n    - Success:\n      ```json\n        {\n          \"success\": true,\n          \"friends\" : [\n            \"common@example.com\"\n          ],\n          \"count\" : 1\n        }\n      ```\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### 4. `POST /api/friends/subscribe` - subscribe to update from an email\n  * Request data:\n    ```json\n      {\n        \"requestor\": \"lisa@example.com\",\n        \"target\": \"john@example.com\"\n      }\n    ```\n  * Response:\n    - Success:\n      ```json\n        {\n          \"success\": true\n        }\n      ```\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### 5. `POST /api/friends/block` - block updates from an email\n  * Request data:\n    ```json\n      {\n        \"requestor\": \"andy@example.com\",\n        \"target\": \"john@example.com\"\n      }\n    ```\n  * Response:\n    - Success:\n      ```json\n        {\n          \"success\": true\n        }\n      ```\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### 6. `POST /api/friends/subscribers` - get all users that can receive updates from a sender\n  * Request data:\n    ```json\n      {\n        \"sender\":  \"john@example.com\",\n        \"text\": \"Hello World! kate@example.com\"\n      }\n    ```\n  * Response:\n    - Success:\n      ```json\n        {\n          \"success\": true,\n          \"recipients\": [\n            \"lisa@example.com\",\n            \"kate@example.com\"\n          ]\n        }\n      ```\n    - Error:\n      ```json\n        {\n          \"error\": \"Error message\"\n        }\n      ```\n\n### HTTP Status Code Used\n  * `200` - success\n  * `404` - resource not found (eg. user email not valid, user id not valid, etc.)\n  * `500` - Internal server error (eg. error while updating database, error while creating new record, etc.)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feriknguyen%2Ffriends-management","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feriknguyen%2Ffriends-management","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feriknguyen%2Ffriends-management/lists"}