Skip to content

Simple example of FastAPI using MVC and microservices elements architecture, the application contained here develops some functionalities for accessing the database and creating models and tests. Below are the steps required to run the database and the application backend locally.

License

Notifications You must be signed in to change notification settings

robsonlimadeveloper/fast-api-mvc-example

Repository files navigation


FastAPI MVC Example

Buy Me a Coffee at ko-fi.com

A simple and scalable FastAPI project following the MVC (Model-View-Controller) pattern with elements of a microservices architecture. This application demonstrates core functionalities such as database access, model creation, and automated testing. Below are the steps required to run the database and the application backend locally.

Develop with:

Existing Features: 🚀

✅ Clean Architecture: Well-organized file structure for easy maintenance and scalability.

✅ Ready-to-Use Configuration: Pre-configured for both development and production environments.

✅ SQLAlchemy Database Management: Robust model handling and database operations.

✅ Well-Defined RESTful APIs: Ready-to-use CRUD and authentication endpoints.

✅ Integrated Documentation: Swagger and Redoc for easy API exploration.

The proposed structure is described as follows:
/app
    __init__.py
    main.py
    /modules
            __init__.py
            /module_1/
                     __init__.py
                     exceptions.py
		     dto.py
		     model.py
		     repository.py
		     service.py
		     views.py
	    /module_2/
                     __init__.py
                     exceptions.py
		     dto.py
		     model.py
		     repository.py
		     service.py
		     views.py
	      /config
		     __init__.py
	      /seeds
		    seed_module_1.py
		    seed_module_2.py
		    seeder.py
/tests
.env
.gitignore
docker-compose.yml
Dockerfile
README.md
requirements.txt

Getting Started:

Follow the steps below to set up and run the database and backend application locally.

Prerequisites

Docker Desktop installed on the environment. (Windows)

Docker Engine and Compose installed on the environment. (Linux)

Installation

Build project

$ docker-compose up --build -d

API Documentation

http://localhost:4010/v1/api/docs/
http://localhost:4010/v1/api/redoc/

Run tests (pytest)

$ docker exec -it api bash
@container $ pytest --capture=no -s -v

Access container database

$ docker exec -it db bash
@container $ psql -U postgres -p 5432

License

MIT - Robson Soares - 2024

About

Simple example of FastAPI using MVC and microservices elements architecture, the application contained here develops some functionalities for accessing the database and creating models and tests. Below are the steps required to run the database and the application backend locally.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published