# zeppyx13/coasther-api architecture

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

- Interactive diagram: https://gitdiagram.com/zeppyx13/coasther-api
- Repository: https://github.com/zeppyx13/coasther-api

## Overview

Coasther is a backend API for managing a single, multi-room lodging business: tenants authenticate, view room/lease and usage information, receive invoices, and pay; administrators manage operational features. The principal documented flow runs from HTTP routes through controllers and services to domain data, with separate automated billing and IoT meter-ingestion stages. The graph also preserves documented complaints, reviews, announcements, AI chat, and notifications. Evidence is limited to the README and sampled/indexed files; uncertain internal links are omitted.

Main entry points: [`src/app.js`](https://github.com/zeppyx13/coasther-api/blob/main/src/app.js) (HTTP application), [`src/jobs/invoiceMonthly.job.js`](https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/invoiceMonthly.job.js) (Invoice generation), [`src/routes/iot.routes.js`](https://github.com/zeppyx13/coasther-api/blob/main/src/routes/iot.routes.js) (IoT routes), [`src/jobs/scheduler.js`](https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/scheduler.js) (Billing scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["HTTP application<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_authcontroller["Auth controller<br/>[auth.controller.js]"]
  node_authservice["Authentication<br/>[auth.service.js]"]
  node_users[("User records<br/>[user.model.js]")]
  node_database[("MySQL pool<br/>[db.js]")]
end

subgraph group_tenant["Tenant operations"]
  node_rooms["Rooms and leases<br/>[room.controller.js]"]
  node_tenantdata["Tenant dashboard"]
end

subgraph group_billing["Billing and meters"]
  node_usage["Usage monitoring"]
  node_meteringest["Meter ingestion<br/>[iot.service.js]"]
  node_iotroutes["IoT routes<br/>[iot.routes.js]"]
  node_usagejob["Monthly usage job"]
  node_invoicejob["Invoice generation"]
  node_scheduler["Billing scheduler<br/>[scheduler.js]"]
  node_payments["Payments and invoices<br/>[payment.service.js]"]
end

subgraph group_admin["Admin and integrations"]
  node_complaints["Complaints"]
  node_reviews["Reviews"]
  node_announcements["Announcements"]
  node_aichat["AI chat<br/>[ai.service.js]"]
  node_notifications["Push notifications<br/>[fcm-sender.js]"]
  node_mailer["Email delivery<br/>[mailer.js]"]
end

node_client(("API client"))
node_midtrans["Midtrans"]
node_device(("IoT device"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_authroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authcontroller -->|"calls"| node_authservice
node_authservice -->|"reads and writes"| node_users
node_app -->|"mounts routes"| node_iotroutes
node_device -->|"sends readings"| node_iotroutes
node_iotroutes -.->|"accepts readings"| node_meteringest
node_client -->|"requests rooms"| node_rooms
node_client -->|"requests dashboard"| node_tenantdata
node_client -->|"requests usage"| node_usage
node_scheduler -->|"runs job"| node_usagejob
node_scheduler -->|"runs job"| node_invoicejob
node_invoicejob -->|"sends email"| node_mailer
node_invoicejob -->|"sends alerts"| node_notifications
node_client -->|"starts payment"| node_payments
node_midtrans -->|"confirms payment"| node_payments
node_client -->|"submits complaints"| node_complaints
node_client -->|"submits reviews"| node_reviews
node_client -->|"requests announcements"| node_announcements
node_client -->|"asks questions"| node_aichat

click node_app "https://github.com/zeppyx13/coasther-api/blob/main/src/app.js"
click node_authroutes "https://github.com/zeppyx13/coasther-api/blob/main/src/routes/auth.routes.js"
click node_authcontroller "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/auth.controller.js"
click node_authservice "https://github.com/zeppyx13/coasther-api/blob/main/src/services/auth.service.js"
click node_users "https://github.com/zeppyx13/coasther-api/blob/main/src/models/user.model.js"
click node_rooms "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/room.controller.js"
click node_tenantdata "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/tenant.controller.js"
click node_usage "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/usageTenant.controller.js"
click node_meteringest "https://github.com/zeppyx13/coasther-api/blob/main/src/services/iot.service.js"
click node_iotroutes "https://github.com/zeppyx13/coasther-api/blob/main/src/routes/iot.routes.js"
click node_usagejob "https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/usageMonthly.job.js"
click node_invoicejob "https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/invoiceMonthly.job.js"
click node_scheduler "https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/scheduler.js"
click node_payments "https://github.com/zeppyx13/coasther-api/blob/main/src/services/payment.service.js"
click node_complaints "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/complaint.controller.js"
click node_reviews "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/review.controller.js"
click node_announcements "https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/announcement.controller.js"
click node_aichat "https://github.com/zeppyx13/coasther-api/blob/main/src/services/ai.service.js"
click node_notifications "https://github.com/zeppyx13/coasther-api/blob/main/src/lib/fcm-sender.js"
click node_mailer "https://github.com/zeppyx13/coasther-api/blob/main/src/lib/mailer.js"
click node_database "https://github.com/zeppyx13/coasther-api/blob/main/src/config/db.js"

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_app,node_authroutes,node_authcontroller,node_authservice,node_users,node_database,node_client toneBlue
class node_rooms,node_tenantdata toneAmber
class node_usage,node_meteringest,node_iotroutes,node_usagejob,node_invoicejob,node_scheduler,node_payments toneMint
class node_complaints,node_reviews,node_announcements,node_aichat,node_notifications,node_mailer toneRose
class node_midtrans,node_device toneIndigo
```

## Components

### API and access

- [HTTP application](https://github.com/zeppyx13/coasther-api/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/zeppyx13/coasther-api/blob/main/src/routes/auth.routes.js): `src/routes/auth.routes.js`
- [Auth controller](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/auth.controller.js): `src/controllers/auth.controller.js`
- [Authentication](https://github.com/zeppyx13/coasther-api/blob/main/src/services/auth.service.js): `src/services/auth.service.js`
- [User records](https://github.com/zeppyx13/coasther-api/blob/main/src/models/user.model.js): `src/models/user.model.js`
- [MySQL pool](https://github.com/zeppyx13/coasther-api/blob/main/src/config/db.js): `src/config/db.js`

### Tenant operations

- [Rooms and leases](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/room.controller.js): `src/controllers/room.controller.js`
- [Tenant dashboard](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/tenant.controller.js): `src/controllers/tenant.controller.js`

### Billing and meters

- [Usage monitoring](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/usageTenant.controller.js): `src/controllers/usageTenant.controller.js`
- [Meter ingestion](https://github.com/zeppyx13/coasther-api/blob/main/src/services/iot.service.js): `src/services/iot.service.js`
- [IoT routes](https://github.com/zeppyx13/coasther-api/blob/main/src/routes/iot.routes.js): `src/routes/iot.routes.js`
- [Monthly usage job](https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/usageMonthly.job.js): `src/jobs/usageMonthly.job.js`
- [Invoice generation](https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/invoiceMonthly.job.js): `src/jobs/invoiceMonthly.job.js`
- [Billing scheduler](https://github.com/zeppyx13/coasther-api/blob/main/src/jobs/scheduler.js): `src/jobs/scheduler.js`
- [Payments and invoices](https://github.com/zeppyx13/coasther-api/blob/main/src/services/payment.service.js): `src/services/payment.service.js`

### Admin and integrations

- [Complaints](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/complaint.controller.js): `src/controllers/complaint.controller.js`
- [Reviews](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/review.controller.js): `src/controllers/review.controller.js`
- [Announcements](https://github.com/zeppyx13/coasther-api/blob/main/src/controllers/announcement.controller.js): `src/controllers/announcement.controller.js`
- [AI chat](https://github.com/zeppyx13/coasther-api/blob/main/src/services/ai.service.js): `src/services/ai.service.js`
- [Push notifications](https://github.com/zeppyx13/coasther-api/blob/main/src/lib/fcm-sender.js): `src/lib/fcm-sender.js`
- [Email delivery](https://github.com/zeppyx13/coasther-api/blob/main/src/lib/mailer.js): `src/lib/mailer.js`

### Other components

- **API client**
- **Midtrans**
- **IoT device**

## Connections

- API client → HTTP application: sends requests (evidence: `src/app.js`)
- HTTP application → Auth routes: mounts routes (evidence: `src/app.js`)
- Auth routes → Auth controller: dispatches (evidence: `src/routes/auth.routes.js`)
- Auth controller → Authentication: calls (evidence: `src/controllers/auth.controller.js`)
- Authentication → User records: reads and writes (evidence: `src/services/auth.service.js`)
- HTTP application → IoT routes: mounts routes (evidence: `src/app.js`)
- IoT device → IoT routes: sends readings
- IoT routes → Meter ingestion: accepts readings
- API client → Rooms and leases: requests rooms
- API client → Tenant dashboard: requests dashboard
- API client → Usage monitoring: requests usage
- Billing scheduler → Monthly usage job: runs job (evidence: `src/jobs/scheduler.js`)
- Billing scheduler → Invoice generation: runs job (evidence: `src/jobs/scheduler.js`)
- Invoice generation → Email delivery: sends email (evidence: `src/jobs/invoiceMonthly.job.js`)
- Invoice generation → Push notifications: sends alerts (evidence: `src/jobs/invoiceMonthly.job.js`)
- API client → Payments and invoices: starts payment
- Midtrans → Payments and invoices: confirms payment
- API client → Complaints: submits complaints
- API client → Reviews: submits reviews
- API client → Announcements: requests announcements
- API client → AI chat: asks questions
