Skip to content

Commit

Permalink
Tx and VAT + Various things (#39)
Browse files Browse the repository at this point in the history

    Design very minimal Tx base system
    Bug corrections
    Rename prj accounting to accounting-structure
    Blazor, best token and session management
    Application cleanup endpoint for integration tests
    First tx submit with validation
    Masstransit events chain after submit Tx
    Renaming, cleanings


Some important commits from older to new...

* First version of entry and transaction db entity design.

* Vat rate contarcts and mappers

* Vat rate, minimal base service. Change account to add the Active param.

* New account field

* Active/Inactive account + add a filter in the BlazorView

* IsActive account in Blazor

* Correction of bug in unique index for security api.

* Big commit: rename accounting api to accounting-structure.api

* Rename accounting contracts prj + namespace

* New backend prj to manage VAT or Sales tax

* Correct db name for accounting_struct_api and security api for table users_roles_by_tenant

* Put in place vatsales tax api

* Sales tax vat first endpoint

* Ok, token management is working better and in minikube too. Only session management is missing.

* Prepare for tax rates endpoints

* Cleanup endpoint for integration tests

* Test add taxrates, modify to dateonly for the valid to, valid from

* Change applications routes

* Change data seed for application in struct api

* Account data in sales-vat tax module.

* Some progress on attaching tax rates to account with a target tax rates account if needed. (for additionnal accounting entries)

* Add account tax rates config and init base data

* Add accountTaxratecongfigs tests

* Consumers account in VAT Tax Api

* Account consumers in tax api.

* Clean all the useless navigation properties

* Rename Feature erro type

* Prepare transaction service

* Consumer for tax rates in transaction API

* Populate tenant_id in events.

* Replace audit field in all model by a value object and adapt the change tracker accordinly

* Prepare for Submit TX

* First tx submit (with minimal and naive checks).

* Loop on entries check info.

* Submit transaction: first minimal version. (not checking from VAT api now)

* First submit TX test OK.

* Base routes testing for submit TX (security)

* Tx minimal first submit version

* Entry link for tax/vat entries that will be linked to other entries

* Blazor not used thing

* Ok Tx submit with state in the DB

* Fake consumer for tax validation

* Publish the state of a TX for other components...

* force ubik name as docker compose project

* Config for minikube for accounting-tx and accounting-tax

* comment in README

* update readme

* Remove unused usings

---------
  • Loading branch information
fdonnet authored Nov 15, 2024
1 parent c85a984 commit 057c2a3
Show file tree
Hide file tree
Showing 384 changed files with 9,293 additions and 1,823 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
/src/mycert.cer
85 changes: 54 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
NEW BIG PR implemented:
LAST BIG PR implemented:

- security api and tenant management
- remove authorization via roles from keycloack
- implement Yarp as a proxy and authorization manager (call the security api and forward request to backend apis, authorization via policy requierments for each route)
- remove masstransit for request/response, keep it only for events (pub/sub)
- review and simplify the test parts (complete review) => only integration tests for the moment. No real backend functions to unit test.
- Blazor app now calls the Yarp proxy
- double-entry preparation
- 2 new backend apis (tx and sales-or-vat-tax)
- Blazor better token management

Next steps between:

- vat-sales tax module implementation
- .Net 9 (Blazor adaptations)
- SingalR hub to trace tx status
- Blazor double-entry ui
- Aspire (re-test the thing)
- will see...

# Ubik - Accounting

Expand All @@ -26,11 +32,11 @@ At this stage, **DO NOT USE THIS SYSTEM ON A PRODUCTION** environnement.

## For the Kubernetes/Minikube guys

For detailed instructions on deploying locally with Minikube, please refer to the [local deployment guide](./deploy/deploy-local-readme.md).
For detailed instructions on deploying locally with Minikube (full experience), please refer to the [local deployment guide](./deploy/deploy-local-readme.md).

## Build and Run

At the root of the repository. "Mount" the dependencies with Docker by running this command in your terminal:
**At the root of the repository**, "Mount" the dependencies with Docker by running this command in your terminal:

`docker compose -f .\docker-compose.yml -f .\docker-integration-tests.yml up -d`

Expand All @@ -43,11 +49,15 @@ At the root of the repository. "Mount" the dependencies with Docker by running t
> - Pgadmin: to admin your dbs if needed
> - Apis: backend apis (security/accounting) for integration testing
### Ready to play
### Ready to play and debug

#### Run backend Apis or define a multiple projects startup

`dotnet run --launch-profile https --project ./src/Ubik.Accounting.SalesOrVatTax.Api/Ubik.Accounting.SalesOrVatTax.Api.csproj`

#### Run backend Apis
`dotnet run --launch-profile https --project ./src/Ubik.Accounting.Transaction.Api/Ubik.Accounting.Transaction.Api.csproj`

`dotnet run --launch-profile https --project ./src/Ubik.Accounting.Api/Ubik.Accounting.Api.csproj`
`dotnet run --launch-profile https --project ./src/Ubik.Accounting.Structure.Api/Ubik.Accounting.Structure.Api.csproj`

`dotnet run --launch-profile https --project ./src/Ubik.Security.Api/Ubik.Security.Api.csproj`

Expand All @@ -59,10 +69,7 @@ At the root of the repository. "Mount" the dependencies with Docker by running t

`dotnet run --launch-profile https --project ./src/Ubik.Accounting.WebApp/Ubik.Accounting.WebApp.csproj`

And now, you can access the very first version of a the Blazor 8 webapp here <https://localhost:7249>

*Don't change the ports of the api and the blazor apps. It's hard coded in the Blazor prj (need to be changed) because no service discovery for the moment.*
*In Debug, create a multiple project startup that runs all this stuff*
And now (when all the stuff are up and running), you can access the very first version of a the Blazor 8 webapp here <https://localhost:7249>

### All the things are up

Expand All @@ -82,40 +89,54 @@ Try to log with different access rights and play with the only available "Accoun

Now you can run your preferred code editor and start to deep dive... (see below)

## External libs

| Package | For what |
|----------- | -------- |
| [Asp.Versioning](https://github.com/dotnet/aspnet-api-versioning) | automatic versioning of API (controllers / endpoints) |
| EfCore | commands and ez queries + data init etc |
| [Dapper](https://github.com/DapperLib/Dapper) | some read queries |
| [EFCore.NamingConvention](https://github.com/efcore/EFCore.NamingConventions) | force EF core to postgres SnakeCase => way better if you need to use Dapper too |
| [LanguageExt.Core](https://github.com/louthy/language-ext) | use Either<Left, Right> pattern |
| [Masstransit](https://github.com/MassTransit/MassTransit) | message bus abstraction + inbox/outbox pattern |

## Yarp Proxy

-- Ubik.YarpProxy --

Manages all the authorization stuff by calling the security api and forward the requests to the backend. (cool af)
Manages all the authorization stuff by calling the security api and forward the requests to the backend.

## Security Api

-- Ubik.Security.Api --

Used by the proxy to manage authorizations and exposes admin and user endpoints to manage the authorizations/users/tenants config.

## Accounting Api
## Accounting structure Api

-- Ubik.Accounting.Api --
-- Ubik.Accounting.Structure.Api --

Some used external libs:
Manages the accounting structure.

| Package | For what |
|----------- | -------- |
| [Asp.Versioning](https://github.com/dotnet/aspnet-api-versioning) | automatic versioning of API (controllers / endpoints) |
| EfCore | commands and ez queries + data init etc |
| [Dapper](https://github.com/DapperLib/Dapper) | some read queries |
| [EFCore.NamingConvention](https://github.com/efcore/EFCore.NamingConventions) | force EF core to postgres SnakeCase => way better if you need to use Dapper too |
| [LanguageExt.Core](https://github.com/louthy/language-ext) | use Either<Left, Right> pattern |
| [Masstransit](https://github.com/MassTransit/MassTransit) | message bus abstraction + inbox/outbox pattern |
## Accounting tx Api

-- Ubik.Accounting.Transaction.Api --

For the moment, implement the submit Tx endpoint and create some states and events related to future Txs management.

# Accounting sales or VAT tax

-- Ubik.Accounting.SalesOrVatTax.Api --

Will implement all the rules related to sales or VAT taxes and validate a Tx when needed. Will be used to declare and enforce the rules. (for each country etc)

## Features folder in backend Apis

Contains the core features (in Vertical Slices mode).

- Command and query services
- When a command is executed with success, an event is published to the message bus (pub/sub)
- Functional `Either<Error, Result>` patterns in all layers to transfer errors between layer and to keep the code not too dirty. (not an expert but I like it)
- Functional `Either<Error, Result>` patterns in all layers to transfer errors between layer and to keep the code not too dirty.

## Frontend Blazor

Expand Down Expand Up @@ -149,7 +170,7 @@ Send some love on github to this projects...
- Typed HttpClient to access the backend api
- Tailwind config - Tailwind Flowbite design layout etc
- A very minimal reverse proxy controller that allows components (automode) to call the backend api when they are WASM.
- Some stuff about security (Token cache service, UserService with circuit, middleware)
- Some stuff about security (Token cache service)

In program.cs, you can access the config of:

Expand All @@ -158,6 +179,8 @@ In program.cs, you can access the config of:
- Cookie auth with OpenIdC (connection + refresh token in OnValidatePrincipal)
- ...

=> next, implement new .Net 9 Blazor stuff related to authentication and render modes.

### Ubik.Accounting.WebApp.Client

(client-auto side)
Expand All @@ -184,7 +207,7 @@ In program.cs, you can access the config of:

## Others

-- Ubik.Accounting.ApiService.Common -- / -- Ubik.Db.Common -- / -- Ubik.Accounting.Contracts --
-- Ubik.Accounting.ApiService.Common -- / -- Ubik.Db.Common -- / -- Ubik.xxx.Contracts --

- Common config things that can be reused in other projects
- This part will maybe grow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounting-api
name: accounting-structure-api
labels:
app: accounting-api
app: accounting-structure-api
spec:
replicas: 1
selector:
matchLabels:
app: accounting-api
app: accounting-structure-api
template:
metadata:
labels:
app: accounting-api
app: accounting-structure-api
spec:
containers:
- name: accounting-api
image: ubik-accounting-api-test:latest
- name: accounting-structure-api
image: ubik-accounting-structure-api-test:latest
imagePullPolicy: Never
env:
- name: ConnectionStrings__AccountingContext
value: 'Host=ubik-postgres-postgresql;Port=5432;Database=ubik_accounting;Username=postgres;Password=test01'
value: 'Host=ubik-postgres-postgresql;Port=5432;Database=ubik_accounting_struct;Username=postgres;Password=test01'
- name: ASPNETCORE_ENVIRONMENT
value: Development
- name: MessageBroker__Host
Expand All @@ -41,10 +41,10 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: accounting-api
name: accounting-structure-api
spec:
selector:
app: accounting-api
app: accounting-structure-api
ports:
- protocol: TCP
port: 80
Expand Down
51 changes: 51 additions & 0 deletions deploy/accounting-tax-api/accounting-tax-api-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounting-sales-vat-tax-api
labels:
app: accounting-sales-vat-tax-api
spec:
replicas: 1
selector:
matchLabels:
app: accounting-sales-vat-tax-api
template:
metadata:
labels:
app: accounting-sales-vat-tax-api
spec:
containers:
- name: accounting-sales-vat-tax-api
image: ubik-accounting-sales-vat-tax-api-test:latest
imagePullPolicy: Never
env:
- name: ConnectionStrings__AccountingSalesTaxDbContext
value: 'Host=ubik-postgres-postgresql;Port=5432;Database=ubik_accounting_salestax;Username=postgres;Password=test01'
- name: ASPNETCORE_ENVIRONMENT
value: Development
- name: MessageBroker__Host
value: 'amqp://ubik-rabbitmq:5672'
- name: AuthServer__MetadataAddress
value: "https://keycloak-local/realms/ubik/.well-known/openid-configuration"
- name: AuthServer__Authority
value: "https://keycloak-local/realms/ubik"
- name: AuthServer__AuthorizationUrl
value: "https://keycloak-local/realms/ubik/protocol/openid-connect/auth"
- name: AuthServer__TokenUrl
value: "https://keycloak-local/realms/ubik/protocol/openid-connect/token"
- name: AuthManagerKeyCloakClient__RootUrl
value: "http://keycloak-local/"
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: accounting-sales-vat-tax-api
spec:
selector:
app: accounting-sales-vat-tax-api
ports:
- protocol: TCP
port: 80
targetPort: 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounting-transaction-api
labels:
app: accounting-transaction-api
spec:
replicas: 1
selector:
matchLabels:
app: accounting-transaction-api
template:
metadata:
labels:
app: accounting-transaction-api
spec:
containers:
- name: accounting-transaction-api
image: ubik-accounting-tx-api-test:latest
imagePullPolicy: Never
env:
- name: ConnectionStrings__AccountingTxContext
value: 'Host=ubik-postgres-postgresql;Port=5432;Database=ubik_accounting_tx;Username=postgres;Password=test01'
- name: ASPNETCORE_ENVIRONMENT
value: Development
- name: MessageBroker__Host
value: 'amqp://ubik-rabbitmq:5672'
- name: AuthServer__MetadataAddress
value: "https://keycloak-local/realms/ubik/.well-known/openid-configuration"
- name: AuthServer__Authority
value: "https://keycloak-local/realms/ubik"
- name: AuthServer__AuthorizationUrl
value: "https://keycloak-local/realms/ubik/protocol/openid-connect/auth"
- name: AuthServer__TokenUrl
value: "https://keycloak-local/realms/ubik/protocol/openid-connect/token"
- name: AuthManagerKeyCloakClient__RootUrl
value: "http://keycloak-local/"
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: accounting-transaction-api
spec:
selector:
app: accounting-transaction-api
ports:
- protocol: TCP
port: 80
targetPort: 8080
38 changes: 33 additions & 5 deletions deploy/deploy-local-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Contains config to access the already existing postgres db

### Generate self signed certificate (if you want to change them in ingress)

To remember the commands only:
To remember the commands only (you can skip this part):

`openssl req -newkey rsa:2048 -nodes -keyout tls.key -out tls.csr`

Expand All @@ -73,19 +73,47 @@ To remember the commands only:

`helm install ubik-cache bitnami/redis -f ./redis/values-dev.yaml`

## Accounting Api
## Accounting Structure Api

Build image

`docker build -t ubik-accounting-api-test:latest -f ../src/Ubik.Accounting.Api/Dockerfile ../`
`docker build -t ubik-accounting-structure-api-test:latest -f ../src/Ubik.Accounting.Structure.Api/Dockerfile ../`

Load image in minikube

`minikube image load ubik-accounting-api-test:latest`
`minikube image load ubik-accounting-structure-api-test:latest`

Apply deployement

`kubectl apply -f ./accounting-api/accounting-api-deploy.yaml`
`kubectl apply -f ./accounting-structure-api/accounting-structure-api-deploy.yaml`

## Accounting Transaction Api

Build image

`docker build -t ubik-accounting-tx-api-test:latest -f ../src/Ubik.Accounting.Transaction.Api/Dockerfile ../`

Load image in minikube

`minikube image load ubik-accounting-tx-api-test:latest`

Apply deployement

`kubectl apply -f ./accounting-transaction-api/accounting-transaction-api-deploy.yaml`

## Accounting Sales Vat Tax Api

Build image

`docker build -t ubik-accounting-sales-vat-tax-api-test:latest -f ../src/Ubik.Accounting.SalesOrVatTax.Api/Dockerfile ../`

Load image in minikube

`minikube image load ubik-accounting-sales-vat-tax-api-test:latest`

Apply deployement

`kubectl apply -f ./accounting-tax-api/accounting-tax-api-deploy.yaml`

## Security api

Expand Down
2 changes: 1 addition & 1 deletion deploy/keycloack/ingress-for-keycloack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "http://ubik-proxy, http://ubik-webapp, https://ubik-webapp"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin"
nginx.ingress.kubernetes.io/configuration-snippet: |
Expand Down
Loading

0 comments on commit 057c2a3

Please sign in to comment.