# jyonkov/motech architecture

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

- Interactive diagram: https://gitdiagram.com/jyonkov/motech
- Repository: https://github.com/jyonkov/motech

## Overview

##### Main Components

a. Core Platform Components:
- Platform Server (motech-platform-server)
- Platform Common (motech-platform-common)
- Platform Scheduler (motech-platform-scheduler)
- Platform Server API (motech-platform-server-api)

b. Service Modules:
- Appointments Service
- Outbox Service
- IVR (Interactive Voice Response) Service
- Pill Reminder Service
- Decision Tree Service
- TAMA (Treatment Advice through Mobile Alerts) Service

##### Client Layer
- Web Interface (VxmlControllers)
- IVR Interface

##### Service Layer
- Authentication Services
- Event Handling Services
- Business Logic Services

##### Data Access Layer
- DAO Implementations
- CouchDB Storage
- REST Implementations

##### Integration Layer
- OSGi Framework
- Event System
- Scheduler System

##### Key Relationships to Highlight

a. Event Flow:
- Event propagation from ServerEventRelay through EventListeners
- Relationship between MotechScheduler and event handling

b. Data Flow:
- Flow from Controllers → Services → DAOs → Database
- Integration points between different modules

##### Specific Implementation Details

Key architectural patterns:
- OSGi-based modularity
- Event-driven architecture
- MVC pattern in web components
- Repository pattern in data access
- Decision tree-based rule engine

##### Component Relationships

- OSGi service dependencies
- Event subscriptions
- Database access patterns
- API calls between modules

##### Technical Specifications

Annotations for:
- CouchDB as the primary database
- Java-based implementation
- OSGi framework
- Spring dependency injection
- Drools rule engine integration

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px
    classDef integration fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef interface fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef data fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef security fill:#FFB6C1,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        WEB["Web Interface"]:::interface
        IVR["IVR Interface"]:::interface
        VXML["VXML Controllers"]:::interface
    end

    %% Core Platform
    subgraph CorePlatform
        PS["Platform Server"]:::core
        PC["Platform Common"]:::core
        PSched["Platform Scheduler"]:::core
        PSAPI["Platform Server API"]:::core
    end

    %% Service Layer
    subgraph ServiceLayer
        AS["Appointments Service"]:::service
        OS["Outbox Service"]:::service
        IVRS["IVR Service"]:::service
        PRS["Pill Reminder Service"]:::service
        DTS["Decision Tree Service"]:::service
        TAMA["TAMA Service"]:::service
    end

    %% Integration Layer
    subgraph IntegrationLayer
        OSGI["OSGi Framework"]:::integration
        EG["Event Gateway"]:::integration
        EH["Event Handling"]:::integration
        EL["Event Listeners"]:::integration
    end

    %% Data Access Layer
    subgraph DataLayer
        ADao["Appointments DAO"]:::data
        ODao["Outbox DAO"]:::data
        PRDao["Pill Reminder DAO"]:::data
        DB[(CouchDB)]:::data
    end

    %% Relationships
    ClientLayer --> ServiceLayer
    ServiceLayer --> IntegrationLayer
    IntegrationLayer --> DataLayer
    DataLayer --> DB
    
    EH --> EL
    PSched --> EH
    OSGI --> ServiceLayer
    EG --> ServiceLayer

    %% Click Events
    click PS "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-server"
    click PC "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-common"
    click PSched "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-scheduler"
    click PSAPI "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-server-api"
    click AS "https://github.com/jyonkov/MOTECH/tree/master/motech-appointments-api"
    click OS "https://github.com/jyonkov/MOTECH/tree/master/motech-outbox-api"
    click IVRS "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-ivr"
    click PRS "https://github.com/jyonkov/MOTECH/tree/master/motech-pillreminder-api"
    click DTS "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-decisiontree"
    click TAMA "https://github.com/jyonkov/MOTECH/tree/master/tama-api"
    click ADao "https://github.com/jyonkov/MOTECH/tree/master/motech-appointments-api/src/main/java/org/motechproject/appointments/api/dao"
    click ODao "https://github.com/jyonkov/MOTECH/tree/master/motech-outbox-api/src/main/java/org/motechproject/outbox/api/dao"
    click PRDao "https://github.com/jyonkov/MOTECH/tree/master/motech-pillreminder-api/src/main/java/org/motechproject/pillreminder/api/dao"
    click EH "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-server-api/src/main/java/org/motechproject/server/event"
    click EL "https://github.com/jyonkov/MOTECH/blob/master/motech-platform-server-api/src/main/java/org/motechproject/server/event/EventListener.java"
    click OSGI "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-server-api/src/main/java/org/motechproject/server/osgi"
    click EG "https://github.com/jyonkov/MOTECH/tree/master/motech-platform-common/src/main/java/org/motechproject/gateway"
    click VXML "https://github.com/jyonkov/MOTECH/blob/master/motech-platform-decisiontree/src/main/java/org/motechproject/server/decisiontree/web/VxmlController.java"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Service Modules]:::service
        L3[Integration Components]:::integration
        L4[Interfaces]:::interface
        L5[Data Components]:::data
    end
```
