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


Talk Python's Mastodon Michael Kennedy's Mastodon