Skip to content

uchilaka/cami

Repository files navigation

Customer Accounts Management & Invoicing MVP

Ruby Version

  • 3.2.2

Service/Vendor dependencies

  • Ngrok for local development tunneling

System Dependencies

System dependencies are defined in the following configuration files:

  • .tool-versions (see .tool-versions.example)
  • Gemfile
  • Brewfile
  • package.json
    • yarn.lock

Configuration

Development service ports

Service Port
Rails 16006
Redis 16079
Postgres (app store) 16032
MongoDB (invoicing score) 16017

Running the app for the first time

1. Setup the environment

If you use asdf, you will also need to setup the following plugins and install their corresponding versions with the asdf install command:

Review the .env.example file to ensure the environment variables are set. You can control which variables are made available in each environment while working locally using the following files:

  • .env.local
  • .env.test

The .envrc (see .envrc.example) file should be included for compatibility with other features like docker compose and simply sources the .env.local file.

1. Install dependencies

# Install system dependencies
brew bundle
# Setup the ASDF dependencies file
cp -v .tool-versions.example .tool-versions
# Install Ruby dependencies
bundle install
# Install Node dependencies
yarn install

2. Setup your application secrets

Search for development.yml.enc to locate the entry in the KeePass store with the application's encrypted secrets files.

Run the following code to update the application for the corresponding environments. You will need to do this before running the test suite.

# Help menu for the secrets command
bin/thor help lx-cli:secrets:edit
# Edit the secrets file (for the development environment)
bin/thor lx-cli:secrets:edit --environment development

3. Start up the application's services

bin/start-docker

4. Initialize the database

# Get help with the DB setup command
bin/thor help lx-cli:db:setup
# Initialize the app store database
bin/thor lx-cli:db:setup --postgres
# Initialize the invoicing score database
bin/thor lx-cli:db:setup --mongodb

5. Start up the app

You can also start up the app's non-dockerized services with the included IDE configurations for RubyMine in the .ide-configs folder.

This is the same command you'll need any time you want to start up the application:

bin/dev

Database management

Review the list of available rake tasks for managing the MongoDB database:

bundle exec rake -T | grep mongoid

# Sample output
rake db:mongoid:create_collections             # Create collections for Mongoid models
rake db:mongoid:create_collections:force       # Drop and create collections for Mongoid models
rake db:mongoid:create_indexes                 # Create indexes specified in Mongoid models
rake db:mongoid:drop                           # Drop the database of the default Mongoid client
rake db:mongoid:purge                          # Drop all non-system collections
rake db:mongoid:remove_indexes                 # Remove indexes specified in Mongoid models
rake db:mongoid:remove_undefined_indexes       # Remove indexes that exist in the database but are not specified in Mongoid models
rake db:mongoid:shard_collections              # Shard collections with shard keys specified in Mongoid models

Setting up the document store in the test environment

This guide is intended as a temporary solution until we can come up with something better for bringing up the document store with the right set of permissions the first time the application setup is run.

# Show help menu for mongosh
docker exec -it mongodb.accounts.larcity mongosh --help

# Run the command to initialize the database
docker exec -it mongodb.accounts.larcity mongosh \
  --authenticationDatabase admin
  --file ./development/mongodb/docker-entrypoint-initdb.d/init-doc-stores
  --username <MONGO_INITDB_ROOT_USERNAME>
  --password <MONGO_INITDB_ROOT_PASSWORD>

# Run the command to connect the mongodb container
bin/thor lx-cli:db:connect --mongodb

Once connected to the database instance, run the following commands to setup test credentials:

// List databases
show dbs

// Use the admin database
use admin

// Create a new user
db.createUser({
  user: "db_admin",
  pwd: `${process.env.MONGO_INITDB_ROOT_PASSWORD}`,
  roles: [
    { role: "dbOwner", db: "doc_store_development" },
    { role: "dbOwner", db: "doc_store_test" },
  ]
})

use doc_store_test

// Create a new user (for testing purposes)
db.createUser({
  user: "db_admin",
  pwd: passwordPrompt(),
  roles: [
    { role: "dbOwner", db: "doc_store_test" }
  ]
})

use doc_store_development

// Create a new user (for development purposes)
db.createUser({
  user: "db_admin",
  pwd: passwordPrompt(),
  roles: [
    { role: "dbOwner", db: "doc_store_development" }
  ]
})

// Example: Grant roles to an existing user
db.grantRolesToUser("db_admin", ["dbOwner"])

How to run the test suite

TODO: Add test suite instructions

Services (job queues, cache servers, search engines, etc.)

TODO: Add services

Deployment instructions

TODO: Add deployment instructions

Development

Managing application secrets

To edit credentials in your IDE, run the following command in your console:

bin/thor lx-cli:secrets:edit

To view help information about managing application credentials, run the following command in your console:

bin/rails credentials:help

To edit the credentials file for your development environment using the rails credentials scripts and your command line, run the following code in your console:

EDITOR=nano bin/rails credentials:edit --environment ${RAILS_ENV:-development}

Using NGROK

Follow these steps to setup ngrok for your local environment:

  • Ensure you have updated your .envrc file with the NGROK_AUTH_TOKEN. You can get this from KeePass

  • Run the following script to export the token to your local ngrok.yml config file:

    ngrok config add-authtoken ${NGROK_AUTH_TOKEN}

Then you can open a tunnel to your local environment by running:

thor lx-cli:tunnel:open_all

Generating a Monogid Model

rails g model Invoice --orm=mongoid

After generating the model, if you would like to inherit application functionality for document records, you can include the DocumentRecord concern in the model:

class Invoice
  include DocumentRecord
end

Print key file

bin/thor help lx-cli:secrets:print_key

FAQs

RubyMine

How do I disable these "Missing type signature" errors?

Go to Settngs | Editor | Inspections | Ruby | RBS and uncheck Missing type signature

Integration Partners

PayPal

Guides and References

Future Work

  • Review Yahoo + Google updated email sender requirements and make any needed changes to the Brevo configs
  • Implement forbidden rescue page (or just set a flash message and redirect to the root path)
  • "Continue with Google" quick link in the profile dropdown
  • Fix web concurrency support (issues here might be related to log streaming). Here's the error message: objc[97397]: +[NSCharacterSet initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug
  • AASM for account status
  • Setup and update production credentials in the config/credentials/production.yml.enc file
  • Implement :confirmable to secure accounts when switching/adding auth providers
  • Implement magic links
  • Implement Omniauth via apple
  • Implement FontAwesome library for SVG icons
  • Secure accounts with MFA
  • Setup secrets using docker images' compatibility with secret files
  • Vite CJS API is deprecated and will be removed in v6. Update the vite.config.js file to use the ESM build instead
  • New ESLint configuration system is available. You will need to create a new eslint.config.js file to use the new configuration system
  • Setup RSwag for baller request specs & API tools
  • Setup flipper for feature flags
  • Knapsack Pro for parallelizing tests
  • Check out Redis Stack for docker for advanced indexing & search features with redis data
  • Playwright E2E test suite
  • Implement default authorization policies
  • Consolidate vite configuration & dependencies right now, vite is a dependency of both the front and backend separately. Is there a better way?