How appmobiliza/platform works
1. Repository shape
- This is a Turborepo-style monorepo with three runtime apps and several shared packages.
- The architecture is intentionally split so that UI apps stay thin and most cross-cutting logic lives in shared packages.
2. Primary client surfaces
- apps/mobile is the field/operator app built with Expo + React Native.
- apps/web is the admin/operations dashboard built with Next.js.
- Both clients consume the same backend and shared contract types, so they present different UIs over a common business model.
3. Backend boundary
- apps/api is the central HTTP service, using Hono, tRPC, and Better Auth.
- It exposes feature routers for profiles, requests, locations, favorites, metrics, notifications, settings, and shift logs.
- This service is the main orchestration layer between the clients, the database, auth, and realtime integrations.
4. Shared API contract layer
- packages/contracts holds the request/response shapes, enums, and Zod schemas shared by all apps.
- This package is the main type-safety boundary: clients and backend agree on the same domain vocabulary here.
- It reduces drift between the mobile app, dashboard, and API router payloads.
5. Business logic layer
- packages/domain contains the core domain rules and use cases, such as request creation, request timeouts, scholar history, favorites, and metric export.
- The API routes should be understood as transport adapters around this layer rather than the place where business rules live.
- For an architecture diagram, this is the key “application logic” tier between API transport and persistence.
6. Persistence layer
- packages/db owns PostgreSQL access via Drizzle ORM, schema definitions, and migrations.
- The schema is organized by domain areas like auth, profiles, requests, settings, locations, and extras.
- packages/seed provides controlled data generation for local/dev datasets and likely supports test or bootstrap flows.
7. Authentication boundary
- packages/auth centralizes Better Auth integration for client, server, and proxy use cases.
- apps/web and apps/mobile both rely on this shared auth layer rather than implementing separate auth stacks.
- The API also depends on it, so auth is a cross-application concern rather than a per-app feature.
8. Realtime and presence
- packages/realtime abstracts multiple realtime providers through client/server adapters.
- It supports provider-specific implementations such as Ably, Pusher, Supabase, WebSocket, and mock adapters.
- This package sits alongside the API and clients to handle live updates like position, attendance, or request status changes.
9. Environment and configuration
- packages/env is the single source of truth for environment variable validation and access.
- The repo avoids direct process.env access from apps/packages and routes all config through this package.
- This is an important deployment boundary because it normalizes local, staging, and hosted environments.
10. Mobile app structure
- The mobile app is organized around route-driven screens, feature hooks, local stores, and reusable UI primitives.
- Its key flows include authentication, onboarding, profile setup, request creation, travel/navigation, history, and scholar/student-specific views.
- It also contains map and location logic, route calculation helpers, and realtime position broadcasting, which suggests the mobile app is responsible for live field operations.
11. Web dashboard structure
- The web app is organized as an admin dashboard with pages for atendimento, bolsistas, estudantes, relatórios, and configuration.
- It uses shared UI building blocks, detail sidebars, date filters, charts, and dashboard-specific stores/components.
- The dashboard is the primary operational console for managing users, locations, shifts, and reporting rather than performing field tasks.
12. Data flow across the system
- The common flow is: mobile/web client -> API router -> domain use case -> database and/or realtime integration -> response back through shared contracts.
- Some client features also interact with external services directly, such as location/routing helpers and realtime transport abstractions.
- Because contracts, auth, and env are shared, the system’s main architectural constraint is consistency across all three app surfaces.
13. Tooling and repo-wide boundaries
- TypeScript is the lingua franca across the monorepo, with shared config presets under config/typescript.
- Biome handles formatting/linting, and Turbo coordinates builds and checks across packages.
- Tests are present at multiple layers, including API router/security tests, mobile component tests, and realtime adapter tests, showing a strong emphasis on contract and behavior verification.
14. How to draw it
- A clean diagram would place apps/mobile and apps/web as separate clients at the top, both pointing to apps/api.
- Under the API, show packages/auth, packages/contracts, packages/domain, packages/db, packages/realtime, and packages/env as shared dependencies.
- Put PostgreSQL/Neon beneath packages/db, and external realtime providers beneath packages/realtime.
Main entry points: api API service · mobile Mobile app · web Web app · realtime Realtime
Components 22
Apps
Primary runtime surfaces for mobile users, web operators, and API traffic.
- Mobile app · Field/operator React Native app for onboarding, requests, travel, and live position updates.
apps/mobile - Web app · Admin and operations console for managing users, shifts, locations, and reports.
apps/web - API service · Central HTTP service that orchestrates feature routers, auth, persistence, and realtime.
apps/api - Mobile routes · Route-driven screens for auth, onboarding, profile setup, request creation, history, and travel.
apps/mobile/src/app - Mobile state · Client state, realtime hooks, map logic, auth session, and request orchestration.
apps/mobile/src/lib - Mobile UI · Reusable UI primitives and flow components for scholar-facing experiences.
apps/mobile/src/components - Web pages · Admin pages for atendimentos, bolsistas, estudantes, relatórios, and configuration.
apps/web/app - Web UI · Sidebar, detail panels, charts, settings controls, and reusable dashboard widgets.
apps/web/components - Web data · Dashboard auth, cached data, tRPC server helpers, and derived reporting data.
apps/web/lib - Feature routers · Profile, request, location, favorite, metrics, notification, settings, and shift-log endpoints.
apps/api/src/routers - API tests · Behavioral and security coverage for routers, validation, auth, RBAC, and PII handling.
apps/api/src/__tests__
Shared packages
Cross-cutting domain, auth, data, realtime, and environment logic used by all apps.
- Contracts · Shared request/response shapes, enums, and Zod schemas that define the domain vocabulary.
packages/contracts - Domain logic · Core business rules for request creation, timeouts, scholar history, favorites, and metric export.
packages/domain - Database · PostgreSQL access layer with schema definitions, migrations, and database client helpers.
packages/db - Auth · Shared authentication integration for client, server, and proxy usage.
packages/auth - Realtime · Abstraction over live-update providers for client and server transports.
packages/realtime - Env · Single source of truth for validated environment variables and runtime config.
packages/env - tRPC core · Shared tRPC context and error helpers supporting the API boundary.
packages/trpc - Seed data · Controlled generators for local development and bootstrap datasets.
packages/seed - Adapters · Client/server implementations for Ably, Pusher, Supabase, WebSocket, and mock modes.
packages/realtime/src/adapters - Schema · Domain-oriented schema modules for auth, profiles, requests, settings, locations, and extras.
packages/db/src/schema - Models · Feature-specific contract modules plus shared enums and validation helpers.
packages/contracts/src
Connections 36
- Mobile app → Mobile routes: renders · The mobile app hosts its route-driven screens here.
- Mobile app → Mobile UI: uses · Screens compose shared mobile UI primitives and flow components.
- Mobile app → Mobile state: depends on · Mobile UI relies on local stores, hooks, auth, map, and realtime helpers.
- Web app → Web pages: renders · The dashboard is organized as Next.js pages and layouts.
- Web app → Web UI: uses · Pages build on shared dashboard components and controls.
- Web app → Web data: depends on · Web pages rely on auth helpers, tRPC server access, and derived dashboard data.
- Mobile state → Auth: auth · Mobile uses the shared auth client and session flow.
- Web data → Auth: auth · Web uses shared client/server auth integrations.
- Mobile state → Env: config · Mobile reads validated runtime configuration through the shared env layer.
- Web data → Env: config · Web runtime configuration is centralized in the env package.
- API service → Auth: auth · The API delegates authentication concerns to the shared Better Auth layer.
- API service → Env: config · The API consumes validated environment settings from the shared env layer.
- API service → tRPC core: rpc core · The API uses shared tRPC context and error helpers.
- API service → Contracts: contracts · Routers and clients share request/response types and validation schemas.
- API service → Domain logic: business logic · Transport adapters call into domain use cases instead of embedding rules.
- API service → Database: persistence · The API reads and writes through the shared database layer.
- API service → Realtime: live updates · The API emits or coordinates realtime events through shared adapters.
- API service → Feature routers: exposes · Feature routers implement the public API surface.
- Feature routers → Contracts: validates · Routers use shared schemas and enums for payload shape agreement.
- Feature routers → Domain logic: calls · Feature endpoints invoke request, favorite, metrics, and history use cases.
- Feature routers → Database: queries · Routers persist and fetch through the schema-backed database layer.
- Feature routers → Realtime: notifies · Selected flows publish live status and presence changes.
- Domain logic → Database: reads/writes · Domain use cases depend on persisted state and domain tables.
- Domain logic → Contracts: domain types · Use cases align with shared enums and validated shapes.
- Database → Schema: defines · The database package organizes tables and enums by domain area.
- Realtime → Adapters: implements · Client and server adapters provide provider-specific transport implementations.
- Realtime → Env: provider config · Realtime provider selection and credentials are driven by env values.
- Models → Contracts: provides · Feature schemas and enums form the shared business vocabulary.
- Schema → Database: backs · Schema modules back the persisted domain model.
- Seed data → Database: populates · Seed generators create controlled datasets for local and bootstrap use.
- Mobile app → API service: calls · Mobile interacts with the backend for requests, profiles, history, and live state.
- Web app → API service: calls · Web dashboard consumes the backend for operational management and reporting.
- Mobile app → Contracts: types · Mobile aligns UI and service calls with shared contract definitions.
- Web app → Contracts: types · Web aligns dashboard payloads with the same shared contracts.
- Mobile app → Realtime: subscribes · Mobile listens to live position and request status updates.
- Web app → Realtime: subscribes · Dashboard views can reflect live operational changes.