Skip to content

Maua-Dev/clean_mss_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

clean_mss_template ๐ŸŒก๐Ÿฝ

Template for microservices repositories based in Clean Arch

The Project ๐Ÿ“ฝ

Introduction and Objectives โ‰

The main objective is to provide a template for repositories that can be used as a starting point for new projects. This architecture is based on the Clean Architecture, and it was based in many other projects and books, articles that were mixed by the students of Mauรก Institute of Technology, from the academic group Dev. Community Mauรก.

Reasons 1๏ธโƒฃ3๏ธโƒฃ

The project aims to help developers to start new projects with a good architecture, and with a good structure, so that anybody can create good applications.

Clean Architecture ๐Ÿงผ๐Ÿฐ

The purpose of the project is to learn and create a Clean Architecture for microservices stateless with AWS Lambda which is a way of structuring the code in layers, each of which has a specific responsibility. This architecture is based on the principles of SOLID and books like "Clean Architecture: A Craftsman's Guide to Software Structure and Design" by Robert C. Martin.

We also tried to explain for new programmers in the mos intuitive way and you can see the explanation here: Clean Architecture Figma

Folder Structure ๐ŸŽ„๐ŸŒด๐ŸŒฒ๐ŸŒณ

Our folder structure was developed specially for our projects.

.
โ”œโ”€โ”€ iac
โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ modules
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ create_user
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ delete_user
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ get_user
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ update_user
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ app
โ”‚ย ย  โ””โ”€โ”€ shared
โ”‚ย ย      โ”œโ”€โ”€ domain
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ entities
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ enums
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ repositories
โ”‚ย ย      โ”œโ”€โ”€ helpers
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ enum
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ errors
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ functions
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ http
โ”‚ย ย      โ””โ”€โ”€ infra
โ”‚ย ย          โ”œโ”€โ”€ dto
โ”‚ย ย          โ”œโ”€โ”€ external
โ”‚ย ย          โ””โ”€โ”€ repositories
โ””โ”€โ”€ tests
    โ”œโ”€โ”€ modules
    โ”‚ย ย  โ”œโ”€โ”€ create_user
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
    โ”‚ย ย  โ”œโ”€โ”€ delete_user
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
    โ”‚ย ย  โ”œโ”€โ”€ get_user
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ app
    โ”‚ย ย  โ””โ”€โ”€ update_user
    โ”‚ย ย      โ””โ”€โ”€ app
    โ””โ”€โ”€ shared
        โ”œโ”€โ”€ domain
        โ”‚ย ย  โ””โ”€โ”€ entities
        โ”œโ”€โ”€ helpers
        โ””โ”€โ”€ infra

Name Format ๐Ÿ“›

Files and Directories ๐Ÿ“

  • Files have the same name as the classes
  • snake_case ๐Ÿ (ex: ./app/create_user_controller.py)

Classes ๐Ÿ•ด

  • Pattern ๐Ÿ“Ÿ

    • CamelCase ๐Ÿซ๐Ÿช
  • Types ๐Ÿงญ

    • Interface starts with "I" --> IUserRepository, ISelfieRepository ๐Ÿ˜€
    • Repository have the same name as interface, without the "I" and the type in final (ex: UserRepositoryMock, SelfieRepositoryDynamo) ๐Ÿฅฌ
    • Controller ends with "Controller" --> CreateUserController, GetSelfieController ๐ŸŽฎ
    • Usecase ends with "Usecase" --> CreateUserUsecase, GetSelfieUsecase ๐Ÿ 
    • Viewmodel ends with "Viewmodel" --> CreateUserViewmodel, GetSelfieViewmodel ๐Ÿ‘€
    • Presenter ends with "Presenter" --> CreateUserPresenter, GetSelfiePresenter๐ŸŽ

Methods ๐Ÿ‘จโ€๐Ÿซ

  • snake_case ๐Ÿ
  • Try associate with a verb (ex: create_user, get_user, update_selfie)

Variables ๐Ÿ…ฐ

  • snake_case ๐Ÿ
  • Avoid verbs

Enums

  • SNAKE_CASE ๐Ÿ
  • File name ends with "ENUM" (ex: "STATE_ENUM")

Tests ๐Ÿ“„

  • snake_case ๐Ÿ
  • "test" follow by class name (ex: test_cadastrar_usuario_valido, test_cadastrar_usuario_sem_email)
    • The files must start with "test" to pytest recognition

Commit ๐Ÿ’ข

  • Start with verb
  • Ends with emoji ๐Ÿ˜Ž

Architecture Diagram ๐Ÿ—

img.png

Installation ๐Ÿ‘ฉโ€๐Ÿ’ป

Clone the repository using template

Create virtual ambient in python (only first time)

Windows
python -m venv venv
Linux
virtualenv -p python3.9 venv

Activate the venv

Windows:
venv\Scripts\activate
Linux:
source venv/bin/activate

Install the requirements

pip install -r requirements-dev.txt

Run the tests

pytest

To run local set .env file

STAGE = TEST

Contributors ๐Ÿ’ฐ๐Ÿค๐Ÿ’ฐ

Special Thanks ๐Ÿ™

About

Template for microservices repositories based in Clean Arch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7