FastAPI based ecommerce backend.
By default, the dependencies are managed with uv, go there and install it.
You can install all the dependencies with:
$ uv syncThen you can activate the virtual environment with:
$ source .venv/bin/activateMake sure your editor is using the correct Python virtual environment, with the interpreter at ./.venv/bin/python.
Modify or add SQLModel models for data and SQL tables in ./app/models.py, API endpoints in ./app/api/, CRUD (Create, Read, Update, Delete) utils in ./app/crud.py.
There are already configurations in place to run the backend through the VS Code debugger, so that you can use breakpoints, pause and explore variables, etc.
The setup is also already configured so you can run the tests through the VS Code Python tests tab.
You can use the fastapi run --reload command to run the debug live reloading server.
$ fastapi run --reload app/main.pyTo test the backend run:
$ bash ./scripts/test.shWhen the tests are run, a file htmlcov/index.html is generated, you can open it in your browser to see the coverage of the tests.
As during local development your app directory is mounted as a volume inside the container, you can also run the migrations with alembic commands inside the container and the migration code will be in your app directory (instead of being only inside the container). So you can add it to your git repository.
Make sure you create a "revision" of your models and that you "upgrade" your database with that revision every time you change them. As this is what will update the tables in your database. Otherwise, your application will have errors.
-
Alembic is already configured to import your SQLModel models from
./app/models.py. -
After changing a model (for example, adding a column), inside the container, create a revision, e.g.:
$ alembic revision --autogenerate -m "Add column last_name to User model"-
Commit to the git repository the files generated in the alembic directory.
-
After creating the revision, run the migration in the database (this is what will actually change the database):
$ alembic upgrade headIf you don't want to use migrations at all, uncomment the lines in the file at ./app/core/db.py that end in:
SQLModel.metadata.create_all(engine)and comment the line in the file scripts/prestart.sh that contains:
$ alembic upgrade headIf you don't want to start with the default models and want to remove them / modify them, from the beginning, without having any previous revision, you can remove the revision files (.py Python files) under ./app/alembic/versions/. And then create a first migration as described above.
The email templates are in ./app/email-templates/. Here, there are two directories: build and src. The src directory contains the source files that are used to build the final email templates. The build directory contains the final email templates that are used by the application.
Before continuing, ensure you have the MJML extension installed in your VS Code.
Once you have the MJML extension installed, you can create a new email template in the src directory. After creating the new email template and with the .mjml file open in your editor, open the command palette with Ctrl+Shift+P and search for MJML: Export to HTML. This will convert the .mjml file to a .html file and now you can save it in the build directory.