{"id":20452273,"url":"https://github.com/zakharb/microapi","last_synced_at":"2025-04-13T03:15:04.290Z","repository":{"id":142499994,"uuid":"489038688","full_name":"zakharb/MicroAPI","owner":"zakharb","description":"Micro Services with FastAPI and Docker","archived":false,"fork":false,"pushed_at":"2024-06-15T03:26:18.000Z","size":4247,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T03:14:47.464Z","etag":null,"topics":["docker","docker-compose","fastapi","microservices","nginx","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zakharb.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":"2022-05-05T16:00:37.000Z","updated_at":"2025-03-26T12:21:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"8fc625fd-4703-4216-b139-0d883194415d","html_url":"https://github.com/zakharb/MicroAPI","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/zakharb%2FMicroAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakharb%2FMicroAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakharb%2FMicroAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakharb%2FMicroAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zakharb","download_url":"https://codeload.github.com/zakharb/MicroAPI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657919,"owners_count":21140846,"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":["docker","docker-compose","fastapi","microservices","nginx","postgresql"],"created_at":"2024-11-15T11:08:49.653Z","updated_at":"2025-04-13T03:15:04.266Z","avatar_url":"https://github.com/zakharb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.linkedin.com/in/zakharb/microapi\"\u003e\n  \u003cimg src=\"img/logo.png\" alt=\"logo\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\n\u003ca href=\"https://git.io/typing-svg\"\u003e\n  \u003cimg src=\"https://readme-typing-svg.herokuapp.com?font=Fira+Code\u0026weight=600\u0026size=30\u0026pause=1000\u0026color=05998B\u0026center=true\u0026width=500\u0026lines=++Microservice+architecture;+with+FastAPI+and+Docker\" alt=\"description\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/version-1.2-green\" height=\"20\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/python-3.11-green\" height=\"20\"/\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/usage.gif\" alt=\"usage\" /\u003e\n\u003c/p\u003e\n\n\n## :green_square: Getting Started\n\n[MicroAPI](https://github.com/zakharb/microapi) is fully separates API in Async mode based on [Microservices](https://en.wikipedia.org/wiki/Microservices)   \n\nFor CRUD operations is used `Customer - Product - Price - Order` model  \n\n\u003e The `Customer` buys a `Product` with a different `Price` and receives an `Order`  \n\u003e The `Price` is calculated including taxes/discounts depending on the type of customer/  \n\nEach part is work like Microservice  \nThe Microservice runs in separate Docker container   \n\nMicroservice has its own Database  \nDatabase can be switch from Postgres to MongoDB or other  \n\n\n### Requirements\n\n![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge\u0026logo=fastapi)\n![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge\u0026logo=docker\u0026logoColor=white)\n![Postgres](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge\u0026logo=postgresql\u0026logoColor=white)\n![Nginx](https://img.shields.io/badge/nginx-%23009639.svg?style=for-the-badge\u0026logo=nginx\u0026logoColor=white)\n\n### Installing\n\nClone the project\n\n```\ngit clone git@github.com:zakharb/microapi.git\ncd microapi\n```\n\nStart docker-compose\n\n```\ndocker-compose up -d\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/install.gif\" alt=\"animated\" /\u003e\n\u003c/p\u003e\n\n## :green_square: Usage  \n\n### Customers  \nGet, put, update, delete `Customers` via API [Customers](http://localhost:8080/api/v1/customers/docs)    \n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/customers.gif\" alt=\"animated\" /\u003e\n\u003c/p\u003e\n\n### Products    \nGet, put, update, delete `Products` via API [Products](http://localhost:8080/api/v1/products/docs)  \n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/products.png\" /\u003e\n\u003c/p\u003e\n\n### Prices    \nGet `Prices` via API [Prices](http://localhost:8080/api/v1/prices/docs)  \n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/prices.png\" /\u003e\n\u003c/p\u003e\n\n### Orders    \nGet `Orders` via API [Orders](http://localhost:8080/api/v1/orders/docs)  \n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"img/orders.png\" /\u003e\n\u003c/p\u003e\n\n\n## :green_square: Configuration  \nTo solve problem with performance each Service run in container  \n[Uvicorn]((https://www.uvicorn.org/)) work as ASGI server and connect to one piece with [Nginx](https://www.nginx.com/)  \nMain configuration is `docker-compose.yml`  \n\n- every service located in separate directory `name-service`  \n- use `Dockerfile` to change docker installation settings  \n- folder `app` contain FastAPI application  \n- all services connected to one piece in `docker-compose.yml`  \n- example of service + DB containers (change `--workers XX` to increase multiprocessing)  \n\n### Examples  \n`Customer` service\n```\n  customer_service:\n    build: ./customer-service\n    command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4\n    #command: gunicorn main:app --workers 4 --worker-class --host 0.0.0.0 --port 8000\n    volumes:\n      - ./customer-service/:/app/\n    ports:\n      - 8001:8000\n    environment:\n      - DATABASE_URI=postgresql://customer_db_username:customer_db_password@customer_db/customer_db_dev\n    depends_on:\n       - customer_db\n    logging:\n        driver: none \n  \n  customer_db:\n    image: postgres:latest\n    volumes:\n      - postgres_data_customer:/var/lib/postgresql/data/\n    environment:\n      - POSTGRES_USER=customer_db_username\n      - POSTGRES_PASSWORD=customer_db_password\n      - POSTGRES_DB=customer_db_dev\n    logging:\n        driver: none \n```\n\n\n## :green_square: Client  \nThere is client for work with Microservices  \n`Microapiclient` is used for generating data and testing\n\nIt is located in folder `client`\n\n### Install  \n```\ncd client\npython3 -m venv venv\nsource venv/bin/activate \npython -m pip install -e .\n```\n\n### Run\n```\ncd client\nsource venv/bin/activate \npython -m microapiclient\n\n  __   __   _                      _____   _____  _______ \n (__)_(__) (_)        _           (_____) (_____)(_______)\n(_) (_) (_) _    ___ (_)__  ___  (_)___(_)(_)__(_)  (_)   \n(_) (_) (_)(_) _(___)(____)(___) (_______)(_____)   (_)   \n(_)     (_)(_)(_)___ (_)  (_)_(_)(_)   (_)(_)     __(_)__ \n(_)     (_)(_) (____)(_)   (___) (_)   (_)(_)    (_______)\n\nusage: __main__.py [-h]\n                   {getcustomer,postcustomer,getproduct,postproduct,getprice,postorder,postorders,generateorder}\n                   ...\n\npositional arguments:\n  {getcustomer,postcustomer,getproduct,postproduct,getprice,postorder,postorders,generateorder}\n    getcustomer         Get customer from DB\n    postcustomer        Post new customer into DB\n    getproduct          Get product by name from DB\n    postproduct         Post new product into DB\n    getprice            Get price_net and price_gross\n    postorder           Post order into DB\n    postorders          Bulk write orders into DB\n    generateorder       Generate order into CSV file\n\noptional arguments:\n  -h, --help            show this help message and exit\n\n```\n\n### Examples  \n\n- Generate Customers  \n```\npython -m microapiclient postcustomer --customer-count 50\n```  \n- Generate Products   \n```\npython -m microapiclient postproduct --product-count 50\n```  \n- Generate Orders to file  \n```\npython -m microapiclient generateorder --order-count 1000 --task-count 32\n```  \n- Bulk write Orders from file to DB  \n```\npython -m microapiclient postorders --order-file orders.csv --task-count 32\n```  \n- View logs in `client.log`  \n```\ncat client.log | more\n```\n\n## :green_square: Deployment\n\nEdit `Dockerfile` for each Microservice and deploy container\n\n## :green_square: Versioning\n\nUsing [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/zakharb/microapi/tags). \n\n## :green_square: Authors\n\n* **Zakhar Bengart** - *Initial work* - [Ze](https://github.com/zakharb)\n\nSee also the list of [contributors](https://github.com/zakharb/microapi/contributors) who participated in this project.\n\n## :green_square: License\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakharb%2Fmicroapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzakharb%2Fmicroapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakharb%2Fmicroapi/lists"}