# hotosm/fmtm architecture

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

- Interactive diagram: https://gitdiagram.com/hotosm/fmtm
- Repository: https://github.com/hotosm/fmtm

## Overview

##### Main Components

a. Frontend Layer:
- React-based web application (src/frontend)
- Svelte-based mapper interface (src/mapper)
- Mobile interface for ODK Collect integration

b. Backend Layer:
- FastAPI application (src/backend)
- Authentication system with OSM integration
- Task management system
- Project management system
- Organization management system

c. Data Storage:
- PostgreSQL database with PostGIS extension
- MinIO for file storage
- ODK Central for form storage and submissions

d. Infrastructure:
- Nginx reverse proxy
- Docker containerization
- Kubernetes orchestration

##### Relationships and Data Flow

**1. User Authentication Flow:**
- Browser -> Nginx -> FastAPI -> OSM OAuth -> Database

**2. Project Creation Flow:**
- Frontend -> FastAPI -> Database
- > ODK Central (form creation)
- > MinIO (file storage)

**3. Mapping Flow:**
- Mobile App -> ODK Central -> FastAPI -> Database
- > Frontend (real-time updates)

**4. Data Submission Flow:**
- ODK Collect -> ODK Central -> FastAPI
- > PostgreSQL/PostGIS -> Frontend

##### Important Elements to Highlight

a. Integration Points:
- ODK Central integration
- OSM authentication
- MinIO storage interface
- PostGIS spatial capabilities

b. Security Layers:
- Authentication middleware
- API gateway
- Role-based access control

c. Data Processing:
- Task splitting system
- Geospatial processing
- Data validation and conflation

##### Architectural Patterns to Emphasize

- Microservices architecture (multiple containers)
- API-first design
- Event-driven updates for real-time features
- Spatial data handling capabilities
- Offline-first mobile capabilities

**[Client Layer]**
- ↓
**[API Gateway/Nginx]**
- ↓
**[Application Services]**
- ↓
**[Data Services]**
- ↓
**[Storage Layer]**

##### Technical Details to Note

- FastAPI backend with PostgreSQL
- React frontend with Redux state management
- Svelte mapper interface
- Docker containerization
- Kubernetes orchestration
- ODK ecosystem integration
- OSM authentication and data flow

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'fontSize': '16px'}}}%%

flowchart TB
    subgraph Client
        Browser["Web Browser"]
        ODKCollect["ODK Collect Mobile App"]
        ReactFE["React Frontend"]
        SvelteMapper["Svelte Mapper"]
    end

    subgraph Gateway
        Nginx["Nginx Reverse Proxy"]
    end

    subgraph Backend
        FastAPI["FastAPI Backend"]
        Auth["Authentication System"]
        TaskMgmt["Task Management"]
        ProjMgmt["Project Management"]
        OrgMgmt["Organization Management"]
        UserMgmt["User Management"]
        SubHandler["Submission Handler"]
        APIRoutes["API Routes"]
        MinIOInt["MinIO Integration"]
    end

    subgraph External
        OSMAuth["OSM OAuth"]
        ODKCentral["ODK Central"]
    end

    subgraph Storage
        PostgreSQL[(PostgreSQL/PostGIS)]
        MinIO[(MinIO Storage)]
        DBMigrations["Database Migrations"]
        DBModels["Database Models"]
    end

    %% Client Layer Connections
    Browser --> Nginx
    ODKCollect --> ODKCentral
    ReactFE --> Nginx
    SvelteMapper --> Nginx

    %% Gateway Layer
    Nginx --> FastAPI
    Nginx --> MinIO

    %% Backend Layer Connections
    FastAPI --> Auth
    FastAPI --> TaskMgmt
    FastAPI --> ProjMgmt
    FastAPI --> OrgMgmt
    FastAPI --> UserMgmt
    FastAPI --> SubHandler
    FastAPI --> APIRoutes
    FastAPI --> MinIOInt

    %% External Service Connections
    Auth --> OSMAuth
    FastAPI --> ODKCentral

    %% Storage Layer Connections
    TaskMgmt --> PostgreSQL
    ProjMgmt --> PostgreSQL
    OrgMgmt --> PostgreSQL
    UserMgmt --> PostgreSQL
    SubHandler --> PostgreSQL
    MinIOInt --> MinIO
    PostgreSQL --- DBMigrations
    PostgreSQL --- DBModels

    %% Click Events
    click ReactFE "https://github.com/hotosm/fmtm/tree/development/src/frontend/"
    click SvelteMapper "https://github.com/hotosm/fmtm/tree/development/src/mapper/"
    click FastAPI "https://github.com/hotosm/fmtm/tree/development/src/backend/app/"
    click Auth "https://github.com/hotosm/fmtm/tree/development/src/backend/app/auth/"
    click TaskMgmt "https://github.com/hotosm/fmtm/tree/development/src/backend/app/tasks/"
    click ProjMgmt "https://github.com/hotosm/fmtm/tree/development/src/backend/app/projects/"
    click OrgMgmt "https://github.com/hotosm/fmtm/tree/development/src/backend/app/organisations/"
    click DBModels "https://github.com/hotosm/fmtm/tree/development/src/backend/app/db/"
    click ODKCentral "https://github.com/hotosm/fmtm/tree/development/odkcentral/"
    click Nginx "https://github.com/hotosm/fmtm/tree/development/nginx/"
    click APIRoutes "https://github.com/hotosm/fmtm/blob/development/src/backend/app/main.py"
    click UserMgmt "https://github.com/hotosm/fmtm/tree/development/src/backend/app/users/"
    click SubHandler "https://github.com/hotosm/fmtm/tree/development/src/backend/app/submissions/"
    click DBMigrations "https://github.com/hotosm/fmtm/tree/development/src/backend/migrations/"
    click MinIOInt "https://github.com/hotosm/fmtm/blob/development/src/backend/app/s3.py"

    %% Styling
    classDef client fill:#2374ab,color:#fff
    classDef gateway fill:#ff7f50,color:#fff
    classDef backend fill:#2ecc71,color:#fff
    classDef external fill:#9b59b6,color:#fff
    classDef storage fill:#f1c40f,color:#000
    
    class Browser,ODKCollect,ReactFE,SvelteMapper client
    class Nginx gateway
    class FastAPI,Auth,TaskMgmt,ProjMgmt,OrgMgmt,UserMgmt,SubHandler,APIRoutes,MinIOInt backend
    class OSMAuth,ODKCentral external
    class PostgreSQL,MinIO,DBMigrations,DBModels storage
```
