# remodik/lentik architecture

> Architecture diagram of the GitHub repository remodik/lentik, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/remodik/lentik
- Repository: https://github.com/remodik/lentik

## Overview

1. **Repo shape**
   - This is a three-part product: a **FastAPI backend** in `services/api`, a **Next.js web app** in `services/web`, and a **React Native mobile app** in `mobile`.
   - `infra/docker-compose.yml` ties the deployable services together for local/runtime orchestration, with PostgreSQL as the main shared datastore.

2. **Backend is the system of record**
   - The API service is a **single FastAPI monolith** organized by domain routers rather than microservices.
   - `app/main.py` is the entry point; `routers/` exposes feature APIs, `models/` defines persistence entities, `schemas/` defines request/response contracts, and `services/` holds cross-cutting business workflows.

3. **Core data store and schema management**
   - Persistent application state lives in **PostgreSQL 16**.
   - Schema evolution is managed with **Alembic migrations** under `services/api/alembic/versions`, showing a long-lived relational model that has evolved through chat, media, calendar, budgeting, roles, audit, and family-tree features.

4. **Authentication and session boundary**
   - Auth is not just email/password: the README and code structure indicate **login + PIN**, JWT issuance, and persistent sessions.
   - Security concerns are separated into `core/security.py`, `core/jwt.py`, `core/sessions.py`, `core/rate_limit.py`, and auth dependencies in `auth/deps.py`.
   - This makes authentication, session validation, and authorization distinct concerns before domain logic runs.

5. **Authorization and family-scoped access**
   - The app is built around **families** as the main tenant boundary.
   - Permissions are richer than a simple member/admin split: there are **roles**, **permission overrides**, and related services for role management.
   - The presence of family join, invites, and member/role routers suggests most API access is gated by family membership plus per-resource permissions.

6. **Realtime communication layer**
   - Chat is a major subsystem with **realtime messaging**, read receipts, reactions, mentions, attachments, pinned messages, and channel settings.
   - Realtime delivery is handled separately via `app/ws/manager.py`, while `ws_tickets.py` in core suggests short-lived WebSocket authorization tickets.
   - Presence is part of the backend data model, so online status is treated as shared server state rather than only client UI state.

7. **Shared media and file pipeline**
   - Uploads are a first-class backend concern: there is a dedicated `uploads` router and `core/uploads.py`.
   - `UPLOAD_DIR` in the root README indicates file storage is **filesystem-based** rather than an external object store.
   - Gallery items, chat attachments, and media metadata are modeled separately, so the architecture distinguishes between file blobs and application records about those files.

8. **Business domains beyond chat**
   - The backend is a broad family hub, not just a messenger.
   - Feature domains include **calendar events and reminders**, **budget/expenses/transactions**, **notes**, **family tree layout**, **audit logging**, and **membership/invite flows**.
   - `services/` contains workflows like reminders dispatching, calendar reminder generation, invite handling, and audit recording, implying these are coordinated server-side processes rather than purely client-driven screens.

9. **Web frontend architecture**
   - The web app is a **Next.js 15** application using the App Router structure in `src/app/`.
   - UI is composed from feature components under `src/components/`, with supporting hooks and API wrappers in `src/lib/`.
   - The web client includes a **notification system**, **theme provider/selector**, **mobile navigation**, and a **service worker** in `public/sw.js`, so it behaves like a responsive app with PWA-style capabilities.

10. **Mobile frontend architecture**
   - The mobile app is a separate **React Native** client with its own navigation, screens, contexts, and component set.
   - `AuthContext` and `FamilyContext` indicate shared global state for login/session and current-family selection.
   - Feature API modules under `mobile/src/api/` mirror the backend domains, showing the mobile app is a thin client over the same backend contract.

11. **Client-to-server data flow**
   - Both web and mobile clients talk to the FastAPI backend through HTTP APIs, using feature-specific API wrappers rather than direct server coupling.
   - Chat and presence additionally rely on the backend’s WebSocket path for low-latency updates.
   - The backend then persists state in PostgreSQL and, for uploads, stores file content on disk while keeping metadata in the database.

12. **Operational boundary**
   - `infra/docker-compose.yml` is the primary local integration boundary, assembling the backend, frontend, and database with environment-based configuration.
   - The repository is structured so that deployment concerns stay mostly outside the feature code: app logic lives in `services/api`, `services/web`, and `mobile`, while infra handles composition and runtime wiring.

Main entry points: [`services/api/app/routers`](https://github.com/remodik/lentik/tree/master/services/api/app/routers) (Routers), [`infra/docker-compose.yml`](https://github.com/remodik/lentik/blob/master/infra/docker-compose.yml) (Compose), [`services/api/app/main.py`](https://github.com/remodik/lentik/blob/master/services/api/app/main.py) (API entry), [`services/api/app/ws/manager.py`](https://github.com/remodik/lentik/blob/master/services/api/app/ws/manager.py) (WS manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_infra["Infra"]
  node_compose["Compose<br/>orchestration<br/>[docker-compose.yml]"]
  node_db[("Postgres<br/>relational store")]
end

subgraph group_api["Backend"]
  node_api_main["API entry<br/>FastAPI app<br/>[main.py]"]
  node_api_auth["Auth core<br/>security"]
  node_api_deps["Auth deps<br/>request gating<br/>[deps.py]"]
  node_api_routers["Routers<br/>domain API"]
  node_api_services["Workflows<br/>business services"]
  node_api_models[("Models<br/>ORM entities")]
  node_api_schemas["Schemas<br/>contracts"]
  node_api_ws["WS manager<br/>realtime<br/>[manager.py]"]
  node_api_migrations["Migrations<br/>schema history"]
end

subgraph group_web["Web app"]
  node_web_app["Next app<br/>Next.js app"]
  node_web_ui["Web UI<br/>client components"]
  node_web_lib["Web lib<br/>client services"]
  node_web_sw["Service worker<br/>pwa runtime<br/>[sw.js]"]
end

subgraph group_mobile["Mobile app"]
  node_mobile_nav["Mobile nav<br/>React Native app<br/>[RootNavigator.js]"]
  node_mobile_state["App state<br/>contexts"]
  node_mobile_api["Mobile API<br/>client wrappers"]
  node_mobile_screens["Screens<br/>feature views"]
end

node_compose -->|"runs"| node_api_main
node_compose -->|"provisions"| node_db
node_compose -->|"runs"| node_web_app
node_compose -.->|"supports"| node_mobile_nav
node_api_main -->|"uses"| node_api_auth
node_api_main -->|"protects"| node_api_deps
node_api_main -->|"mounts"| node_api_routers
node_api_routers -->|"orchestrates"| node_api_services
node_api_routers -->|"persists"| node_api_models
node_api_routers -->|"validates"| node_api_schemas
node_api_services -->|"reads/writes"| node_api_models
node_api_services -.->|"checks"| node_api_auth
node_api_ws -->|"authorizes"| node_api_auth
node_api_models -->|"stored in"| node_db
node_api_migrations -->|"evolves"| node_db
node_api_ws -->|"streams"| node_api_models
node_web_app -->|"composes"| node_web_ui
node_web_app -->|"calls"| node_web_lib
node_web_ui -->|"depends on"| node_web_lib
node_web_ui -.->|"enhanced by"| node_web_sw
node_mobile_nav -->|"shares state"| node_mobile_state
node_mobile_nav -->|"renders"| node_mobile_screens
node_mobile_screens -->|"calls"| node_mobile_api
node_mobile_api -->|"talks to"| node_api_routers
node_web_lib -->|"talks to"| node_api_routers
node_web_lib -->|"subscribes"| node_api_ws
node_mobile_api -->|"subscribes"| node_api_ws

click node_compose "https://github.com/remodik/lentik/blob/master/infra/docker-compose.yml"
click node_api_main "https://github.com/remodik/lentik/blob/master/services/api/app/main.py"
click node_api_auth "https://github.com/remodik/lentik/tree/master/services/api/app/core"
click node_api_deps "https://github.com/remodik/lentik/blob/master/services/api/app/auth/deps.py"
click node_api_routers "https://github.com/remodik/lentik/tree/master/services/api/app/routers"
click node_api_services "https://github.com/remodik/lentik/tree/master/services/api/app/services"
click node_api_models "https://github.com/remodik/lentik/tree/master/services/api/app/models"
click node_api_schemas "https://github.com/remodik/lentik/tree/master/services/api/app/schemas"
click node_api_ws "https://github.com/remodik/lentik/blob/master/services/api/app/ws/manager.py"
click node_api_migrations "https://github.com/remodik/lentik/tree/master/services/api/alembic/versions"
click node_web_app "https://github.com/remodik/lentik/tree/master/services/web/src/app"
click node_web_ui "https://github.com/remodik/lentik/tree/master/services/web/src/components"
click node_web_lib "https://github.com/remodik/lentik/tree/master/services/web/src/lib"
click node_web_sw "https://github.com/remodik/lentik/blob/master/services/web/public/sw.js"
click node_mobile_nav "https://github.com/remodik/lentik/blob/master/mobile/src/navigation/RootNavigator.js"
click node_mobile_state "https://github.com/remodik/lentik/tree/master/mobile/src/context"
click node_mobile_api "https://github.com/remodik/lentik/tree/master/mobile/src/api"
click node_mobile_screens "https://github.com/remodik/lentik/tree/master/mobile/src/screens"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_compose,node_db toneBlue
class node_api_main,node_api_auth,node_api_deps,node_api_routers,node_api_services,node_api_models,node_api_schemas,node_api_ws,node_api_migrations toneAmber
class node_web_app,node_web_ui,node_web_lib,node_web_sw toneMint
class node_mobile_nav,node_mobile_state,node_mobile_api,node_mobile_screens toneRose
```

## Components

### Infra

Local composition and runtime wiring

- [Compose](https://github.com/remodik/lentik/blob/master/infra/docker-compose.yml): orchestration · Local service assembly and env wiring · `infra/docker-compose.yml`
- **Postgres**: relational store · Primary shared datastore for application state

### Backend

FastAPI monolith and persistence

- [API entry](https://github.com/remodik/lentik/blob/master/services/api/app/main.py): FastAPI app · Monolithic backend application bootstrap · `services/api/app/main.py`
- [Auth core](https://github.com/remodik/lentik/tree/master/services/api/app/core): security · Login, PIN, JWT, sessions, rate limiting, upload and WS ticket controls · `services/api/app/core`
- [Auth deps](https://github.com/remodik/lentik/blob/master/services/api/app/auth/deps.py): request gating · Authentication and authorization dependencies · `services/api/app/auth/deps.py`
- [Routers](https://github.com/remodik/lentik/tree/master/services/api/app/routers): domain API · Domain routers exposing the backend surface · `services/api/app/routers`
- [Workflows](https://github.com/remodik/lentik/tree/master/services/api/app/services): business services · Cross-cutting server workflows and coordinators · `services/api/app/services`
- [Models](https://github.com/remodik/lentik/tree/master/services/api/app/models): ORM entities · Persistence entities for families, chat, calendar, budgets, roles, and audit · `services/api/app/models`
- [Schemas](https://github.com/remodik/lentik/tree/master/services/api/app/schemas): contracts · Request and response payload definitions · `services/api/app/schemas`
- [WS manager](https://github.com/remodik/lentik/blob/master/services/api/app/ws/manager.py): realtime · WebSocket connection and broadcast management · `services/api/app/ws/manager.py`
- [Migrations](https://github.com/remodik/lentik/tree/master/services/api/alembic/versions): schema history · Alembic database evolution for the relational model · `services/api/alembic/versions`

### Web app

Next.js client and UI

- [Next app](https://github.com/remodik/lentik/tree/master/services/web/src/app): Next.js app · App Router web frontend · `services/web/src/app`
- [Web UI](https://github.com/remodik/lentik/tree/master/services/web/src/components): client components · Feature views, modals, navigation, theme, and notifications · `services/web/src/components`
- [Web lib](https://github.com/remodik/lentik/tree/master/services/web/src/lib): client services · API wrappers, presence, permissions, and hooks · `services/web/src/lib`
- [Service worker](https://github.com/remodik/lentik/blob/master/services/web/public/sw.js): pwa runtime · Background caching and notification support · `services/web/public/sw.js`

### Mobile app

React Native client

- [Mobile nav](https://github.com/remodik/lentik/blob/master/mobile/src/navigation/RootNavigator.js): React Native app · Native navigation and screen composition · `mobile/src/navigation/RootNavigator.js`
- [App state](https://github.com/remodik/lentik/tree/master/mobile/src/context): contexts · Auth and family selection state boundaries · `mobile/src/context`
- [Mobile API](https://github.com/remodik/lentik/tree/master/mobile/src/api): client wrappers · Feature-specific HTTP clients for backend domains · `mobile/src/api`
- [Screens](https://github.com/remodik/lentik/tree/master/mobile/src/screens): feature views · Native feature screens for chat, budget, gallery, reminders, and profile · `mobile/src/screens`

## Connections

- Compose → API entry: runs · Compose starts the backend service
- Compose → Postgres: provisions · Compose wires the database service
- Compose → Next app: runs · Compose starts the web client
- Compose → Mobile nav: supports · Local environment also supports the mobile client
- API entry → Auth core: uses · App startup relies on security and session boundaries
- API entry → Auth deps: protects · Routes are guarded by auth dependencies
- API entry → Routers: mounts · Main app registers domain routers
- Routers → Workflows: orchestrates · Routers delegate workflows to service layer
- Routers → Models: persists · Routers operate on domain entities
- Routers → Schemas: validates · Routers exchange typed request/response contracts
- Workflows → Models: reads/writes · Workflows coordinate persistent state
- Workflows → Auth core: checks · Business actions depend on session and permission rules
- WS manager → Auth core: authorizes · WebSocket access uses short-lived tickets and security checks
- Models → Postgres: stored in · ORM state is persisted in PostgreSQL
- Migrations → Postgres: evolves · Alembic tracks schema changes in the database
- WS manager → Models: streams · Realtime features reflect presence and message state
- Next app → Web UI: composes · App Router pages are built from feature components
- Next app → Web lib: calls · Pages use shared client logic and API bindings
- Web UI → Web lib: depends on · UI components use hooks and API helpers
- Web UI → Service worker: enhanced by · Notifications and PWA behavior are supported in the browser shell
- Mobile nav → App state: shares state · Navigation relies on auth and family contexts
- Mobile nav → Screens: renders · Navigator selects feature screens
- Screens → Mobile API: calls · Screens use domain API modules
- Mobile API → Routers: talks to · Mobile client consumes backend HTTP endpoints
- Web lib → Routers: talks to · Web client consumes backend HTTP endpoints
- Web lib → WS manager: subscribes · Web client also participates in realtime updates
- Mobile API → WS manager: subscribes · Chat and presence can use realtime backend updates
