{"id":25774722,"url":"https://github.com/yanliu1111/microservices-fastapi-fullstack-app","last_synced_at":"2025-02-27T05:33:04.673Z","repository":{"id":172390178,"uuid":"647515229","full_name":"yanliu1111/microservices-fastapi-fullStack-app","owner":"yanliu1111","description":"♻ Inventory and payment application, microservices architecture with FastAPI and Redis as a dataase.","archived":false,"fork":false,"pushed_at":"2024-02-17T17:56:29.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-28T05:55:19.842Z","etag":null,"topics":["bootstrap","fastapi","microservices","react-ts","redis-server","redis-streams"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/yanliu1111.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}},"created_at":"2023-05-31T00:32:12.000Z","updated_at":"2024-04-28T05:55:19.842Z","dependencies_parsed_at":null,"dependency_job_id":"1266212d-1b12-426f-9261-f4ba2eecb507","html_url":"https://github.com/yanliu1111/microservices-fastapi-fullStack-app","commit_stats":null,"previous_names":["yanliu1111/microservices-fastapi-fullstack-app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Fmicroservices-fastapi-fullStack-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Fmicroservices-fastapi-fullStack-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Fmicroservices-fastapi-fullStack-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanliu1111%2Fmicroservices-fastapi-fullStack-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanliu1111","download_url":"https://codeload.github.com/yanliu1111/microservices-fastapi-fullStack-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240984266,"owners_count":19888846,"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":["bootstrap","fastapi","microservices","react-ts","redis-server","redis-streams"],"created_at":"2025-02-27T05:33:03.872Z","updated_at":"2025-02-27T05:33:04.667Z","avatar_url":"https://github.com/yanliu1111.png","language":"TypeScript","readme":"# Inventory and Payment application with Microservices architecture\n\n## 🎯 Description\n\nThis project is building ecommerce full application includes client side using ReactJS and server side using Microservices architecture with FastAPI and Redis as a database. There are two microservices, one for products and the other for orders. I used Redis Stream as message broker among microservices and Redis database.\n\n## 💹 Flowchart\n\n```mermaid\nsequenceDiagram\n    par Client to Microservice-Payment\n        Client-\u003e\u003eMicroservice-Payment: Place an order for the items\n    and Client to Microservice-Inventory\n        Client-\u003e\u003eMicroservice-Inventory: Search and browse the products\n    end\n    Microservice-Payment--\u003e\u003eClient: Retrieve client's order details\n    Microservice-Inventory--\u003e\u003eClient: Retrieve the details of the products\n    Microservice-Payment -\u003e\u003e Microservice-Inventory: Update the Inventory\n```\n\n## 🔗 Teck Stack\n\n- ✅ FastAPI\n- ✅ Microservices\n- ✅ Redis-om\n- ✅ Redis-Stream\n- ✅ React\n- ✅ TypeScript\n- ✅ Vite\n- ✅ React-Router-Dom\n- ✅ Bootstrap-Dashboard\n\n## 🚀 Start the project\n\nIn invertory-microservice directory run the following command:\n\n```bash\nuvicorn main:app --reload\n```\n\nIn payment-microservice directory run the following command:\n\n```bash\nuvicorn main:app --reload --port=8001\n```\n\n(Redis Stream) Turn on Redis server in inventory-microservice and payment-microservice directories:\n\n```bash\npython consumer.py\n```\n\n## 📚 Learning Notes\n\n1. FASTAPI.**BACKGROUND TASKS** is used to run a function in the background. It is useful for tasks that need to run after a request, but that the client doesn't really have to be waiting for the result. **What is different between Background task and message queue**, is that background task is not persistent, it will be lost if the server is restarted. So, it is not suitable for long running tasks. For long running tasks, we need to use message queue.\n2. Some workflows for MVC.\n   - **POST** and **GET** a new product `http://localhost:8000/products/`\n\n```\n{\n  \"id\": \"01H28HATR7JG2YBH22ABPJWW33\",\n  \"name\": \"product\",\n  \"price\": 20.0,\n  \"quantity\": 100\n}\n```\n\nOrder this product id in `http://localhost:8001/orders/`\n\n```\n{\n  \"id\": \"01H28HATR7JG2YBH22ABPJWW33\",\n  \"quantity\": 10\n}\n```\n\n```\n{\n  \"pk\": \"01H28HDT0QXZKAE3F49HPJNN99\",\n  \"product_id\": \"01H28HATR7JG2YBH22ABPJWW33\",\n  \"price\": 20.0,\n  \"fee\": 4.0,\n  \"total\": 24.0,\n  \"quantity\": 10,\n  \"status\": \"pending\"\n}\n```\n\n- In 5 second, the product was delete in inventory **DELETE** `localhost:8000/products/01H28HATR7JG2YBH22ABPJWW33`\n- Copy `pk`from order response and **GET** `http://localhost:8001/orders/01H28HDT0QXZKAE3F49HPJNN99`\n\n```\n{\n  \"pk\": \"01H28HDT0QXZKAE3F49HPJNN99\",\n  \"product_id\": \"01H28HATR7JG2YBH22ABPJWW33\",\n  \"price\": 20.0,\n  \"fee\": 4.0,\n  \"total\": 24.0,\n  \"quantity\": 10,\n  \"status\": \"refunded\"\n}\n```\n\nStatus changed to refunded because the product was deleted in inventory, there is time limit setting for this case.\n\n3. Initial setup for ReactTS (frontend).\n   Change the following in tsconfig.json, and remove `\"allowImportingTsExtensions\": true,`\n\n```json\n   /* Bundler mode */\n  \"moduleResolution\": \"node\",\n  \"allowSyntheticDefaultImports\": true,\n```\n\nAnd tsconfig.node.json file, changed the following:\n\n```json\n\"moduleResolution\": \"node16\",\n```\n\n4.Microservices architecture for frontend building. I should build two frontend React apps, one for inventory and the other for payment. But for this demo, I used one proxy to create two services connection. In real world, we should use two frontend apps.\n\n```ts\nserver: {\n    proxy: {\n      \"/api\": {\n        target: \"http://127.0.0.1:8000\",\n        changeOrigin: true,\n        rewrite: (path) =\u003e path.replace(/^\\/api/, \"\"),\n      },\n      \"/app\": {\n        target: \"http://127.0.0.1:8001\",\n        changeOrigin: true,\n        rewrite: (path) =\u003e path.replace(/^\\/app/, \"\"),\n      },\n```\n\n\u003e 💖 Hope this project can help you to understand Microservices architecture and Redis Stream. If you like it, please give me a star ✨. I need your support to keep going. Thank you so much! 💖\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanliu1111%2Fmicroservices-fastapi-fullstack-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanliu1111%2Fmicroservices-fastapi-fullstack-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanliu1111%2Fmicroservices-fastapi-fullstack-app/lists"}