Ritmo
A calm habit tracker for real life.

Ritmo is habit tracking app I designed and built to introduce myself to the world of mobile development via Expo.
I chose to build a habit tracker because I wanted a ritualized daily check-in flow to keep me accountable. I also wanted to easily set flexible parameters for habit duration and check-in frequency, and none of the apps I tried handled this the way I wanted.

To keep things simple, I decided to build this as a client-only application without any supporting API services. Data is stored in a local SQLite database, with a Drizzle ORM interface on top.
export const goal = sqliteTable('goal', {
id: integer('id').primaryKey({ autoIncrement: true }),
name: text('name').notNull(),
recurrence: text('recurrence', {
enum: [GoalRecurrence.daily, GoalRecurrence.weekly, GoalRecurrence.monthly],
}).notNull(),
daysOfWeek: text('days_of_week', { mode: 'json' })
.notNull()
.$type<DayOfWeek[]>()
.default(
sql`json_array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')`,
),
emoji: text('emoji'),
archivedAt: integer('archived_at', { mode: 'timestamp_ms' }),
remindAt: integer('remind_at', { mode: 'timestamp_ms' }),
})
export const checkin = sqliteTable(
'checkin',
{
id: integer('id').primaryKey({ autoIncrement: true }),
goalId: integer('goal_id')
.references(() => goal.id, { onDelete: 'cascade' })
.notNull(),
date: integer('date', { mode: 'timestamp_ms' }).notNull(),
metricEntry: real('metric_entry').notNull().default(0),
sentiment: integer('sentiment')
.notNull()
.default(Sentiment.neutral)
.$type<Sentiment>(),
notes: text('notes')
.notNull()
.$defaultFn(() => ''),
},
(table) => [
unique().on(table.goalId, table.date),
index('checkin_date_idx').on(table.date),
index('checkin_goal_id_idx').on(table.goalId),
],
)
export const goalRelations = relations(goal, ({ many, one }) => ({
checkins: many(checkin),
}))
export const checkinRelations = relations(checkin, ({ one }) => ({
goal: one(goal, {
fields: [checkin.goalId],
references: [goal.id],
}),
})) Being a full stack engineer, I'm used to implementing core logic in remote web services, so I needed to translate my usual bag of tricks to patterns that made sense for a client only world.
One of the main challenges was figuring out how to handle side effects. For example, when someone checks in to a goal, the following things need to happen in the background:
- Start, update, or cancel the goal's current streak
- Update the goal's status in the iOS widget
- Cancel checkin reminder notifications for that goal
I handled this with a custom-built event architecture, where I could define a system-wide event, e.g. checkin-mutated, and register all of its side-effects in a single file. This keeps the code nicely decoupled, and prevents me from needing to dig around to understand logic flow.
export type CheckinMutatedEvent = {
goal: GoalSchema
checkin: CheckinSchema
}
// Event is a class I wrote, whose constructor accepts the following parameters:
// - Event ID: str
// - An array of handlers: (() => Promise<unknown>)[]
export const checkinMutated = new Event<CheckinMutatedEvent>(
'checkin-mutated',
[
(event) =>
GoalStreakUpdateService.recomputeGoalStreaks(
event.goal,
event.checkin.date,
),
() => DailyNotificationService.scheduleNextCheckinNotification(),
() => AppBadgeService.updateAppBadgeCount(),
],
) The handlers run in sequential order when the event is emitted; consumers can opt into parallel execution via Promise.all(). Emitting an event also returns a Promise that we can use to show a loading spinner while we wait:
await checkinMutated.emit({ goal, checkin: createdCheckin }) Ritmo is available for free on the App Store, in English and espaƱol.

