{"id":13520260,"url":"https://github.com/pkk0/Scalable-backend-template","last_synced_at":"2025-03-31T16:31:08.623Z","repository":{"id":134116331,"uuid":"462761209","full_name":"pkk0/Scalable-backend-template","owner":"pkk0","description":"Blazing fast pre-configured scalable backend template using FastAPI, PostgreSQL, SQLAlchemy, Alembic and Docker Swarm Mode 🚀🌟","archived":false,"fork":false,"pushed_at":"2022-02-23T20:41:56.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-08T23:35:15.320Z","etag":null,"topics":["alembic","async","asynchronous","backend","docker","docker-compose","docker-swarm-mode","fastapi","fastapi-template","postgres","python","scalable","sqlalchemy","template"],"latest_commit_sha":null,"homepage":"","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/pkk0.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":"2022-02-23T14:07:18.000Z","updated_at":"2023-09-20T06:32:49.000Z","dependencies_parsed_at":"2024-02-23T01:20:05.405Z","dependency_job_id":"9eab4368-fd99-414a-8b55-fb8d05cdaed6","html_url":"https://github.com/pkk0/Scalable-backend-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkk0%2FScalable-backend-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkk0%2FScalable-backend-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkk0%2FScalable-backend-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkk0%2FScalable-backend-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkk0","download_url":"https://codeload.github.com/pkk0/Scalable-backend-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213468388,"owners_count":15591699,"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":["alembic","async","asynchronous","backend","docker","docker-compose","docker-swarm-mode","fastapi","fastapi-template","postgres","python","scalable","sqlalchemy","template"],"created_at":"2024-08-01T05:02:15.880Z","updated_at":"2024-08-01T05:13:02.370Z","avatar_url":"https://github.com/pkk0.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Scalable backend template using FastAPI, PostgreSQL, SQLAlchemy, Alembic and Docker Swarm Mode\n\nCreate your backend easily using the latest technology.\n\u003cbr\u003ePre-configured template consists of 3 main components:\n1. API - build with:\n- FastAPI - async, high-performance Python web framework \n- SQLAlchemy - async SQL toolkit and ORM\n- Alembic - database migration tool\n2. database - PostgreSQL  \n3. database tool available from your browser - pgAdmin\n\nScalability is ensured thanks to Docker Swarm Mode.\n\nYou can also use API image and scale it with Kubernetes.\n\u003cbr\u003eHowever, Kubernetes it's not trivial, and it's not recommended for beginners.\n## Configuration\nThe most important configuration sits in .env file.\n\u003cbr\u003eYou should also take a look at docker-compose files.\n\n## Local development\nOpen terminal and type \u003ccode\u003edocker compose up\u003c/code\u003e. It will start all services.\n\n#### First usage\n\nRun the above command, open another terminal and type:\n\u003cbr\u003e\u003ccode\u003edocker exec $(docker ps -f name=api -q | head -n 1) alembic upgrade head\u003c/code\u003e\n\u003cbr\u003eIt will run first migration and create sample database.\n\nTo make development smooth and use full power of your code editor, create a virtual python environment:\n\u003cbr\u003e\u003ccode\u003epython3 -m venv venv\u003c/code\u003e\n\nNow switch to it \u003ccode\u003e. venv/bin/activate\u003c/code\u003e\n\nAnd install all needed packages \u003ccode\u003epip3 install -r requirements.txt\u003c/code\u003e\n\n\n\nNow you can play with your code freely!\n\n\u003ch2\u003eGoing to PRODUCTION\u003c/h2\u003e\n\u003ch4\u003ePreparations\u003c/h4\u003e\nTo deploy backend, we will use Docker Swarm Mode - container orchestration system.\n\nIt means you need at least a single node cluster running.\n\nDon't have one? Don't worry! \n\u003cbr\u003eYou can do it easily, even on your own computer with \u003ccode\u003edocker swarm init\u003c/code\u003e\n\u003cbr\u003eWith that mode set on, you can easily add other servers to your cluster.\n\nNext, on your manager node you have to build a docker image of API \u003ccode\u003edocker build --tag api .\u003c/code\u003e\n\nNow, you have to make sure you configured your environmental variables in .env file!\n\u003cbr\u003eLoad them on your manager node by typing \u003ccode\u003eexport $(cat .env)\u003c/code\u003e\n\nThe last step is to make PostgreSQL data persistent.\n\u003cbr\u003eFor that, you have to mark one of your nodes to always run PostgreSQL database.\n\u003cbr\u003eYou can see all your nodes by running \u003ccode\u003edocker node ls\u003c/code\u003e\n\u003cbr\u003eThen you grab your chosen node ID and label it by typing\n\u003cbr\u003e\u003ccode\u003edocker node update --label-add postgres-data-node=true ID_OF_YOUR_CHOSEN_NODE\u003c/code\u003e\n\u003cbr\u003eon your manager node.\n\n#### Deploying backend\nSimply run \u003ccode\u003edocker stack deploy -c docker-compose-prod.yaml backend\u003c/code\u003e\n\nYay! Your backend is working :) \u003cb\u003eDon't forget to make migrations!\u003c/b\u003e\n\n#### What next?\nNow you can for example scale your API service with a command:\n\u003cbr\u003e\u003ccode\u003edocker service scale backend_api=10\u003c/code\u003e\n\u003cbr\u003eYou will have 10 similar services running behind load balancer. Simple!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkk0%2FScalable-backend-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkk0%2FScalable-backend-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkk0%2FScalable-backend-template/lists"}