Skip to content

gerardorodriguezdev/kmp-fullstack-complex-experiments

Repository files navigation

Home automation project

Production ready home automation project that handles the following:

  1. Arduino device sends BLE event to a Raspberry Pi
  2. Client Jvm app running in the Raspberry Pi receives the event and sends it to the server
  3. The Ktor Jvm server receives the event and stores it in a redis/postgres database for the specific user
  4. The client app (Android/iOS/Browser) retrieves the devices and events from the server for the specific user

Pieces

  • Server (Ktor Jvm servers)
    • App service
    • Mock service (a mock of the app service)
  • Client
    • User app
      • Android target
      • iOS target
      • Browser target (Wasm)
    • Home app
      • Raspberry Pi target (Jvm)

Features

Server:

  • Ktor Jvm
  • Postgres
  • Redis
  • JWT for fast authentication but its contents are encrypted
  • Secure sessions for browser authentication
  • Bearer token for native devices authentication
  • Locally runnable with in-memory data sources
  • Simple Java Email sender
  • Password authentication
  • User pre-authentication
  • JWT blacklisting
  • Wasm application served by Ktor automatically with security best practices
  • Multi-client authentication with the same flow
  • Safe-validated models from creation to use from server to client and vice versa
  • Code reused between all targets as much as possible

User client

  • Android/iOS/Browser targets
  • Kotlin inject
  • Session scoped dependencies
  • Locally testable with locally running servers (mock/production)
  • Encrypted shared preferences

Home client

  • Raspberry Pi target (Jvm)
  • User authentication from the command line
  • Bluetooth communication through Kable
  • Manual setup of Jib for docker image creation
  • Able to run locally with real/mock bluetooth devices

Gradle plugins

  • Standardized plugins for libraries and apps
  • Docker image configuration
  • Docker compose configuration
  • Postgres configuration
  • Redis configuration
  • Fake server for the browser client
  • Easy Wasm distribution serving for server
  • Wasm configuration with compression, HTML generation, deliverables with hashes for caching

CI

  • Creation of environments
  • Creation and publishing of docker images
  • Creation and uploading of APK
  • Creation and uploading of IPA

How to run?

The project is thought to be able to be run locally and mock certain pieces if required

To select which environment to run, it uses Chamaleon so select the environment and use the IntelliJ run configurations available

Important run configurations

Server

  • runAll: Runs the server using docker compose (and redis/postgres if needed automatically)
  • runJvm: Runs the server with the JVM (requires using the Chamaleon in-memory environment)

User Client

  • runAndroid: Runs the android client
  • runIos: Runs the iOS client
  • runWasm: Runs the wasm client

Home Client

  • runAll: Runs the client using docker
  • runJvm: Runs the client with the Jvm

Environments

Server

  • localMemoryDataSources: Uses in-memory data sources
  • localRealDataSources: Uses real data sources (postgres and redis)
  • localRemoteTemplate: Template with almost the same configuration as production except still using non-secure http

User Client

  • local: Connects to a local non-secure http server so you can use the mock server if required
  • debugRemoteTemplate: Template to test with a remote server (can be staging/production)

Home Client

  • local: Connects to a local non-secure http server so you can use the mock server if required
  • localFakeDevicesController: Uses a fake devices controller that returns events from a device as if you were connected to a bluetooth device so you can test without a real device
  • debugRemoteTemplate: Template to test with a remote server (can be staging/production)

Deployment considerations

Your hosting service should handle:

  • Rate limiting
  • SSL certificates
  • Load balancing
  • Https redirect
  • Postgres security, backups and updates
  • Redis security and updates

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages