Flask REST API Clean Architecture Practice
A Clean Architecture Practice with Flask REST API.
This is a practice project I used to learn Clean Architecture by implementing the REST API with a full Authentication/Authorization Protocols, Dependency Injection and furthermore the Swagger documentation.
Basic Folder Structure
application.py
The major application declaration file.
apps
The Application Layer that defines API controller endpoint, global exceptions and also Request/Response/Presenter/Validator adapters.
config
Application Configuration files are here.
core
The core concept of the Clean Architecture practice. The kernel
part is about the interface and abstract class definitions. The core
part contains the business logic and the domains objects such as entity, value object, use case and also the repository.
extensions
Some configuration and plugins I used, to make the application itself cleaner.
infra
The Infrastructure Layer that provides the actual implementation of network, persistent, cache layer... etc.
tests
Test folder, not implemented yet.
Dependencies
flask
: Base Web Frameworkwerkzeug
: Utility Library under Flaskauthlib
: OpenID Connect Provider Libraryflask-restplus
= REST API, Swagger Libraryflask-injector
= Dependency Injectionattrs
= Data Classes Utility LIbrarycattrs
= Serialization / Deserialization
Run the project
> pipenv sync
Enter Shell
> pipenv shell
Start App
> flask run
Sample API request
API Documentation
TODO Items for POC
- Apply Clean Architecture
- Layer Abstraction
- Dependency Injection
- UseCase Implementation
- Serialization / Deserialization
- Mock Repo Implementation
- Handle Exceptions
- Response Marshalling
- Review usecase.execute() with Req/Resp
- Review API Documentation
- Implement Full Story with Entity, ValueObject
- Request Validation with Marshmallow
- Deal with Date/DateTime
- Database with SQLAlchemy
- Logging
- OAuth2 with Authlib Implementation
- Authentication to Resource API
- Dev/Prod Configuration
- Apply Tests
- WSGI Settings