From b0b4e2db435a52e9a2c75f24f110962d685ca5ec Mon Sep 17 00:00:00 2001 From: Martin Komischke Date: Wed, 18 Nov 2026 10:09:38 +0100 Subject: [PATCH] improve documentation --- LICENSE | 11 ++ LICENSE.md | 26 ---- README.md | 176 ++++++------------------ codecov.yml | 18 +++ docs/ARCHITECTURE.md | 101 ++++++++++++++ CONTRIBUTING.md => docs/CONTRIBUTING.md | 0 docs/KUBERNETES.md | 64 +++++++++ 7 files changed, 233 insertions(+), 163 deletions(-) create mode 100644 LICENSE delete mode 100644 LICENSE.md create mode 100644 codecov.yml create mode 100644 docs/ARCHITECTURE.md rename CONTRIBUTING.md => docs/CONTRIBUTING.md (100%) create mode 100644 docs/KUBERNETES.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d42d1af --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +MIT License +=========== + +Copyright (c) Martin Komischke + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 1c4a05b..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,26 +0,0 @@ -The MIT License (MIT) -===================== - -Copyright © Martin Komischke - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index e81d240..7f85853 100644 --- a/README.md +++ b/README.md @@ -1,167 +1,69 @@ +
+ # Fairly +**Split expenses and settle debts between individuals.** 💚 + + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![PHP Version](https://img.shields.io/badge/PHP-8.4-777BB4.svg?logo=php&logoColor=white)](https://www.php.net/) +[![Docker](https://img.shields.io/badge/Docker-Multi--stage-2496ED?logo=docker&logoColor=white)](https://www.docker.com/) +[![Kubernetes](https://img.shields.io/badge/Kubernetes-Helm-326CE5?logo=kubernetes&logoColor=white)](https://helm.sh/) ![app-ci-workflow](https://github.com/makomweb/fairly/actions/workflows/app-ci.yaml/badge.svg) -[![codecov](https://codecov.io/gh/makomweb/fairly/graph/badge.svg?token=O6WQ8USL6T)](https://codecov.io/gh/makomweb/fairly) +[![codecov](https://img.shields.io/codecov/c/github/makomweb/fairly?flag=core&logo=codecov&token=O6WQ8USL6T)](https://codecov.io/gh/makomweb/fairly?flags[0]=core) + +
-## Goal +--- -This is a full-stack, cloud-native web application for tracking and splitting expenses and settling debts among 2 individuals. It is built on PHP 8.4, Symfony 8, MySQL 8, and React 19, and uses **event sourcing** to maintain a complete audit trail of all financial transactions. +## 🎯 Purpose -It follows DDD principles to separate the application into generic, core, and supporting domains — enforced by [deptrac](https://github.com/deptrac/deptrac). This makes it easy to achieve full code coverage for the core domain. +A full-stack, cloud-native web application for tracking and splitting expenses and settling debts among 2 individuals. Built on **PHP 8.4**, **Symfony 8**, **MySQL 8**, and **React 19**, featuring **event sourcing** for a complete audit trail. -It also showcases Kubernetes deployment using Helm. +By strictly isolating the **Core** from infrastructure and framework code (enforced via [deptrac](https://github.com/deptrac/deptrac)), the business logic achieves **100% test coverage**. -## Screenshots +## 📸 Screenshots - - - + + +
Login viewTrack viewCalculate viewLogin viewTrack viewCalculate view
-## Prerequisites - -### For Docker Compose (Local Development) -- [Make](https://www.gnu.org/software/make/) -- [Docker](https://www.docker.com/) -- [Docker Compose](https://docs.docker.com/compose/) - -### For Kubernetes Deployment -- [Make](https://www.gnu.org/software/make/) -- [Docker](https://www.docker.com/) -- [Kubernetes](https://kubernetes.io/) (kind, minikube, or Docker Desktop) -- [Helm 3](https://helm.sh/) +## 🚀 Quick Start (Local Development) -## Local Development (Docker Compose) +### Prerequisites +* [Make](https://www.gnu.org/software/make/) +* [Docker](https://www.docker.com/) & [Docker Compose](https://docs.docker.com/compose/) +### Run ```bash make start # Build images, start services, and open in browser make help # Show all available targets ``` - Visit `http://localhost:8000` in your browser. -## Contributing - -See [CONTRIBUTING.md](./CONTRIBUTING.md) for: -- Running tests -- Code style and quality checks -- Database migrations -- Development workflow - -## Architecture - -``` - Browser / Client - │ - ┌────────────────┼─────────────────┐ - │ :8000 │ :8080 │ :5173 (dev) - ▼ ▼ ▼ - ┌────────────┐ ┌──────────────┐ ┌───────────────┐ - │ dashboard │ │ web (Nginx) │ │ npm-dev │ - │ (Homer) │ │ │ │ (Vite/React/ │ - └────────────┘ └──────┬───────┘ │ TypeScript) │ - │ FastCGI └───────────────┘ - │ :9000 - ▼ - ┌──────────────────┐ async ┌──────────────┐ - │ app (PHP-FPM) │────messages────▶│ worker │ - │ Symfony │ │ (Messenger) │ - └──────────────────┘ └──────────────┘ - │ │ - └────────────────┬────────────────┘ - │ SQL - ▼ - ┌─────────────────┐ - │ db (MySQL) │ - └─────────────────┘ - - ───────────────────────── Backend Layers ───────────────────────── - - ┌─────────────────────────────────────────────────────────────────┐ - │ Supporting │ Controllers · Auth · Repositories · Async │ - │ │ Normalizers · Instrumentation · EventListeners │ - ├──────────────┴──────────────────────────────────────────────────┤ - │ Core │ ExpenseTracker · Calculator │ - │ (Domain) │ Event Sourcing · Expenses · Compensation │ - ├──────────────┴──────────────────────────────────────────────────┤ - │ Generic │ Symfony · Doctrine · Twig · DomPDF · Monolog | - | │ PhpParser · phpDocumenter · OpenAPI | - └─────────────────────────────────────────────────────────────────┘ - Supporting depends on Core & Generic · Core has no deps -``` - -## Kubernetes Deployment +## 🚢 Kubernetes & Helm Deployment +Deploy production-ready with Helm: ```bash -# Build production images +# Build production images & deploy make prod +helm upgrade --install app ./helm --set replicaCount.app=3 --set replicaCount.worker=2 +``` +For detailed Kubernetes setup, port-forwarding, and architecture, see [docs/KUBERNETES.md](./docs/KUBERNETES.md). -# Deploy with 3 app pods + 2 worker pods -helm install app ./helm --set replicaCount.app=3 --set replicaCount.worker=2 -# or: -helm upgrade --install app ./helm - -# Access the application via NodePort: -# Link: http://localhost:30190 -# Or configure port forwarding via: -kubectl port-forward svc/app-fairly-web 8080:80 -# Link: http://localhost:8080 +## 🏛️ Architecture -# View logs for all pods with the PHP label (app + worker) -kubectl logs -f -l technology=php -``` +* **Backend Layers:** Clear separation into 3 subdomains: *Core*, *Supporting*, and *Generic*. +* **Event Sourcing:** Full audit trail stored in MySQL. -### Kubernetes Architecture +For full system diagrams and deep-dive architecture insights, check out [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md). -``` -┌────────────────────────────────────────────────────────────────────────┐ -│ Kubernetes Cluster │ -├────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ -│ │ nginx (web) │ │ app (PHP-FPM) │ │ worker │ │ -│ │ Deployment │ │ Deployment │ │ (Messenger) │ │ -│ │ NodePort:30190 │ │ Pod × 1 │ │ Pod × 1 │ │ -│ │ Pods × 1 │─→│ FastCGI :9000 │ │ One-shot pattern │ │ -│ └──────────────────┘ └──────────────────┘ └──────────────────┘ │ -│ │ │ │ │ -│ │ Serves SPA │ Business logic │ Async tasks │ -│ │ EasyAdmin │ API endpoints │ from queue │ -│ │ Static assets │ Session mgmt (DB) │ │ -│ │ │ Event sourcing (DB) │ │ -│ │ │ │ │ -│ └───────────┬───────────┴───────────┬───────────┘ │ -│ │ │ │ -│ ┌──────▼───────────────────────▼──┐ │ -│ │ MySQL StatefulSet │ │ -│ │ PVC Storage (8Gi) │ │ -│ │ - Event store │ │ -│ │ - Sessions │ │ -│ │ - Application data │ │ -│ └─────────────────────────────────┘ │ -│ △ │ -│ │ init Job │ -│ ┌──────┴──────┐ │ -│ │ db-init │ │ -│ │ (one-time) │ │ -│ └─────────────┘ │ -│ │ -│ ┌──────────────────────────────────────────────────────────────┐ │ -│ │ Grafana Alloy (k8s-monitoring) │ │ -│ │ - Collects logs from all pods │ │ -│ │ - Metrics collection & forwarding │ │ -│ └──────────────────────────────────────────────────────────────┘ │ -│ │ -└────────────────────────────────────────────────────────────────────────┘ -``` +## 🤝 Contributing & Documentation -**Components:** -- **nginx (web)**: Serves React SPA frontend, static assets, EasyAdmin UI. Proxies API requests to PHP-FPM via FastCGI. -- **PHP-FPM (app)**: Symfony backend handling business logic, API endpoints, and session management. Stores sessions in MySQL. -- **Worker**: Processes async jobs via Messenger with one-shot pattern (processes single message per pod lifecycle, then restarts for fresh environment). -- **MySQL**: Persistent data storage with StatefulSet and PVC. Stores event sourcing audit trail, sessions, and application data. -- **db-init Job**: One-time database initialization (schema, fixtures, migrations). -- **Grafana Alloy**: Log collection and forwarding for observability across all cluster components. +* **[Contributing Guide](./docs/CONTRIBUTING.md):** Running tests, code style, and database migrations. +* **[Kubernetes Guide](./docs/KUBERNETES.md):** Pod structure, storage, and monitoring. +* **[Architecture Overview](./docs/ARCHITECTURE.md):** Detailed flowcharts and DDD boundaries. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..fa66f34 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,18 @@ +fixes: + - "/var/www/project/src/::src/" + +coverage: + status: + project: + default: + target: auto + core: + target: 100% + flags: + - core + +flags: + core: + paths: + - src/Fairly/ + carryforward: true \ No newline at end of file diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..236aaaf --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,101 @@ +# 🏛️ Architecture + +This document provides an overview of the local development environment, backend domain boundaries, and Kubernetes cluster architecture for **Fairly**. + +--- + +## System & Local Development Architecture + +``` + Browser / Client + │ + ┌────────────────┼─────────────────┐ + │ :8000 │ :8080 │ :5173 (dev) + ▼ ▼ ▼ + ┌────────────┐ ┌──────────────┐ ┌───────────────┐ + │ dashboard │ │ web (Nginx) │ │ npm-dev │ + │ (Homer) │ │ │ │ (Vite/React/ │ + └────────────┘ └──────┬───────┘ │ TypeScript) │ + │ FastCGI └───────────────┘ + │ :9000 + ▼ + ┌──────────────────┐ async ┌──────────────┐ + │ app (PHP-FPM) │────messages────▶│ worker │ + │ Symfony │ │ (Messenger) │ + └──────────────────┘ └──────────────┘ + │ │ + └────────────────┬────────────────┘ + │ SQL + ▼ + ┌─────────────────┐ + │ db (MySQL) │ + └─────────────────┘ +``` + +--- + +## Backend Layers (DDD) + +Fairly follows Domain-Driven Design (DDD) principles to separate the application into generic, core, and supporting domains — enforced by [deptrac](https://github.com/deptrac/deptrac). This isolation makes it easy to achieve full code coverage for the core domain. + +``` + ───────────────────────── Backend Layers ───────────────────────── + + ┌─────────────────────────────────────────────────────────────────┐ + │ Supporting │ Controllers · Auth · Repositories · Async │ + │ │ Normalizers · Instrumentation · EventListeners │ + ├──────────────┴──────────────────────────────────────────────────┤ + │ Core │ ExpenseTracker · Calculator │ + │ │ Event Sourcing · Expenses · Compensation │ + ├──────────────┴──────────────────────────────────────────────────┤ + │ Generic │ Symfony · Doctrine · Twig · DomPDF · Monolog │ + │ │ PhpParser · phpDocumenter · OpenAPI │ + └─────────────────────────────────────────────────────────────────┘ + Supporting depends on Core & Generic · Core has no deps +``` + +--- + +## Kubernetes Cluster Architecture + +``` +┌────────────────────────────────────────────────────────────────────────┐ +│ Kubernetes Cluster │ +├────────────────────────────────────────────────────────────────────────┤ +│ │ +│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ +│ │ nginx (web) │ │ app (PHP-FPM) │ │ worker │ │ +│ │ Deployment │ │ Deployment │ │ (Messenger) │ │ +│ │ NodePort:30190 │ │ Pod × 1 │ │ Pod × 1 │ │ +│ │ Pods × 1 │─→│ FastCGI :9000 │ │ One-shot pattern │ │ +│ └──────────────────┘ └──────────────────┘ └──────────────────┘ │ +│ │ │ │ │ +│ │ Serves SPA │ Business logic │ Async tasks │ +│ │ EasyAdmin │ API endpoints │ from queue │ +│ │ Static assets │ Session mgmt (DB) │ │ +│ │ │ Event sourcing (DB) │ │ +│ │ │ │ │ +│ └───────────┬───────────┴───────────┬───────────┘ │ +│ │ │ │ +│ ┌──────▼───────────────────────▼──┐ │ +│ │ MySQL StatefulSet │ │ +│ │ PVC Storage (8Gi) │ │ +│ │ - Event store │ │ +│ │ - Sessions │ │ +│ │ - Application data │ │ +│ └─────────────────────────────────┘ │ +│ △ │ +│ │ init Job │ +│ ┌──────┴──────┐ │ +│ │ db-init │ │ +│ │ (one-time) │ │ +│ └─────────────┘ │ +│ │ +│ ┌──────────────────────────────────────────────────────────────┐ │ +│ │ Grafana Alloy (k8s-monitoring) │ │ +│ │ - Collects logs from all pods │ │ +│ │ - Metrics collection & forwarding │ │ +│ └──────────────────────────────────────────────────────────────┘ │ +│ │ +└────────────────────────────────────────────────────────────────────────┘ +``` \ No newline at end of file diff --git a/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to docs/CONTRIBUTING.md diff --git a/docs/KUBERNETES.md b/docs/KUBERNETES.md new file mode 100644 index 0000000..8efa6a5 --- /dev/null +++ b/docs/KUBERNETES.md @@ -0,0 +1,64 @@ +# 🚢 Kubernetes & Helm Deployment + +This guide covers deploying **Fairly** to a Kubernetes cluster using Helm. + +--- + +## Prerequisites + +* [Make](https://www.gnu.org/software/make/) +* [Docker](https://www.docker.com/) +* [Kubernetes](https://kubernetes.io/) (kind, minikube, or Docker Desktop) +* [Helm 3](https://helm.sh/) + +--- + +## Deployment Commands + +```bash +# 1. Build production images +make prod + +# 2. Deploy with 3 app pods + 2 worker pods +helm install app ./helm --set replicaCount.app=3 --set replicaCount.worker=2 + +# Or upgrade an existing release: +helm upgrade --install app ./helm +``` + +--- + +## Accessing the Application + +* **Via NodePort:** + Open [http://localhost:30190](http://localhost:30190) in your browser. +* **Via Port Forwarding:** + ```bash + kubectl port-forward svc/app-fairly-web 8080:80 + ``` + Then visit [http://localhost:8080](http://localhost:8080). + +--- + +## Monitoring & Logs + +View live logs for all pods with the PHP label (`app` + `worker`): + +```bash +kubectl logs -f -l technology=php +``` + +--- + +## Cluster Components + +* **nginx (web):** Serves React SPA frontend, static assets, and EasyAdmin UI. Proxies API requests to PHP-FPM via FastCGI. +* **PHP-FPM (app):** Symfony backend handling business logic, API endpoints, and session management (stored in MySQL). +* **Worker:** Processes async jobs via Symfony Messenger using a one-shot pattern (processes a single message per pod lifecycle, then restarts for a fresh environment). +* **MySQL:** Persistent data storage via StatefulSet and PVC (8Gi). Stores the event sourcing audit trail, sessions, and application data. +* **db-init Job:** One-time database initialization (schema, fixtures, migrations). +* **Grafana Alloy:** Log collection and metrics forwarding for observability across all cluster components. + +--- + +> 💡 Looking for the cluster diagram? Check out [ARCHITECTURE.md](./ARCHITECTURE.md). \ No newline at end of file