Skip to content

Commit

Permalink
Improve readme and cleanup dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
leomorpho committed Sep 21, 2024
1 parent fa11aa5 commit 0191718
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 1,310 deletions.
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,39 @@ make stripe-webhook # Sets up a webhook for stripe for local testing
make help # Shows all the commands you can run
```

## Starting DB State

To get a look at what tables are available to start off, you can run

```bash
make schema
```

or go to `ent/schema` and see the declared schemas. Note that ent generates a lot of code. Do not remove it from git. In fact, make sure to keep it there.

To create a new schema, do:
```bash
make ent-new name=YourSchemaName
```

Then generate the migrations
```bash
make makemigrations
```

Then generate the ent generated code to interact with your new schema in Go:
```bash
make ent-gen
```

To apply the migrations, either run `make migrate` or do a `make reset` to start from scratch (often times easier, and your test DB should be treated as disposable).

## Add a route

Create a new file in `routes/` and add your route. A route is a standard Echo handler with some added goodies. Once you've added handlers for your route, you can hook it up to the router in `routes/routes.go`, where the route should be registered to be reachable from the web.


## Realtime
## Realtime and Notifications

There is a `realtime` route that is setup to handle SSE connections to any client desiring real-time data. Realtime data is sent in "notifications" which are just custom events with a notification type, some data, and a profile id. The `NotifierRepo` handles subscribing the client to the right channels and pushing new notifications to the client. Notifications can be stored in the DB in case the client is offline and needs to be picked up later when they reconnect - these will be shown in the notification center UI.

Expand All @@ -200,6 +226,19 @@ Methods for interacting with notifications:
- `DeleteNotification` to delete a notification.
- `GetNotifications` to get all notifications for a user.

Note that actual storage of notifications in the DB is handled by `NotificationStorageRepo`.

## Notification Permissions

The `NotificationSendPermissionRepo` handles the permission logic for sending notifications to a user. It is used to determine if a user has granted permission to send notifications to them and lives at `pkg/repos/notifierrepo/permissions.go`.
You can mostly leave this alone, but if you need to add a new permission platform (e.g. a new push notification service), you may need to add a new permission here.

## Planned Notifications

The `PlannedNotificationsRepo` handles the logic for sending notifications at a planned time and lives at `pkg/repos/notifierrepo/planned_notifications.go`. The repo does not send any notifications, but rather sets up the DB storage for scheduled notifications. It also contains a method to clean up old notifications. But both the sending and deletion methods need to be called as tasks. Two examples are the `TypeAllDailyConvoNotifications` and `TypeEmailUpdates` tasks, as well as the `TypeDeleteStaleNotifications` task, which are commented out in the `cmd/web/main.go` file.

The algorithm used to determine best time to send notifications is very primitive. Feel free to improve it! (or I will eventually, though it's low priority)

## PWA Notifications

There are 2 push notification repos for different use cases:
Expand All @@ -211,6 +250,72 @@ Both have similar interfaces:
- `SendPushNotifications`: to send a push notification to a user. This is generally handled by the `NotifierRepo` after storing a notification in the DB using the `PublishNotification` method.
- `DeletePushSubscriptionByEndpoint`: to delete a push subscription by endpoint.

## Profile Repo

The `ProfileRepo` handles all the profile logic and lives at `pkg/repos/profilerepo/profilerepo.go`. It contains basic CRUD methods for profiles, as well as some helper methods for getting friends, updating profile info, etc.

There is extensive "friendship" logic in the repo, which is currently not used in the app. It is left over from [Chérie](https://cherie.chatbond.app/) as a demo. Feel free to delete these methods if you don't need them!

- `GetFriends`: to get all friends for a profile. This is a demo as there is no friends feature in the app.
- `AreProfilesFriends`: to check if two profiles are friends. This is a demo as there is no friends feature in the app.
- `LinkProfilesAsFriends`: to link two profiles as friends. This is a demo as there is no friends feature in the app.
- `UnlinkProfilesAsFriends`: to unlink two profiles as friends. This is a demo as there is no friends feature in the app.
- `GetProfileByID`: to get a profile by ID.
- `GetCountOfUnseenNotifications`: to get the count of unseen notifications for a profile.
- `GetPhotosByProfileByID`: to get the photos for a profile by ID.
- `GetProfilePhotoThumbnailURL`: to get the thumbnail URL for a profile's photo by ID.
- `SetProfilePhoto`: to set the profile photo for a profile by ID.
- `UploadPhoto`: to upload a photo for a profile by ID.
- `UploadImageSizes`: to upload image sizes for a photo by ID.
- `DeletePhoto`: to delete a photo by ID.
- `DeleteUserData`: to delete a user's data by ID. This should be updated to delete all new models that may not cascade delete and is used in the settings to delete a user's data and account.
- `IsProfileFullyOnboarded`: to check if a profile is fully onboarded. This is used in the onboarding flow to check if the profile has completed the onboarding process. Edit as needed. On startup, a non-onboarded profile is redirected to the onboarding page.

Note that a method `EntProfileToDomainObject` is used to convert the ent profile object to a domain profile object, which is a more generic object that is used throughout the app. Generally, domain objects are preferred over ent objects as they are more generic and are not tied to a specific ORM.


## File Uploads

The `StorageClient` handles all the file storage logic and lives at `pkg/repos/storage/storagerepo.go`. It uses minio under the hood to handle the file uploads with AWS S3 API, which means you can easily swap out the storage backend to any S3-compatible service.

The following methods are available:
- `CreateBucket`: to create a new bucket.
- `UploadFile`: to upload a new file.
- `DeleteFile`: to delete a file.
- `GetPresignedURL`: to get a presigned URL for a file.
- `GetImageObjectFromFile`: to get an image object from a file.
- `GetImageObjectsFromFiles`: to get image objects from a list of files.

## Paid/Free Subscriptions

The `SubscriptionsRepo` handles the subscription logic and lives at `pkg/repos/subscriptions/subscriptions.go`. It uses Stripe under the hood to handle the subscription logic. If you'd like to see the stripe webhooks, they live at `pkg/routes/payments.go`.

**Note:** currently, the only type of subscription implemented is a monthly subscription that is either paid or free. Feel free to expand on this!

The following methods are available:
- `CreateSubscription`: to create a new subscription.
- `DeactivateExpiredSubscriptions`: to deactivate all expired monthly subscriptions.
- `UpdateToPaidPro`: to update a subscription to the pro plan.
- `UpdateToFree`: to update a subscription to the free plan.
- `GetCurrentlyActiveProduct`: to get the currently active product for a profile.
- `CancelWithGracePeriod`: to cancel a subscription with a grace period.
- `CancelOrRenew`: to cancel a subscription or renew it.


## Regenerate Logo Image Assets

There is a python script in `scripts/regen_logo_images.py` that should be run when the logo in `static/logo.png` is updated.
This will regenerate the logo assets for different app icons and the favicon. It will also regenerate the correct iOS and Android app icons and place them in the `static/ios-wrapper/` and `static/android-wrapper/` directories. Note that for iOS it will remove alpha transparency and make the background black (as apple requires).

```bash
cd scripts
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

python3 scripts/regen_logo_images.py
```

## Deployment

First, make sure all your env vars in the Kamal file `deploy.yml` are correct. All your vars should be set either in:
Expand Down
38 changes: 2 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ require (
github.com/aws/aws-sdk-go-v2 v1.18.1
github.com/aws/aws-sdk-go-v2/config v1.18.27
github.com/aws/aws-sdk-go-v2/service/sns v1.20.13
github.com/casbin/casbin-pg-adapter v1.4.0
github.com/casbin/casbin/v2 v2.82.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckarep/golang-set/v2 v2.6.0
github.com/disintegration/imaging v1.6.2
github.com/eko/gocache/v2 v2.3.1
Expand All @@ -36,12 +33,12 @@ require (
github.com/labstack/echo-contrib v0.15.0
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/mattn/go-sqlite3 v1.14.23
github.com/mileusna/useragent v1.3.4
github.com/minio/minio-go/v7 v7.0.67
github.com/nats-io/nats.go v1.33.1
github.com/nyaruka/phonenumbers v1.3.4
github.com/orsinium-labs/enum v1.3.0
github.com/pgvector/pgvector-go v0.2.1
github.com/resend/resend-go/v2 v2.5.0
github.com/rs/zerolog v1.29.1
github.com/samber/slog-echo v1.12.1
Expand All @@ -50,8 +47,6 @@ require (
github.com/stripe/stripe-go/v78 v78.6.0
github.com/testcontainers/testcontainers-go v0.29.1
github.com/testcontainers/testcontainers-go/modules/postgres v0.29.1
github.com/weaviate/weaviate v1.24.3
github.com/weaviate/weaviate-go-client/v4 v4.13.1
github.com/ziflex/lecho/v3 v3.5.0
golang.org/x/crypto v0.26.0
google.golang.org/api v0.183.0
Expand All @@ -73,13 +68,10 @@ require (
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.26 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.34 // indirect
Expand All @@ -92,12 +84,12 @@ require (
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect
github.com/casbin/govaluate v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
Expand All @@ -110,18 +102,7 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/loads v0.21.1 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.21.0 // indirect
github.com/go-pg/pg/v10 v10.12.0 // indirect
github.com/go-pg/zerochecker v0.2.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -147,27 +128,21 @@ require (
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.23 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mmcloughlin/meow v0.0.0-20181112033425-871e50784daf // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
Expand All @@ -177,7 +152,6 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pegasus-kv/thrift v0.13.0 // indirect
Expand Down Expand Up @@ -205,20 +179,13 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/bufpool v0.1.11 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
Expand Down Expand Up @@ -248,5 +215,4 @@ require (
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apimachinery v0.26.2 // indirect
mellium.im/sasl v0.3.1 // indirect
)
Loading

0 comments on commit 0191718

Please sign in to comment.