Project Structure
When you create a new project with jsweb new, it generates a standard directory structure designed for scalability and organization. Understanding this structure is key to developing applications with JsWeb.
Here’s what a typical JsWeb project looks like:
myproject/
├── alembic/ # Database migration scripts
├── static/ # Static files (CSS, JavaScript, images)
├── templates/ # Jinja2 templates
├── alembic.ini # Alembic configuration
├── app.py # Main application file
├── auth.py # Authentication logic and routes
├── config.py # Application configuration
├── forms.py # Form definitions
├── models.py # Database models
└── views.py # Application views and routes
Key Files and Directories
app.py
This is the entry point of your application. It's where you create the main JsWebApp instance, register blueprints, and configure your application.
config.py
This file contains all your application's configuration variables, such as the database URI, secret key, and other settings.
views.py
This file is intended to hold your application's main views and routes. For larger applications, it's common to organize routes into separate files using blueprints.
auth.py
This file contains the logic for user authentication, including registration, login, and logout routes. It's a good example of how to use blueprints to organize related functionality.
models.py
This is where you define your SQLAlchemy database models. These models are used by Alembic to generate database migrations.
forms.py
This file is where you define your application's forms using the built-in form library.
templates/
This directory contains your HTML templates. JsWeb uses Jinja2 for templating, so you can use all of Jinja2's features, such as template inheritance, macros, and filters.
static/
This directory is for your static assets, such as CSS, JavaScript, and images. These files are served directly by the web server.
alembic/
This directory contains the database migration scripts generated by Alembic. You shouldn't need to edit these files directly.
alembic.ini
This is the configuration file for Alembic. It contains the settings that Alembic uses to connect to your database and manage migrations.