# bostads-ab-mimer/organisation-api architecture

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

- Interactive diagram: https://gitdiagram.com/bostads-ab-mimer/organisation-api
- Repository: https://github.com/bostads-ab-mimer/organisation-api

## Overview

Organisation API exposes authenticated REST endpoints for reading users, cost pools, responsibility areas and properties, and for creating or deleting user-to-organisation relationships. Requests enter through the Express app, route to domain controllers, and query Neo4j. User synchronisation is a separate workflow: startup, a daily schedule, or an API request invokes the sync service, which fetches Microsoft directory users and reconciles them in Neo4j. The README documents these capabilities; the shown source supports the principal route, query, and sync links. Other controller implementations were not excerpted, so their database links follow documented CRUD behavior.

Main entry points: [`src/index.ts`](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/index.ts) (Express App), [`src/config/db.ts`](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/config/db.ts) (Neo4j Connection), [`src/services/userService.ts`](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/services/userService.ts) (User Reconciliation), [`src/controllers/v1/userController.ts`](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/userController.ts) (User Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_app["Express App<br/>[index.ts]"]
  node_user_routes["User Routes<br/>[userRoutes.ts]"]
  node_cost_routes["Cost Pool Routes<br/>[costPoolRoutes.ts]"]
  node_area_routes["Responsibility Routes"]
  node_property_routes["Property Routes"]
end

subgraph group_orgdata["Organisation Data"]
  node_user_controller["User Controller<br/>[userController.ts]"]
  node_cost_controller["Cost Pool Controller"]
  node_area_controller["Responsibility Controller"]
  node_property_controller["Property Controller"]
  node_neo4j[("Neo4j Database")]
end

subgraph group_usersync["User Synchronisation"]
  node_sync_controller["Sync Endpoint<br/>[userController.ts]"]
  node_sync_service["User Reconciliation<br/>[userService.ts]"]
  node_graph_integration["Microsoft Graph Client"]
  node_scheduler["Daily Scheduler<br/>[cronJob.ts]"]
end

subgraph group_runtime["Runtime Infrastructure"]
  node_auth["API Authentication<br/>[auth.ts]"]
  node_errors["Error Handler<br/>[error-handler.ts]"]
  node_db_config["Neo4j Connection<br/>[db.ts]"]
  node_swagger["API Documentation Setup<br/>[swaggerOptions.ts]"]
end

node_client(("API Client"))
node_directory(("Microsoft Directory"))

node_client -->|"sends requests"| node_app
node_app -->|"applies authentication"| node_auth
node_app -->|"registers handler"| node_errors
node_app -->|"mounts users"| node_user_routes
node_app -->|"mounts cost pools"| node_cost_routes
node_app -->|"mounts responsibility areas"| node_area_routes
node_app -->|"mounts properties"| node_property_routes
node_app -->|"configures API docs"| node_swagger
node_user_routes -->|"dispatches requests"| node_user_controller
node_cost_routes -->|"dispatches requests"| node_cost_controller
node_area_routes -->|"dispatches requests"| node_area_controller
node_property_routes -->|"dispatches requests"| node_property_controller
node_user_controller -->|"queries database"| node_db_config
node_cost_controller -->|"queries database"| node_db_config
node_area_controller -->|"queries database"| node_db_config
node_property_controller -->|"queries database"| node_db_config
node_db_config -->|"connects to"| node_neo4j
node_user_controller -->|"starts sync"| node_sync_service
node_app -->|"syncs on startup"| node_sync_service
node_scheduler -->|"runs scheduled sync"| node_sync_service
node_sync_service -->|"fetches directory users"| node_graph_integration
node_graph_integration -.->|"requests user data"| node_directory
node_sync_service -->|"reconciles user records"| node_db_config

click node_app "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/index.ts"
click node_auth "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/middleware/auth.ts"
click node_errors "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/middleware/error-handler.ts"
click node_user_routes "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/userRoutes.ts"
click node_cost_routes "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/costPoolRoutes.ts"
click node_area_routes "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/responsibilityAreasRoutes.ts"
click node_property_routes "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/propertiesRoutes.ts"
click node_user_controller "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/userController.ts"
click node_cost_controller "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/costPoolsController.ts"
click node_area_controller "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/responsibilityAreasController.ts"
click node_property_controller "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/propertiesController.ts"
click node_db_config "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/config/db.ts"
click node_sync_controller "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/userController.ts"
click node_sync_service "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/services/userService.ts"
click node_graph_integration "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/integrations/microsoftGraphApi.ts"
click node_scheduler "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/scheduler/cronJob.ts"
click node_swagger "https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/config/swaggerOptions.ts"

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_user_routes,node_cost_routes,node_area_routes,node_property_routes,node_client toneBlue
class node_user_controller,node_cost_controller,node_area_controller,node_property_controller,node_neo4j toneAmber
class node_sync_controller,node_sync_service,node_graph_integration,node_scheduler toneMint
class node_auth,node_errors,node_db_config,node_swagger toneRose
class node_directory toneIndigo
```

## Components

### REST API

- [Express App](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/index.ts): `src/index.ts`
- [User Routes](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/userRoutes.ts): `src/routes/v1/userRoutes.ts`
- [Cost Pool Routes](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/costPoolRoutes.ts): `src/routes/v1/costPoolRoutes.ts`
- [Responsibility Routes](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/responsibilityAreasRoutes.ts): `src/routes/v1/responsibilityAreasRoutes.ts`
- [Property Routes](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/routes/v1/propertiesRoutes.ts): `src/routes/v1/propertiesRoutes.ts`

### Organisation Data

- [User Controller](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/userController.ts): `src/controllers/v1/userController.ts`
- [Cost Pool Controller](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/costPoolsController.ts): `src/controllers/v1/costPoolsController.ts`
- [Responsibility Controller](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/responsibilityAreasController.ts): `src/controllers/v1/responsibilityAreasController.ts`
- [Property Controller](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/propertiesController.ts): `src/controllers/v1/propertiesController.ts`
- **Neo4j Database**

### User Synchronisation

- [Sync Endpoint](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/controllers/v1/userController.ts): `src/controllers/v1/userController.ts`
- [User Reconciliation](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/services/userService.ts): `src/services/userService.ts`
- [Microsoft Graph Client](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/integrations/microsoftGraphApi.ts): `src/integrations/microsoftGraphApi.ts`
- [Daily Scheduler](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/scheduler/cronJob.ts): `src/scheduler/cronJob.ts`

### Runtime Infrastructure

- [API Authentication](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/middleware/auth.ts): `src/middleware/auth.ts`
- [Error Handler](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/middleware/error-handler.ts): `src/middleware/error-handler.ts`
- [Neo4j Connection](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/config/db.ts): `src/config/db.ts`
- [API Documentation Setup](https://github.com/bostads-ab-mimer/organisation-api/blob/master/src/config/swaggerOptions.ts): `src/config/swaggerOptions.ts`

### Other components

- **API Client**
- **Microsoft Directory**

## Connections

- API Client → Express App: sends requests (evidence: `src/index.ts`)
- Express App → API Authentication: applies authentication (evidence: `src/index.ts`)
- Express App → Error Handler: registers handler (evidence: `src/index.ts`)
- Express App → User Routes: mounts users (evidence: `src/index.ts`)
- Express App → Cost Pool Routes: mounts cost pools (evidence: `src/index.ts`)
- Express App → Responsibility Routes: mounts responsibility areas (evidence: `src/index.ts`)
- Express App → Property Routes: mounts properties (evidence: `src/index.ts`)
- Express App → API Documentation Setup: configures API docs (evidence: `src/index.ts`)
- User Routes → User Controller: dispatches requests (evidence: `src/routes/v1/userRoutes.ts`)
- Cost Pool Routes → Cost Pool Controller: dispatches requests (evidence: `src/routes/v1/costPoolRoutes.ts`)
- Responsibility Routes → Responsibility Controller: dispatches requests (evidence: `src/routes/v1/responsibilityAreasRoutes.ts`)
- Property Routes → Property Controller: dispatches requests (evidence: `src/routes/v1/propertiesRoutes.ts`)
- User Controller → Neo4j Connection: queries database (evidence: `src/controllers/v1/userController.ts`)
- Cost Pool Controller → Neo4j Connection: queries database (evidence: `src/controllers/v1/costPoolsController.ts`)
- Responsibility Controller → Neo4j Connection: queries database (evidence: `src/controllers/v1/responsibilityAreasController.ts`)
- Property Controller → Neo4j Connection: queries database (evidence: `src/controllers/v1/propertiesController.ts`)
- Neo4j Connection → Neo4j Database: connects to (evidence: `src/config/db.ts`)
- User Controller → User Reconciliation: starts sync (evidence: `src/controllers/v1/userController.ts`)
- Express App → User Reconciliation: syncs on startup (evidence: `src/index.ts`)
- Daily Scheduler → User Reconciliation: runs scheduled sync (evidence: `src/scheduler/cronJob.ts`)
- User Reconciliation → Microsoft Graph Client: fetches directory users (evidence: `src/services/userService.ts`)
- Microsoft Graph Client → Microsoft Directory: requests user data
- User Reconciliation → Neo4j Connection: reconciles user records (evidence: `src/services/userService.ts`)
