# Conventions

A Fellow application is a set of business modules on top of Nitro (server), Bun (runtime), Vue (frontend) and PostgreSQL.

## Project layout

```
index.html                Page shell template; its module script names the client entry (src/main.ts).
app.ts                    Application configuration (defineApp).
src/                      Vue frontend. src/fellow.gen.ts is generated (typed client, pages map).
modules/<id>/
  module.ts               Manifest: id, version, dependencies, permissions.
  public.ts               The only file other modules may import.
  entities/<entity>.ts    Schema + table mapping (defineEntity).
  services/<name>.ts      Business rules and data access.
  routes/<name>.ts        HTTP contracts (defineRoute). Thin: validate, authorize, call a service.
  events/<name>.ts        Typed, versioned events (defineEvent).
  migrations/NNNN_x.sql   SQL migrations owned by the module.
  tests/<name>.test.ts    bun:test tests.
```

## Naming

- Module ids, entities and fields: lowercase `snake_case`.
- Route id: `<module>.<resource>.<action>` (`records.documents.create`).
- Permission: `<module>.<entity>.<action>` (`records.document.create`). Declared in the manifest.
- Event: `<module>.<entity>.<fact>` in the past tense (`records.document.created`).
- Table: `<module>_<plural>` (`records_documents`).
- Error code: `<module>.<entity>.<problem>` (`records.document.not_found`).

## Sources of truth

Nothing is declared twice. The manifest holds what cannot be derived (identity, version,
dependencies, permissions). Routes, entities, events and migrations are discovered from files.
`fellow intel` builds the project map from them, so it can never drift from the code.

## Environment

Validated on first use. `fellow doctor` reports problems.

- `DATABASE_URL`: PostgreSQL URL. The role must not be SUPERUSER or BYPASSRLS.
- `FELLOW_SECRET`: at least 32 characters; signs access tokens.
- `FELLOW_DB_POOL_MAX`: pool size, default 10.
