Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Your first Flask site
Lecture: Project structure
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
In this short little section
0:01
I want to give you a glimpse into the future
0:03
of what our app is going to look like.
0:06
And I've talked a couple of times already
0:08
in this course about structuring your application
0:10
as a real app, not just some silly single file app.py
0:15
or something like that. All right that's just not realistic for real apps
0:17
with many dependencies, JavaScript files, CSS, etc, etc.
0:21
So lets look at how I'm going to structure this project.
0:24
You're welcome to do it this way
0:25
it's worked really well for a long time for me.
0:28
You can do it some other way if you want.
0:29
But at least maybe it will inspire you, okay?
0:31
So take my ideas and adapt them to the way you like.
0:34
So here is the final project
0:35
the one that you saw in the opening chapter.
0:37
And we've got our Top Level Directory.
0:40
This one is the project route, but not the web route.
0:43
Then we have Alembic, this is for our database migrations
0:47
to help evolve our database schema to match our
0:50
SQLAlchemy schema, that's automatic.
0:52
Then we next have our web site content
0:55
the implementation and the route and all that.
0:58
Here's some stuff for installing, which we get
1:00
by installing this as a package, like a local install.
1:04
Here's some settings to set up the server
1:06
here's a bunch of unit tests, to test our code.
1:08
Here's our virtual environment
1:10
and here's our requirements and our set up file
1:12
and also some Alembic settings
1:13
that's the migration stuff as well.
1:15
Then looking at the website
1:16
we have a bunch of stuff in here that's pretty good.
1:18
We've got a bin folder, that's just a bunch
1:21
of little utilities to pre-load some data
1:23
and do some reports and whatnot.
1:25
We have data, that's going to hold
1:26
all of our models, our SQLAlchemy models.
1:28
We'll talk about how to define them
1:30
but these represent our database tables basically.
1:33
Here we're actually storing our database locally
1:35
you might not do that in a real one, but for SQLite we will.
1:38
Bunch of little helper, infrastructure bits
1:40
like cookie authentication and request dictionaries
1:43
and some decorators to help us write simple review methods.
1:46
Then these services, these are not web services
1:48
but just services to our app
1:50
these are our database, query abstractions
1:52
and stuff like that.
1:53
So here's all the database queries for, say, packages
1:55
and here's all the ones having to do with the users.
1:58
Static files, CSS, and so on.
2:00
We don't have any JavaScript in this app
2:02
imagine that, a web app, 2019 with no JavaScript.
2:05
We actually don't need it, but you can add some if you want, it would go in here.
2:08
We have our templates
2:09
and our templates are grouped by the views.
2:12
So we have our views like account, and cms and home.
2:15
And then we have our views, our Jinja templates for those.
2:17
So very important to group those in a clean way.
2:19
And then our data exchange models
2:22
what data comes from the user
2:25
and what data is passed to the template
2:26
and what validation do we have
2:27
like you have account home, and logon
2:29
and register view models in there.
2:31
We'll talk about what those are when we get to them.
2:34
But then finally, we have our views.
2:37
These are the decorated functions
2:40
that run when a request comes in.
2:41
That's kind of the top level bit there.
2:43
Then we have our app.py, this is the start up code
2:45
and registration and database configuration.
2:48
All that kind of stuff.
2:49
This is where we're going.
2:50
A lot of this might not make any sense yet
2:52
and that's totally fine, we're going to
2:53
spend a whole chapter on that
2:54
and we're going to spend a whole chapter on that, and so on.
2:57
Also, here for example.
2:58
So we're going to build this up
2:59
but I want to give you a glimpse of what is this
3:02
going to look like when its done.
3:03
What did this project structure
3:05
for a real Flask app look like?
3:07
Well, here's my example.