How naro-tw/dfans-api works
Project type and purpose
• This is a standalone backend web API written in Ruby (using Rack, likely Sinatra or a custom controller framework).
• Purpose: manage confidential photo albums—create accounts, authenticate via tokens or SSO, create albums, upload/retrieve photos, enforce authorization policies.
File structure
• Top-level files: Gemfile (Ruby dependencies), Rakefile (task runner), config.ru (Rack launcher), Procfile (for Heroku-like deployment).
• app/controllers: HTTP entry points for each resource (accounts, albums, photos, auth), plus a central app.rb that wires routes.
• app/models: domain objects (Account, Album, Photo, Password, GithubAccount).
• app/services: business logic units (authentication, authorization, CRUD operations, participant management).
• app/policies: authorization rules and scopes.
• app/lib: supporting utilities (token generation, key stretching, JSON parsing, secure DB wrappers).
• app/db: migrations, seed data, and a “store” directory for persisted photo files.
• spec: integration and unit tests validating API contracts, services, and utilities.
README for additional insights
• The README lists RESTful JSON routes under /api/v1.
• Workflow: client → HTTP router → controller → service layer → model/DB → response.
• Supports external GitHub SSO (“authorize_sso” service).
Elements
• Clear labels: “Client”, “API Router”, each Controller, Service classes, Policy classes, Model/DB, File Store, External SSO.
• HTTP → Controller
• Controller → Service
• Service → Policy/Model/DB/Store
• Service → External SSO
• Model ↔ DB
• Front-end clients in blue
• API/web layer in green
• Business logic in yellow
• Data/storage in orange
• External services in gray
Detailed capture of essential elements
• Utilities (e.g., AuthToken generator, KeyStretch) next to the Service or Policy layer.
• Performance/security notes: e.g., key stretching slows brute-force, secure_db encrypts at rest.