From 25e85f68ed74609f4023b64d2bff8a2226643080 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 24 Mar 2024 20:17:14 +0100 Subject: [PATCH 1/4] N-FIN-45: add README content --- .env.example | 8 ++++ README.md | 67 +++++++++++++++++++++++++++++++ docker/finances-prod/.env.example | 11 +++++ 3 files changed, 86 insertions(+) create mode 100644 .env.example create mode 100644 docker/finances-prod/.env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ace6820 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ + +# +# This environment file sets variables for the development +# Database specifics are set in the docker-compose file and the ORIGIN is not required for local development +# + +# prisma database url +DATABASE_URL="postgresql://prisma:prisma@localhost:5432/finances?schema=public" diff --git a/README.md b/README.md index 1539d89..9f22666 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,70 @@ # Next-Finances This is my simple finances tracker that I use to keep track of my spending. + +## Using the app + +### Understanding the Basics + +- **Entities**: The core building blocks of your finances. + - Accounts: Where you hold money (e.g., bank accounts, PayPal account, cash) + - Entities: Where you spend money (e.g., Walmart, Spotify, Netflix) +- **Payments**: Record money movement. + - Expenses: Money leaving an Account. (Account -> Entity) + - Income: Money entering an Account. (Entity -> Account) +- **Categories** *(optional)*: Add labels to Payments for better tracking. + +### Your First Steps + +- Set up: Create Entities and Accounts that reflect your finances. +- Record a Payment: + - Enter the amount and date. + - Select payor and payee + - *(optional)* Assign a category or enter a note. +- Explore: View your payment history and view your statics at the dashboard + +### Tips + +- Install the website as a PWA for easy access. +- Get in the habit of recording Payments as they happen for accurate tracking. +- Use categories to understand your spending patterns. + +## Development + +Clone this repository and run the following commands: + +```bash + +## create .env file +cp .env.example .env + +## start the database +docker compose -f docker/finances-dev/docker-compose.yml up -d + +## generate prisma client +npx prisma generate + +## apply database migrations +npx prisma migrate deploy + +## start the development server +npm run dev + +``` + +Then open [http://localhost:3000](http://localhost:3000) with your browser and create an account. +While in development mode, you can generate sample data from the [Account page](http://localhost:3000/account). + +## Deployment + +Copy the [docker-compose.yaml](./docker/finances-prod/docker-compose.yaml) file and +the [.env.example](./docker/finances-prod/.env.example) from 'docker/finances-prod' to your server. + +Rename the `.env.example` file to `.env` and adjust the required environment variables. + +The docker setup expects you to run a Traefik reverse proxy. It will then register itself automatically. +If your setup is different, you will need to adjust the `docker-compose.yaml` file accordingly. + +The finances containers will automatically register themselves to a running watchtower container if it is present. + +Finally run `docker-compose up -d` on your server to start the application. diff --git a/docker/finances-prod/.env.example b/docker/finances-prod/.env.example new file mode 100644 index 0000000..d32102f --- /dev/null +++ b/docker/finances-prod/.env.example @@ -0,0 +1,11 @@ + +# database configuration +DB_USER="db_user" +DB_PASSWORD="db_password" + +# prisma database url +DATABASE_URL="postgresql://$DB_USER:$DB_PASSWORD@postgres:5432/finances?schema=public" + +APPLICATION_DOMAIN="finances.thielker.xyz" +COOKIE_DOMAIN="$APPLICATION_DOMAIN" +ORIGIN="https://$APPLICATION_DOMAIN" From f36a44aacd99577f92aa63f1f25a127c271cca17 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 24 Mar 2024 20:17:28 +0100 Subject: [PATCH 2/4] N-FIN-45: add example watchtower setup --- docker/finances-prod/watchtower_setup.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docker/finances-prod/watchtower_setup.sh diff --git a/docker/finances-prod/watchtower_setup.sh b/docker/finances-prod/watchtower_setup.sh new file mode 100644 index 0000000..b308dd1 --- /dev/null +++ b/docker/finances-prod/watchtower_setup.sh @@ -0,0 +1,13 @@ + +# +# run this container on your server to keep the labeled containers up to date +# +# run 'docker login' to authenticate with your docker hub account +# label your containers with 'com.centurylinklabs.watchtower.enable=true' to enable watchtower +# +docker run -d \ + --name watchtower \ + --restart unless-stopped \ + -v $HOME/.docker/config.json:/config.json \ + -v /var/run/docker.sock:/var/run/docker.sock \ + containrrr/watchtower -s "*/30 * * * * *" --label-enable From 0807c1cbc7360a35197f646eb8675451fa428dcc Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 24 Mar 2024 20:17:42 +0100 Subject: [PATCH 3/4] N-FIN-45: add example traefik setup --- docker/finances-prod/traefik.toml | 13 +++++++++++++ docker/finances-prod/traefik_setup.sh | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 docker/finances-prod/traefik.toml create mode 100644 docker/finances-prod/traefik_setup.sh diff --git a/docker/finances-prod/traefik.toml b/docker/finances-prod/traefik.toml new file mode 100644 index 0000000..3738e71 --- /dev/null +++ b/docker/finances-prod/traefik.toml @@ -0,0 +1,13 @@ +[entryPoints] +[entryPoints.web] +address = ":80" +# [entryPoints.web.http.redirections.entryPoint] +# to = "websecure" +# scheme = "https" + +[entryPoints.websecure] +address = ":443" + +[providers.docker] +watch = true +network = "web" diff --git a/docker/finances-prod/traefik_setup.sh b/docker/finances-prod/traefik_setup.sh new file mode 100644 index 0000000..18a913a --- /dev/null +++ b/docker/finances-prod/traefik_setup.sh @@ -0,0 +1,13 @@ + +# +# run this container on your server to use traefik as a reverse proxy +# +docker run -d \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v $PWD/traefik.toml:/traefik.toml \ + -p 80:80 \ + -p 443:443 \ + --restart unless-stopped \ + --network web \ + --name traefik \ + traefik:v2.10 From 4dd33369d18b4385db57d032e7d72bbf5f1ce11b Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 24 Mar 2024 20:37:55 +0100 Subject: [PATCH 4/4] N-FIN-45: apply environment variable to traefik labels --- docker/finances-prod/docker-compose.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/finances-prod/docker-compose.yaml b/docker/finances-prod/docker-compose.yaml index 3471f5c..7017d47 100644 --- a/docker/finances-prod/docker-compose.yaml +++ b/docker/finances-prod/docker-compose.yaml @@ -25,7 +25,7 @@ services: restart: unless-stopped labels: - "traefik.enable=true" - - "traefik.http.routers.xyz-next-finances.rule=Host(`finances.thielker.xyz`)" + - "traefik.http.routers.xyz-next-finances.rule=Host(`${APPLICATION_DOMAIN}`)" - "traefik.http.routers.xyz-next-finances.entrypoints=web, websecure" - "traefik.http.routers.xyz-next-finances.tls=true" - "traefik.http.routers.xyz-next-finances.tls.certresolver=lets-encrypt" @@ -46,7 +46,7 @@ services: restart: unless-stopped labels: - "traefik.enable=true" - - "traefik.http.routers.xyz-next-finances-studio.rule=Host(`studio.finances.thielker.xyz`)" + - "traefik.http.routers.xyz-next-finances-studio.rule=Host(`studio.${APPLICATION_DOMAIN}`)" - "traefik.http.routers.xyz-next-finances-studio.entrypoints=web, websecure" - "traefik.http.services.xyz-next-finances-studio.loadbalancer.server.port=5555" - "traefik.http.routers.xyz-next-finances-studio.tls=true"