# artefactual-labs/aipscan architecture

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

- Interactive diagram: https://gitdiagram.com/artefactual-labs/aipscan
- Repository: https://github.com/artefactual-labs/aipscan

## Overview

##### Main Components

a. Frontend Layer:
- Web Interface (Flask templates in /templates)
- Static Assets (CSS/JS in /static)
- Report Visualizations

b. Backend Components:
- Flask Application Server
- Celery Worker System
- RabbitMQ Message Broker
- Database Layer (SQLite/MySQL)
- Optional Typesense Search Engine

c. External Systems:
- Archivematica Storage Service
- Archivematica AIP Storage

##### Component Relationships

**[Web Browser] <-> [Flask App Server]**

- [Database]
- [Typesense] (optional)

- [RabbitMQ] <-> [Celery Workers]

- v
**[Archivematica Storage Service] <-> [AIP METS Files]**

##### Module Organization

- API Module (/API): REST endpoints
- Aggregator Module (/Aggregator): AIP fetching and processing
- Reporter Module (/Reporter): Report generation
- Data Module (/Data): Data access layer
- User Module (/User): User management

##### Key Technical Details

- Port numbers (5000 for Flask, 5672 for RabbitMQ, 15672 for RabbitMQ admin)
- API endpoints
- Database connections
- Celery task queue
- Typesense integration points

##### Deployment Context

Optional deployment configurations:
- Development setup
- Docker-based deployment
- Production setup with MySQL

##### Reporting workflow

Keep the abstraction level high enough to show system architecture while including sufficient detail about the unique aspects of AIPscan, such as its METS file processing and reporting capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]:::client
    end

    subgraph "Application Layer"
        Flask["Flask App Server"]:::server
        click Flask "https://github.com/artefactual-labs/AIPscan/blob/main/AIPscan/__init__.py"
        
        subgraph "Core Modules"
            API["API Module"]:::module
            click API "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/API/"
            Aggregator["Aggregator Module"]:::module
            click Aggregator "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/Aggregator/"
            Reporter["Reporter Module"]:::module
            click Reporter "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/Reporter/"
            Data["Data Module"]:::module
            click Data "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/Data/"
            User["User Module"]:::module
            click User "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/User/"
        end

        subgraph "Frontend Components"
            Templates["Templates"]:::frontend
            click Templates "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/templates/"
            Static["Static Assets"]:::frontend
            click Static "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/static/"
            ReportTemplates["Report Templates"]:::frontend
            click ReportTemplates "https://github.com/artefactual-labs/AIPscan/tree/main/AIPscan/Reporter/templates/"
        end
    end

    subgraph "Processing Layer"
        Celery["Celery Workers"]:::worker
        click Celery "https://github.com/artefactual-labs/AIPscan/blob/main/AIPscan/celery.py"
        RabbitMQ["RabbitMQ<br/>Port: 5672"]:::messagebroker
        METSProcessor["METS Processor"]:::processor
        click METSProcessor "https://github.com/artefactual-labs/AIPscan/blob/main/AIPscan/Aggregator/mets_parse_helpers.py"
    end

    subgraph "Data Layer"
        DB["Database<br/>(SQLite/MySQL)"]:::database
        click DB "https://github.com/artefactual-labs/AIPscan/blob/main/AIPscan/models.py"
        Typesense["Typesense Search"]:::search
        click Typesense "https://github.com/artefactual-labs/AIPscan/blob/main/AIPscan/typesense_helpers.py"
    end

    subgraph "External Systems"
        StorageService["Archivematica<br/>Storage Service"]:::external
        AIPStorage["AIP Storage"]:::storage
    end

    %% Connections
    Browser <--> |"HTTP/HTTPS"|Flask
    Flask --> Templates
    Flask --> Static
    Flask --> API
    Flask --> Reporter
    Flask --> Data
    Flask --> User
    Flask --> RabbitMQ
    RabbitMQ --> Celery
    Celery --> METSProcessor
    METSProcessor --> StorageService
    StorageService --> AIPStorage
    Reporter --> ReportTemplates
    Data --> DB
    Data --> Typesense
    Aggregator --> METSProcessor

    %% Styles
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef server fill:#E8F5E9,stroke:#1B5E20
    classDef module fill:#F3E5F5,stroke:#4A148C
    classDef frontend fill:#FFF3E0,stroke:#E65100
    classDef worker fill:#FFEBEE,stroke:#B71C1C
    classDef messagebroker fill:#FCE4EC,stroke:#880E4F
    classDef processor fill:#F1F8E9,stroke:#33691E
    classDef database fill:#E8EAF6,stroke:#1A237E
    classDef search fill:#FFF8E1,stroke:#F57F17
    classDef external fill:#EFEBE9,stroke:#3E2723
    classDef storage fill:#E0F2F1,stroke:#004D40
```
