Although a beginner in web development, I currently have been working on a larger Flask application.
At the moment I'm working with the structure shown below but I'm wondering what is the best way to structure such an application especially regarding different database connections (SQLAlchemy).
Unlike what is shown in the usual (and very helpful) Flask tutorials, I envision an architecture of multiple, partially independent (sub)apps, each also relying on its own database connection. Also, I don't necessarily want to load all databases immediately when accessing the main website but only the one of the subapp that is needed.
For communication between server and client I plan to use REST API and I already use Blueprints to separate the subapps.
The app has a unified frontend, where the subapps are simply mapped to different URL endpoints (e.g. website.net/app1 and website.net/app2).
Any guidance on structuring such an app is greatly appreciated, thanks!
Current app structure:
project/
├─ run.py
├─ webapp/
│ ├─ __init__.py
│ ├─ static/
│ ├─ templates/
│ ├─ app1/
│ │ ├─ data/
│ │ │ ├─ app1_database.py
│ │ │ ├─ app1_db_session.py
│ │ │ ├─ app1_modelbase.py
│ │ ├─ database/
│ │ ├─ services/
│ │ │ ├─ app1_services.py
│ │ ├─ templates/
│ │ │ ├─ app1/
│ │ │ │ ├─ app1.html
│ │ ├─ __init__.py
│ │ ├─ app1_forms.py
│ │ ├─ app1_views.py
│ ├─ app2/
│ │ ├─ data/
│ │ │ ├─ app2_database.py
│ │ │ ├─ app2_db_session.py
│ │ │ ├─ app2_modelbase.py
│ │ ├─ database/
│ │ ├─ services/
│ │ │ ├─ app2_services.py
│ │ ├─ templates/
│ │ │ ├─ app2/
│ │ │ │ ├─ app2.html
│ │ ├─ __init__.py
│ │ ├─ app2_forms.py
│ │ ├─ app2_views.py
As we are talking about modules and directories structure the main goal is to compose the app in a way that will be easy to you to maintain, debug and improve. I think if you have several apps in one project you better place each on a different server. We usually use blueprints when we want to separate logic within a single app and especially when we are planning to reuse this logic in a different app. So we can just copy-paste the single blueprint to another project. For example authentication blueprint. It can be the same in several apps.
You didn't show any business logic of the app. So it's hard to say. I usually slpit files into directories considering business logic.
I'm trying to convert an old Ant project to Maven. The project has a massive code base which is packed in different wars using Ant targets. It has multiple source folders, and each war is generated using different classes of these source folder. The code base should be separated in different sub-project but at the moment this is not an option so the goal is to have multiple wars for one project.
I've tried to use maven modules, creating a parent pom and a subfolder maven-modules in which I have one pom for each war that I need to generate, here's an example:
OldMassiveProject
│ ├── src
│ │ └── bunch.of.packages
│ ├── other_src
│ │ └── bunch.of.packages
│ ├── various_resources_folder
...
│ ├── maven_modules
│ │ ├── module_1
│ │ │ └── pom.xml
│ │ ├── module_2
│ │ │ └── pom.xml
...
│ │ ├── module_n
│ │ │ └── pom.xml
│ ├── deploy_configuration
│ │ ├── module_1
│ │ │ ├── spring_files
│ │ │ └── web.xml
│ │ ├── module_2
│ │ │ ├── spring_files
│ │ │ └── web.xml
...
│ │ ├── module_n
│ │ │ ├── spring_files
│ │ │ └── web.xml
│ └── pom.xml (parent pom)
I've managed to create the wars but my IDE (Eclipse) cannot resolve imports of the dependencies used in the modules'pom. That's because the parent pom doesn't specify those dependencies so they are not added to the project's classpath. My question is: Is there a way to import modules' pom dependencies in the projectclass path?
I cannot make generation work using beta SailsJs (v0.10.0-rc8).
I tried this and that but with no success.
Any ideas would be appreciated.
~/dev$ npm -g ls | grep sails
├─┬ sails#0.10.0-rc8
│ ├── grunt-sails-linker#0.9.5
│ ├── sails-build-dictionary#0.10.1
│ ├─┬ sails-disk#0.10.1
│ ├─┬ sails-generate#0.10.3
│ │ ├── sails-generate-adapter#0.10.4
│ │ ├── sails-generate-backend#0.10.13
│ │ ├─┬ sails-generate-controller#0.10.6
│ │ ├── sails-generate-frontend#0.10.18
│ │ ├── sails-generate-generator#0.10.11
│ │ ├── sails-generate-gruntfile#0.10.10
│ │ ├─┬ sails-generate-model#0.10.9
│ │ ├── sails-generate-new#0.10.16
│ │ ├── sails-generate-views#0.10.1
│ │ └── sails-generate-views-jade#0.10.0
│ ├── sails-stringfile#0.3.2
│ ├─┬ sails-util#0.10.2
~/dev$ sails new project
info: Created a new Sails app 'project'!
~/dev/project$ sails generate api user
error: No generator called 'controller' found; perhaps you meant 'sails generate api controller'?
error: No generator called 'model' found; perhaps you meant 'sails generate api model'?
I can't reproduce this with a fresh install of Sails. Maybe there's a problem with your Sails install? Try:
npm cache clear
sudo npm uninstall -g sails
sudo npm install -g sails#beta
I created a Scala project with SBT, referencing ScalaTest. Now it has this tree:
├───lib
├───lib_managed
│ └───scala_2.9.0
│ └───compile
├───project
│ ├───boot
│ │ ├───other
│ │ │ └───net.java.dev.jna
│ │ │ └───jna
│ │ │ └───3.2.3
│ │ ├───scala-2.7.7
│ │ │ ├───lib
│ │ │ └───org.scala-tools.sbt
│ │ │ └───sbt
│ │ │ └───0.7.7
│ │ │ ├───compiler-interface-bin_2.7.7.final
│ │ │ ├───compiler-interface-bin_2.8.0.final
│ │ │ ├───compiler-interface-bin_2.8.1.final
│ │ │ ├───compiler-interface-bin_2.9.0.final
│ │ │ ├───compiler-interface-src
│ │ │ └───xsbti
│ │ └───scala-2.9.0
│ │ └───lib
│ └───build
│ └───target
│ └───scala_2.7.7
│ ├───analysis
│ └───classes
├───src
│ ├───main
│ │ ├───resources
│ │ └───scala
│ └───test
│ ├───resources
│ └───scala
└───target
In addition to src tree, which files/directories should I put under version control (now using SVN)?
For sbt 0.7, ignore the following:
lib_managed
target
project/boot
project/build/target
project/plugins/lib_managed
project/plugins/src_managed
project/plugins/target
project/plugins/project/build.properties
There's sbt 0.10.x now btw.
For xsbt 0.10+, here is my .gitignore, in my xsbt template project:
target/
project/boot/
*.jar
It is similar to the official .gitignore in the xsbt project, but Eugene's might be more complete.
What is the difference between a build and deploy and re-deploy?
What should be done when you just have some HTML changes and no Java code changes?
Should I do a build and deploy or just a re-deploy?
Disclaimer: Defining what build and deploy means is very subjective.
I will start with deploy. Deploy should mean take all of my artifacts and either copy them to a server, or execute them on a server. It should truly be a simple process.
Build means, process all of my code/artifacts and prepare them for deployment. Meaning compile, generate code, package, etc.
That helped? Some people do consider deploy as part of the "build process" which I don't really argue with because generally in order to test or run you have to deploy it somewhere.
The rule is generally if it is dynamic code, then you need to do a build/redeploy.
If you are just editing static html, css, images etc. then you can simply just patch (and preferably a server restart).
As always when "patching" there is added risk that you could not be deploying the entire code base, or someone could do it wrong.
Personally I like doing full build/redeploys because you always know you are in-sync with your source control. However there is always risk that deployments go bad, either the build part or the install part. If your builds take a long time, or you are unnecessarily having to deploy a lot of moving parts, then consider either breaking them down into smaller deployable components or create a more complete deployment plan.
As usual there is no silver bullet here.
Build means to Compile the project.
Deploy means to Compile the project & Publish the output
For web applications no need to deploy or nothing need to do at client side except simple browser with url.
all web applications are deployed at Server Machine(IIS) only, that application can be accessed by all client machines (any browser is enough).
For Desktop applications Wherever you want to use the application, need to deployed/installed in that system.
Watch this deploying process:
------ Build started: Project: AdventureWorks, Configuration: Release ------
Skipping 'belyaev_db.rds'. Item is up to date.
Skipping 'Sales Rep.rdl'. Item is up to date.
Skipping 'Top_10.rsd'. Item is up to date.
Build complete -- 0 errors, 0 warnings
------ Deploy started: Project: AdventureWorks, Configuration: Release ------
Deploying to http://...
Deploying data source '/Data Sources/belyaev_db'.
Warning : ...
Deploying data set '/Datasets/Top_10'.
Warning : ...
Error ...
Deploy complete -- 1 errors, 2 warnings
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
In this case I have some issues but as you can see - first step is in building - verification data sources and reports and only after that - deploying.
Build and Deployment are Back To Back Processes!
Build can be taken Only if there is any JAVA Code Change.
For only HTML or CSS file updates, no need of New Build.
The Property files change needs the Server Restart.
No need of Deploying Unchanged Build ear/tar file.
For updated ear Build, Deployment on Server process should be initiated.
The gist:
SOURCE DEPLOYMENT MODEL
┌──────────────────────────────────────────────────────────────────────┐
│ │
│ BINARY DEPLOYMENT MODEL │
│ ┌─────────────────────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ ┌────────┐ │ ┌─────────────┐ ┌─────────────┐ │ │
│ │ source │ BUILD │ │ application │ DELIVER │ installed │ │ │
│ │ code ├─────────┼─►│ binary ├──────────►│ application │ │ │
│ └────────┘ │ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ │ │ │
│ └─────────────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────────┘
To put it in context:
BINARY DEPLOYMENT MODEL
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ BUILD MACHINE │
│ ( OR FARM ) TARGET MACHINE │
│ ______________________________________ _____________________ │
│ / /│ / /│ │
│ ┌─────────────────────────────────────┐ │ ┌────────────────────┐ │ │
│ │ │ │ │ │ │ │
│ │ ┌────────┐ ┌─────────────┐ │ │ │ ┌─────────────┐ │ │ │
│ │ │ source │ BUILD │ application │ │ │ DELIVER │ │ installed │ │ │ │
│ │ │ code ├─────────►│ binary ├─┼─┼─────────┼──►│ application │ │ │ │
│ │ └────────┘ └─────────────┘ │ │ │ └─────────────┘ │ │ │
│ │ │/ │ │/ │
│ └─────────────────────────────────────┘ └────────────────────┘ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
SOURCE DEPLOYMENT MODEL
┌───────────────────────────────────────────────────────────────────────────────┐
│ │
│ BUILD MACHINE │
│ ( OR FARM ) TARGET MACHINE │
│ _______________ _____________________________________________ │
│ / /│ / /│ │
│ ┌──────────────┐ │ ┌────────────────────────────────────────────┐ │ │
│ │ │ │ │ │ │ │
│ │ ┌────────┐ │ │ │ ┌─────────────┐ ┌─────────────┐ │ │ │
│ │ │ source │ │ │ DELIVER │ │ application │ BUILD │ installed │ │ │ │
│ │ │ code ├──┼─┼───────────┼──►│ binary ├────────►│ application │ │ │ │
│ │ └────────┘ │ │ │ └─────────────┘ └─────────────┘ │ │ │
│ │ │/ │ │/ │
│ └──────────────┘ └────────────────────────────────────────────┘ │
│ │
└───────────────────────────────────────────────────────────────────────────────┘