diff --git a/docs/architecture.md b/docs/architecture.md index 8e4188b..963657b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,61 +1,28 @@ -Cette conversation a été générée avec Duck.ai (https://duck.ai) à l'aide du modèle Mistral Small 3 d'Mistral AI. Les chats IA peuvent afficher des informations inexactes ou offensantes (voir https://duckduckgo.com/duckai/privacy-terms pour en savoir plus). +# Aperonight - Technical Architecture -==================== +## Overview -Message 1 sur 6 de l'utilisateur - 16/08/2025, 08:29:15: -For a git Ruby on Rails web project with the the goal to propose night parties in Paris and allow party maker to create their own parties. +Aperonight is a Ruby on Rails web application designed for proposing night parties in Paris and allowing party makers to create their own events. The application serves two primary user groups: -The application for customers must: -* shows parties (upcoming and past) -* permit user to book one or many tickets for a party (choosing their bundle : simple entry, 4 people pass with bottle, VIP, etc) -* accept credit cards, paypal, bank account payments -* generate unique tickets (per person or per order -* be able to be used on mobile to permit promotors to scan tickets using phone +### For Customers: +- View upcoming and past parties +- Book tickets with customizable bundles (simple entry, VIP, group passes, etc.) +- Complete secure payments via credit card, PayPal, or bank transfer +- Access mobile-friendly interface for ticket management +- Receive unique, scannable tickets (QR codes) -For promotors: -* allow them to create and program parties -* aggregate parties from other website (shogun, bizouk, weezevent) +### For Promoters: +- Create and schedule parties +- Define custom ticket bundles and pricing +- Aggregate events from external platforms (Shogun, Bizouk, Weezevent) +- Scan tickets at events using mobile devices -Give advices on this application and give the arhitecture to implement. +## Technical Architecture -Mistral Small 3: -Creating a Ruby on Rails web application for proposing night parties in Paris and allowing party makers to create their own parties is an exciting project. Below are some advices and an architecture to implement this application. - -### Advices - -1. **User Authentication and Authorization**: - - Use Devise for user authentication. - - Use Pundit or CanCanCan for authorization to manage different roles (customers, promoters). - -2. **Payment Integration**: - - Use Stripe for credit card payments. - - Use PayPal for PayPal payments. - - For bank account payments, consider integrating with a service like Plaid or directly with a banking API. - -3. **Ticket Generation**: - - Generate unique tickets using a combination of UUIDs and QR codes. - - Use a library like `rufus-scheduler` to handle ticket expiration and validation. - -4. **Mobile Compatibility**: - - Ensure the application is responsive and mobile-friendly. - - Use a library like `qrcode` to generate QR codes for tickets. - - For scanning tickets, use a mobile-friendly QR code scanner library like `zxing` or `html5-qrcode`. - -5. **Aggregation of Parties**: - - Use web scraping or APIs provided by other websites (Shogun, Bizouk, Weezevent) to aggregate parties. - - Consider using a background job processor like Sidekiq for periodic data aggregation. - -6. **Performance and Scalability**: - - Use caching mechanisms like Redis or Memcached to improve performance. - - Consider using a CDN for static assets. - - Implement background jobs for time-consuming tasks like sending emails or processing payments. - -### Architecture - -#### 1. **Database Schema** +### 1. Database Schema ```ruby -# User +# User - Handles both customers and promoters create_table :users do |t| t.string :email t.string :password_digest @@ -63,7 +30,7 @@ create_table :users do |t| t.timestamps end -# Party +# Party - Events created by promoters create_table :parties do |t| t.string :name t.text :description @@ -74,18 +41,27 @@ create_table :parties do |t| t.timestamps end -# Ticket +# TicketType - Customizable bundles defined by promoters +create_table :ticket_types do |t| + t.string :name + t.text :description + t.decimal :price + t.integer :party_id + t.timestamps +end + +# Ticket - Individual ticket instances purchased by customers create_table :tickets do |t| t.string :uuid t.string :qr_code t.integer :party_id t.integer :user_id - t.string :bundle_type # simple entry, 4 people pass with bottle, VIP, etc + t.integer :ticket_type_id t.boolean :used, default: false t.timestamps end -# Payment +# Payment - Transaction records for ticket purchases create_table :payments do |t| t.string :payment_method # credit_card, paypal, bank_account t.string :transaction_id @@ -96,116 +72,7 @@ create_table :payments do |t| end ``` -#### 2. **Models** - -```ruby -class User < ApplicationRecord - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :validatable - has_many :tickets - has_many :payments -end - -class Party < ApplicationRecord - belongs_to :promoter, class_name: 'User' - has_many :tickets -end - -class Ticket < ApplicationRecord - belongs_to :party - belongs_to :user - has_one :payment - - before_create :generate_uuid_and_qr_code - - private - - def generate_uuid_and_qr_code - self.uuid = SecureRandom.uuid - self.qr_code = RQRCode::QRCode.new(self.uuid).as_svg - end -end - -class Payment < ApplicationRecord - belongs_to :user - belongs_to :ticket -end -``` - -#### 3. **Controllers** - -```ruby -class PartiesController < ApplicationController - before_action :authenticate_user! - before_action :set_party, only: [:show, :edit, :update, :destroy] - - def index - @parties = Party.all - end - - def show - end - - def new - @party = Party.new - end - - def create - @party = current_user.parties.build(party_params) - if @party.save - redirect_to @party, notice: 'Party was successfully created.' - else - render :new - end - end - - def edit - end - - def update - if @party.update(party_params) - redirect_to @party, notice: 'Party was successfully updated.' - else - render :edit - end - end - - def destroy - @party.destroy - redirect_to parties_url, notice: 'Party was successfully destroyed.' - end - - private - - def set_party - @party = Party.find(params[:id]) - end - - def party_params - params.require(:party).permit - --------------------- - -Message 2 sur 6 de l'utilisateur - 16/08/2025, 08:30:32: -For the bundles, promotors must be able to define their own for party they craete - -Mistral Small 3: -To allow promoters to define their own bundles for the parties they create, you need to introduce a `Bundle` model that will be associated with the `Party` model. This will enable promoters to create custom bundles for each party, specifying details like the bundle type, price, and any additional perks. - -### Updated Database Schema - -```ruby -# Bundle -create_table :bundles do |t| - t.string :name - t.text :description - t.decimal :price - t.integer :party_id - t.timestamps -end -``` - -### Updated Models +### 2. Core Models ```ruby class User < ApplicationRecord @@ -219,13 +86,18 @@ end class Party < ApplicationRecord belongs_to :promoter, class_name: 'User' has_many :tickets - has_many :bundles + has_many :ticket_types +end + +class TicketType < ApplicationRecord + belongs_to :party + has_many :tickets end class Ticket < ApplicationRecord belongs_to :party belongs_to :user - belongs_to :bundle + belongs_to :ticket_type has_one :payment before_create :generate_uuid_and_qr_code @@ -241,18 +113,33 @@ end class Payment < ApplicationRecord belongs_to :user belongs_to :ticket -end -class Bundle < ApplicationRecord - belongs_to :party - has_many :tickets + enum payment_method: { + credit_card: 'credit_card', + paypal: 'paypal', + bank_account: 'bank_account' + } + + after_create :process_payment + + private + + def process_payment + case self.payment_method + when 'credit_card' + process_stripe_payment + when 'paypal' + process_paypal_payment + when 'bank_account' + process_bank_account_payment + end + end end ``` -### Updated Controllers - -#### PartiesController +### 3. Key Controllers +#### Parties Controller ```ruby class PartiesController < ApplicationController before_action :authenticate_user! @@ -263,12 +150,12 @@ class PartiesController < ApplicationController end def show - @bundles = @party.bundles + @ticket_types = @party.ticket_types end def new @party = Party.new - @party.bundles.build + @party.ticket_types.build end def create @@ -280,23 +167,6 @@ class PartiesController < ApplicationController end end - def edit - @bundles = @party.bundles - end - - def update - if @party.update(party_params) - redirect_to @party, notice: 'Party was successfully updated.' - else - render :edit - end - end - - def destroy - @party.destroy - redirect_to parties_url, notice: 'Party was successfully destroyed.' - end - private def set_party @@ -304,206 +174,15 @@ class PartiesController < ApplicationController end def party_params - params.require(:party).permit(:name, :description, :start_time, :end_time, :location, bundles_attributes: [:id, :name, :description, :price, :_destroy]) + params.require(:party).permit( + :name, :description, :start_time, :end_time, :location, + ticket_types_attributes: [:id, :name, :description, :price, :_destroy] + ) end end ``` -#### BundlesController - -```ruby -class BundlesController < ApplicationController - before_action :authenticate_user! - before_action :set_bundle, only: [:show, :edit, :update, :destroy] - - def index - @bundles = Bundle.all - end - - def show - end - - def new - @bundle = Bundle.new - end - - def create - @bundle = Bundle.new(bundle_params) - if @bundle.save - redirect_to @bundle, notice: 'Bundle was successfully created.' - else - render :new - end - end - - def edit - end - - def update - if @bundle.update(bundle_params) - redirect_to @bundle, notice: 'Bundle was successfully updated.' - else - render :edit - end - end - - def destroy - @bundle.destroy - redirect_to bundles_url, notice: 'Bundle was successfully destroyed.' - end - - private - - def set_bundle - @bundle = Bundle.find(params[:id]) - end - - def bundle_params - params.require(:bundle).permit(:name, :description, :price, :party_id) - end -end -``` - -### Views - -#### parties/_form.html.erb - -```erb -<%= form_with(model: party, local: true) do |form| %> - <% if party.errors.any? %> -
-

<%= pluralize(party.errors.count, "error") %> prohibited this party from being saved:

-