Skip to content

Commit fc54306

Browse files
authored
Docs update (#105)
* Switch to MADR3 ADR format * Move PUML diagrams and fix links * Install Mermaid2 plugin * Move documentation to mkdocs site and improve it Signed-off-by: Federico Busetti <[email protected]>
1 parent f81aaf6 commit fc54306

31 files changed

+792
-399
lines changed

.adr-dir

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1010
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
1111

12-
This is an example implementation of microservice applying
12+
This is an example implementation of a python application applying
1313
concepts from [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
1414
and [SOLID principles](https://en.wikipedia.org/wiki/SOLID).
1515

@@ -18,53 +18,26 @@ and [SOLID principles](https://en.wikipedia.org/wiki/SOLID).
1818
* The application frameworks are decoupled from the domain logic
1919
* The storage layer is decoupled from the domain logic
2020

21-
In this way our components are loosely coupled and the application logic
22-
(the domains package) is completely independent of the chosen framework
23-
and the persistence layer.
21+
This template provides out of the box some commonly used functionalities:
2422

25-
## HTTP API Docs and versioning
23+
* API Documentation using [FastAPI](https://fastapi.tiangolo.com/)
24+
* Async tasks execution using [Celery](https://docs.celeryq.dev/en/stable/index.html)
25+
* Repository pattern for databases using [SQLAlchemy](https://www.sqlalchemy.org/) and [SQLAlchemy bind manager](https://febus982.github.io/sqlalchemy-bind-manager/stable/)
26+
* Database migrations using [Alembic](https://alembic.sqlalchemy.org/en/latest/) (configured supporting both sync and async SQLAlchemy engines)
27+
* [TODO] Producer and consumer to emit and consume events using [CloudEvents](https://cloudevents.io/) format on [Confluent Kafka](https://docs.confluent.io/kafka-clients/python/current/overview.html)
2628

27-
API documentation is provided by [FastAPI](https://fastapi.tiangolo.com/features/)
28-
on `/docs` and `/redoc` paths using OpenAPI format.
29+
## Documentation
2930

30-
I believe that versioning an API at resource level provides a much more
31-
flexible approach than versioning the whole API.
31+
The detailed documentation is available:
3232

33-
The example `books` domain provides 2 endpoints to demonstrate this approach
33+
* Online on [GitHub pages](https://febus982.github.io/bootstrap-python-fastapi/)
34+
* Offline by running `make docs` after installing dependencies with `make dev-dependencies`
3435

35-
* `/api/books/v1` (POST)
36-
* `/api/books/v2` (POST)
36+
## How to use
3737

38-
## Package layers
39-
40-
This application is structured following the principles of Clean Architecture.
41-
Higher level layers can import directly lower level layers. An inversion of control
42-
pattern has to be used for lower level layers to use higher level ones.
43-
44-
Packages are ordered from the highest level to the lowest one.
45-
46-
------
47-
48-
* `alembic` (database migration manager)
49-
* `http_app` (http presentation layer)
50-
* `celery_worker` (async tasks runner)
51-
* `gateways` (database connection manager, repository implementation, event emitter, etc.)
52-
53-
------
54-
55-
* `domains` (services, repository interfaces)
56-
57-
------
58-
59-
## Class dependency schema
60-
61-
![](architecture.png)
62-
63-
## Data flow and layers responsibilities
64-
65-
![](flow.png)
66-
67-
## How to run
38+
Create your GitHub repository using this template (The big green `Use this template` button).
39+
Optionally tweak name and authors in the `pyproject.toml` file, however the metadata
40+
are not used when building the application, nor are referenced anywhere in the code.
6841

6942
Using Docker:
7043

@@ -104,4 +77,4 @@ The following setup makes sure the production image will keep to a minimal size
10477
Using the following pipeline the "test" image is instead ~850MB, more than 400MB that would
10578
end up as a cost in traffic on each image pull.
10679

107-
![](docker-container.png)
80+
![](docs/puml/docker-container.png)

architecture.png

-48 KB
Binary file not shown.

architecture.puml

Lines changed: 0 additions & 54 deletions
This file was deleted.

docker-container.png

-76.8 KB
Binary file not shown.

docker-container.puml

Lines changed: 0 additions & 76 deletions
This file was deleted.

docs/.pages

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
nav:
22
- Home: index.md
3+
- api-documentation.md
4+
- architecture.md
5+
- src packages: packages
6+
- inversion-of-control.md
7+
- dockerfile.md
8+
- ...
39
- ADR: adr

docs/adr/.markdownlint

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# source: https://github.com/adr/madr/blob/3.0.0/template/.markdownlint.yml
2+
default: true
3+
4+
# Allow arbitrary line length
5+
#
6+
# Reason: We apply the one-sentence-per-line rule. A sentence may get longer than 80 characters, especially if links are contained.
7+
#
8+
# Details: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md013---line-length
9+
MD013: false
10+
11+
# Allow duplicate headings
12+
#
13+
# Reasons:
14+
#
15+
# - The chosen option is considerably often used as title of the ADR (e.g., ADR-0015). Thus, that title repeats.
16+
# - We use "Examples" multiple times (e.g., ADR-0010).
17+
# - Markdown lint should support the user and not annoy them.
18+
#
19+
# Details: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md024---multiple-headings-with-the-same-content
20+
MD024: false

docs/adr/.pages

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
nav:
22
- Summary: summary.md
3-
- ...
3+
- ... | regex=^\d{4}-
Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1-
# 1. Record architecture decisions
2-
3-
Date: 2024-01-11
4-
5-
## Status
6-
7-
Accepted
8-
9-
## Context
10-
11-
We need to record the architectural decisions made on this project.
12-
13-
## Decision
14-
15-
We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions).
16-
17-
## Consequences
18-
19-
See Michael Nygard's article, linked above. For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
1+
---
2+
# source: https://github.com/adr/madr/blob/3.0.0/template/adr-template.md
3+
# These are optional elements. Feel free to remove any of them.
4+
status: accepted
5+
date: 2024-02-03
6+
# status: {proposed | rejected | accepted | deprecated | … | superseded by [ADR-0005](0005-example.md)}
7+
# date: {YYYY-MM-DD when the decision was last updated}
8+
# deciders: {list everyone involved in the decision}
9+
# consulted: {list everyone whose opinions are sought (typically subject-matter experts); and with whom there is a two-way communication}
10+
# informed: {list everyone who is kept up-to-date on progress; and with whom there is a one-way communication}
11+
---
12+
# Use Markdown Any Decision Records
13+
14+
## Context and Problem Statement
15+
16+
We want to record any decisions made in this project independent whether decisions concern the architecture ("architectural decision record"), the code, or other fields.
17+
Which format and structure should these records follow?
18+
19+
## Considered Options
20+
21+
* [MADR](https://adr.github.io/madr/) 3.0.0 – The Markdown Any Decision Records
22+
* [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions) – The first incarnation of the term "ADR"
23+
* Other templates listed at <https://schubmat.github.io/DecisionCapture>
24+
* Formless – No conventions for file format and structure
25+
26+
## Decision Outcome
27+
28+
Chosen option: "MADR 3.0.0", because
29+
30+
* Implicit assumptions should be made explicit.
31+
Design documentation is important to enable people understanding the decisions later on.
32+
See also [A rational design process: How and why to fake it](https://doi.org/10.1109/TSE.1986.6312940).
33+
* MADR allows for structured capturing of any decision.
34+
* The MADR format is lean and fits our development style.
35+
* The MADR structure is comprehensible and facilitates usage & maintenance.
36+
* The MADR project is vivid.

0 commit comments

Comments
 (0)