1

Background

I am currently working on a web project in python that is hosted on AWS Elasticbeanstalk. We have two deploy-able web apps. A front end flask application and a back end flask application. Structurally The two are in the same git repository but for deployment each is git archived separately to produce a .zip which can be published to the server.

--project/
   --front/
   --back/

Both modules of the solution need to communicate with a database. I chose to use the ORM sqlalchemy for this. This ORM allows me to create models (python classes) which represent the tables in my database.

ISSUE

My Issues is this. I need to be able to use the models in both modules. Currently I have copies of the files which hold the models in each sub folder. This can lead to a lot of issues in keeping the files synced but also adds a lot of duplicate code in my repository. I was hoping that someone with more experience then myself would be able to describe a better solution.

J Whitfield
  • 755
  • 11
  • 22

1 Answers1

2

You can add a common folder where you have all your models (and shared libraries also), like this:

--project/
   --front/
   --common/
   --back/

Then you deploy two folders front/ and common/ for example.

By doing this, you can either zip the two folders on one Zip file, or use two Zip files.

Akram Fares
  • 1,653
  • 2
  • 17
  • 32
  • This seems to be the best solution I have found, makes my build/deploy process longer but worth it for the reduced code duplication. – J Whitfield Apr 11 '17 at 13:37
  • How do I import files from common in this case in a sane way? It is not a subdirectory of either front or back and python usually require workarounds for imports like this, isn't it? – Rotkiv Apr 15 '20 at 01:17