A Go application that uses the OpenAI API to automatically organize and process scanned magazine pages. The application scans directories of magazine page images, analyzes them using AI to extract metadata, and organizes the files into a structured output directory.
The program follows a concurrent, service-oriented architecture with three main components that communicate via channels:
- Scanner Service: Scans directories for magazine page images and uses AI to determine the correct page order.
- Analyzer Service: Analyzes cover pages using vision AI to extract metadata (title, publication number, month, year).
- Copier Service: Organizes and copies the files to the output directory with proper naming and structure.
All services run concurrently using goroutines and communicate through typed channels.
- Go 1.25+ (or the version specified in
go.mod) - An OpenAI API key with access to GPT-4 or GPT-5 models (for vision capabilities)
- Image files (JPEG/PNG) of magazine pages organized in subdirectories
The program is configured entirely via environment variables:
OPENAI_API_KEY(required): Your OpenAI API key.WORKING_DIR(required): Absolute or relative path to the directory containing subdirectories of magazine page images.OUTPUT_DIR(required): Absolute or relative path where organized magazines will be output.
In GoLand, you can set these in Run | Edit Configurations... under Environment variables.
Clone the repository and download Go dependencies:
git clone <your-repo-url> organizer
cd organizer
go mod tidyThe project includes a Makefile for common tasks:
# Build the application
make build
# Run from source
export OPENAI_API_KEY="your-api-key-here"
export WORKING_DIR="/path/to/your/magazine/scans"
export OUTPUT_DIR="/path/to/output/directory"
make run
# Clean build artifacts
make clean
# Run tests, linters, and build
make all
# Show all available commands
make helpgo build -o bin/organizer ./cmd/organizerexport OPENAI_API_KEY="your-api-key-here"
export WORKING_DIR="/path/to/your/magazine/scans"
export OUTPUT_DIR="/path/to/output/directory"
go run ./cmd/organizerexport OPENAI_API_KEY="your-api-key-here"
export WORKING_DIR="/path/to/your/magazine/scans"
export OUTPUT_DIR="/path/to/output/directory"
./bin/organizer- Create or edit a Run/Debug Configuration for
cmd/organizer/main.go. - Set
OPENAI_API_KEY,WORKING_DIR, andOUTPUT_DIRin Environment variables. - Run the configuration.
The application uses a concurrent pipeline architecture with three services:
- Scans each subdirectory in
WORKING_DIRfor image files - Sends filenames to OpenAI to determine the correct page order
- Produces
MagazinePagesobjects containing ordered page information - Sends results through a channel to the Analyzer Service
- Receives
MagazinePagesfrom the Scanner via a channel - Identifies the cover page (typically the first page)
- Uses OpenAI vision API to analyze the cover image and extract:
- Magazine title
- Publication number
- Month(s) of publication
- Year of publication
- Produces
Magazineobjects with complete metadata - Sends results through a channel to the Copier Service
- Receives
Magazineobjects from the Analyzer via a channel - Creates organized directory structure in
OUTPUT_DIR - Copies and renames files according to the extracted metadata
- Format:
{Title}/{Year}/{Number} - {Months}/page_{n}.jpg
All three services run as goroutines that communicate via typed channels:
chan entities.MagazinePages: Scanner → Analyzerchan entities.Magazine: Analyzer → Copier
The main goroutine uses a shared sync.WaitGroup to wait for all services to complete processing.
- Configuration Service: Manages environment variables and application settings
- AI Proxy: Wraps the OpenAI API client with convenience methods for text and vision requests
- Audit Service: Logs processing events and errors to timestamped audit files
organizer/
├── cmd/
│ └── organizer/
│ └── main.go # Application entry point
├── internal/
│ ├── abstractions/
│ │ ├── entities/ # Domain entities (Magazine, MagazinePages, etc.)
│ │ └── interfaces/ # Channel and service interfaces
│ ├── ai/ # OpenAI API client wrapper
│ ├── analyzer/ # Cover page analysis service
│ ├── audit/ # Audit logging service
│ ├── configuration/ # Configuration management
│ ├── copier/ # File organization and copying service
│ └── scanner/ # Directory scanning and page ordering service
├── bin/ # Compiled binaries (gitignored)
├── Makefile # Build automation
├── go.mod # Module definition and dependencies
├── go.sum # Dependency checksums
└── README.md
Add your preferred license here (e.g., MIT).