How emcousin/pkp works
Main Components
• Rails Application (Backend): This is the core where all business logic and MVC responsibilities reside. Break this down into:
• Controllers: There are several namespaced controllers (admin, coach, dashboard, contacts, etc.) that represent different areas of the back-office interface.
• Models: The data models (e.g., user, member, subscription, course, contact) are implemented along with various concerns (extensions for devise, subscriptions, members, courses, etc.) to encapsulate business rules.
• Views: Organized by theme (admin, dashboard, devise, etc.) to generate the rendered pages.
• Services: For example, the single service “pdf_generator.rb” and other business logic that is separated outside of controllers or models.
• Channels: WebSocket channels (in app/channels) which indicate that realtime features may be supported (e.g., for live notifications or updates).
• Jobs: Background processing via job classes (notably the stripe jobs and more) that likely work with Sidekiq as indicated by the initializer and config files.
• Mailers and Mailboxes: For email notifications, confirmations, and related functionality.
• Database: Indicated by the presence of PostgreSQL configuration and migration files which form the persistent store for the data models.
• External Dependencies and Integrations:
• Redis – as seen in the prerequisites and initializer.
• Stripe – there are several initializers and jobs that manage customers, charges and subscriptions.
• Third-party libraries for background processing (Sidekiq, observed in config/initializers/sidekiq.rb and config/sidekiq.yml).
• Other external assets and tooling including Yarn, Node, and Foreman for managing multiple processes.
Relationships and Interactions
• A typical data flow starts at the browser client which hits the Rails controllers, triggering the MVC cycle (Controllers accept requests, interact with Models, and render Views).
• Background jobs (through Sidekiq) perform asynchronous tasks, like payment processing or notifications.
• The mailers generate emails for various transactions (confirmation, subscription updates, etc.) which are then delivered to users.
• Channels (using Action Cable) maintain bi-directional communication for realtime updates.
• External services (such as Stripe) are integrated via dedicated jobs and initializers, so show how the Rails app communicates with these systems.
• Caching or session management could also be highlighted if needed (through Redis).
Architectural Patterns and Design Principles
• MVC Pattern: The Rails framework’s core design separates the application logic into Models, Views, and Controllers.
• Namespacing: Different folders under controllers (admin, dashboard, coach, contacts) suggest clear segmentation according to user roles or functionality.
• Service Layer: Business logic separated into services (e.g., PDF generation) promoting a clean separation from controller logic.
• Background Processing: Use of job classes (and Sidekiq) for heavy or asynchronous tasks to keep the request/response cycle fast.
• Use of Concerns: Both models and controllers use concerns to share common behavior, which is an important design pattern in this Rails codebase.
Relevant Technologies & Frameworks
• Ruby on Rails – as the main web framework.
• PostgreSQL – for the database.
• Redis – for caching and as a data store for background job processing.
• Sidekiq – for handling background jobs.
• Stripe – for payment processing.
• Action Cable – for websockets and realtime features.
• Devise – for authentication (based on the configurations and overridden controller concerns).
• Webpack/Yarn – for handling JavaScript assets.
• Tailwind CSS – for styling (as indicated by application.tailwind.css).