# mradmacher/paleolog architecture

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

- Interactive diagram: https://gitdiagram.com/mradmacher/paleolog
- Repository: https://github.com/mradmacher/paleolog

## Overview

##### Main Architectural Components

a) Web Layer (Frontend)
- JavaScript client-side applications (catalog, counting, project, species)
- ERB view templates system
- API endpoints

b) Application Core (Backend)
- In the middle
- Main domain entities and services
- Authorization system

c) Data Layer
- At the bottom
- SQLite database connection
- Repository pattern implementation

##### Component Relationships

a) Client-Server Communication
- REST API routes between frontend and backend
- Authentication flow
- View template rendering paths

b) Domain Logic Flow
- Repositories to core entities
- Authorization checks
- Report generation flow

##### Specific Implementation Details

Key architectural elements:

a) Frontend Components:
- JavaScript Apps (catalog_app, counting_app, project_app, etc.)
- View Templates (/web/views/)
- API Clients (/web/js/requests.js)

b) Backend Services:
- Authorizer
- Report Generator
- Counting Summary
- Density Information

c) Repository Layer:
- Project Repository
- Species Repository
- Counting Repository
- Occurrence Repository
- Sample Repository
- Section Repository

##### Specific Architectural Patterns to Highlight

- Repository Pattern: Show clear separation between domain logic and data access
- MVC Pattern: Demonstrate the separation of views, controllers (web handlers), and models
- REST API Architecture: Show the API endpoint organization
- Authentication Flow: Highlight security boundaries

##### Technical Stack Elements

- Ruby (Web Framework)
- SQLite Database
- JavaScript (Frontend)
- ERB Templates
- Docker Container

##### Business Logic Layer (Lib)
- Core Entities
- Services
- Report Generation

##### Data Access Layer (Repository)
- Data Access Objects
- Query Operations
- Database Interactions

Important Notes:
- Keep the paleontological domain context visible in the component naming
- Clear boundaries between authenticated and public areas
- Where Docker containerization fits in the architecture
- Test coverage boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Web_Layer
        JS["JavaScript Apps"]:::frontend
        Views["View Templates"]:::frontend
        API["API Endpoints"]:::frontend
        
        CatalogApp["Catalog App"]:::frontend
        CountingApp["Counting App"]:::frontend
        ProjectApp["Project App"]:::frontend
        SpeciesApp["Species App"]:::frontend
        
        JS --> CatalogApp
        JS --> CountingApp
        JS --> ProjectApp
        JS --> SpeciesApp
    end

    subgraph Core_Services
        Auth["Authorizer"]:::service
        RepGen["Report Generator"]:::service
        CountSum["Counting Summary"]:::service
        DensInfo["Density Information"]:::service
    end

    subgraph Data_Layer
        DB[(SQLite Database)]:::database
        
        ProjRepo["Project Repository"]:::repo
        SpecRepo["Species Repository"]:::repo
        CountRepo["Counting Repository"]:::repo
        OccurRepo["Occurrence Repository"]:::repo
        SampRepo["Sample Repository"]:::repo
        SectRepo["Section Repository"]:::repo
        
        DB --> ProjRepo
        DB --> SpecRepo
        DB --> CountRepo
        DB --> OccurRepo
        DB --> SampRepo
        DB --> SectRepo
    end

    API --> Auth
    Auth --> Core_Services
    Core_Services --> Data_Layer
    Views --> Core_Services
    
    classDef frontend fill:#3498db
    classDef service fill:#2ecc71
    classDef repo fill:#f1c40f
    classDef database fill:#95a5a6
    classDef security fill:#e74c3c

    click JS "https://github.com/mradmacher/paleolog/tree/main/web/js/"
    click CatalogApp "https://github.com/mradmacher/paleolog/blob/main/web/js/catalog_app.js"
    click CountingApp "https://github.com/mradmacher/paleolog/blob/main/web/js/counting_app.js"
    click ProjectApp "https://github.com/mradmacher/paleolog/blob/main/web/js/project_app.js"
    click SpeciesApp "https://github.com/mradmacher/paleolog/blob/main/web/js/species_app.js"
    click Views "https://github.com/mradmacher/paleolog/tree/main/web/views/"
    click API "https://github.com/mradmacher/paleolog/tree/main/web/api/"
    click Auth "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/authorizer.rb"
    click RepGen "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/paleorep/report.rb"
    click CountSum "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/counting_summary.rb"
    click DensInfo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/density_info.rb"
    click ProjRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/project.rb"
    click SpecRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/species.rb"
    click CountRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/counting.rb"
    click OccurRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/occurrence.rb"
    click SampRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/sample.rb"
    click SectRepo "https://github.com/mradmacher/paleolog/blob/main/lib/paleolog/repository/section.rb"
    click DB "https://github.com/mradmacher/paleolog/blob/main/db/.sqlite"
```
