How foryoursafety/lostnfound-api works
Project type and purpose
• This is a monolithic, backend‐only RESTful JSON API written in Ruby.
• It implements a “LostNFound” system: accounts can post items (lost or found) and contacts can be associated with those items.
Main components
a. Clients / Consumer
• Any HTTP client (e.g. web front‐end, mobile app, curl/Postman)
b. HTTP Server & Rack Layer
• Puma (the app server) receives HTTP requests
• Rack middleware (config.ru) hands requests off to the Ruby app
c. Controllers (app/controllers)
• account, auth, item, contact, and root controllers parse HTTP requests, invoke services, and serialize JSON responses
d. Service Layer (app/services)
• Business‐logic classes (e.g. CreateItemForOwner, AddTagToItem) orchestrate model and lib calls
e. Models & Persistence
• ORM-style model classes (app/models/*.rb) represent Accounts, Items, Contacts, Tags, Passwords
• app/lib/secure_db.rb abstracts encrypted DB access; key_stretch.rb handles password hashing
• DB migrations & seeds (db/migrations, db/seeds) define and populate the schema
f. Configuration & Secrets
• config/environments.rb and config/secrets.yml manage environment‐specific settings
g. Testing Suite (spec/)
• Unit and integration specs validate controllers, services, and lib modules
Relationships and data-flow
1. Client issues HTTP request →
2. Puma / Rack →
3. Controller (e.g. ItemsController#create) →
4. Service (e.g. CreateItemForOwner) →
5. Model / lib (e.g. Item.save via secure_db) →
6. Database (SQL)
7. Bubble response back up the chain, serialize JSON, return to Client
Architectural patterns & design principles
• MVC‐style layering: Controllers handle I/O, Services encapsulate use‐cases, Models encapsulate data.
• Single‐process monolith: no microservices, everything runs in one Ruby process.
• Clear separation of concerns: cryptography in app/lib, business logic in app/services.
Relevant technologies & frameworks
• Ruby (version in .ruby-version)
• Rack + config.ru + Puma
• Bundler/Gems indicated in Gemfile
• YAML for config & seeds
• Rake tasks for DB management & tests