How colifeinc/108sharing works
Project Type and Purpose
• 108Sharing is a full-stack web application built with Ruby on Rails (Rails 6) on the backend and a dedicated frontend directory that houses React/TypeScript components.
• The application supports both a traditional server-rendered interface with Rails views and an API layer (with endpoints under /api and /admin/api) for client-side communication.
• It integrates essential external services such as Stripe for payments, Redis for caching and background job management (via Sidekiq), and likely third-party OAuth (Facebook, Google, Twitter) for social logins.
Analyzing the File Structure
• The “app” directory contains Rails MVC components: controllers (including separated admin and API controllers), models (with concerns and business logic), views (for user, admin, and mailers), jobs for background processing, mailers, and policies.
• The “frontend” directory contains a rich collection of React components (atoms, molecules, organisms, pages, layouts) indicating a modern component-based UI for client-side rendering and leveraging TypeScript.
• The “config” directory hosts environment settings, database configurations, initializers (including for Sidekiq and Stripe), and routes, which are central to understanding how requests are handled.
• Docker files (Dockerfile, docker-compose.yml) and deployment scripts (Makefile, Procfile, CI/CD configurations in .circleci and .github) indicate containerized deployment strategies.
Architectural Patterns Highlighted
• The application follows the standard Rails MVC pattern, enhanced with:
• An API layer for mobile or SPA clients.
• A separate frontend build (possibly using Webpack and Yarn) suggesting a decoupled or hybrid approach (server-side rendering plus client-side enhancements).
• Background processing with Sidekiq (via jobs and the Redis configuration).
• The design also includes aspects like service objects (in app/services) for orchestrating business logic, serialization (app/serializers) to format JSON responses, and policies (app/policies) to enforce authorization.
a. Main Components:
• Client/Browser: Users interact via web browsers which render both server-generated pages and run dynamic React components.
• Frontend (React/TypeScript): Responsible for rich client-side UI and consuming Rails APIs.
• Rails Web Server: Handles HTTP requests routed via Rails controllers (including traditional HTML and JSON API responses). It includes the MVC layers (views, controllers, models).
• Database (PostgreSQL): Stores persistent data (managed via ActiveRecord, migrations, seeds).
• Redis: Employed for caching, ActionCable (for WebSocket connections), and background job processing with Sidekiq.
• External Services: Stripe for payments, OAuth providers for authentication, and possibly image processing (Imagemagick) for assets.
• Background Jobs: Managed by Sidekiq (using code under app/jobs) for asynchronous tasks.
• Developer & CI/CD Infrastructure: Docker containers (Dockerfile, docker-compose), CI configurations (.github, .circleci) that orchestrate deployment and testing.
b. Relationships & Data Flow:
• User requests enter via the browser to the Rails web server, which routes some requests to server-rendered pages and others to API endpoints.
• The React frontend may be served via a separate webpack bundle or integrated assets and makes AJAX calls to the API.
• Rails communicates with the PostgreSQL database for CRUD operations.
• Redis is used for caching and as the backing store for Sidekiq and ActionCable, with background jobs (e.g., reservation reminders, notifications) enqueued.
• External API calls (e.g., Stripe payments, OAuth token validations) occur via dedicated service classes in app/services.
• The admin subsystem (with endpoints in /admin and /admin/api) provides a backend UI for administrators.