Plataforma de administración de inversiones con backend Rails API y frontend React.
- Backend: Rails 8 API (raíz del proyecto)
- Postgres + Devise + Google OAuth
- RSpec para testing
- Rubocop para linting
- Brakeman para security scanning
- Frontend: React + Vite + TypeScript (
ui/)- TailwindCSS para estilos
- Vitest + Testing Library para testing
- ESLint para linting
- Ruby 3.2.4 (ver
.ruby-version) - Node >= 20.x
- Postgres >= 14
- Git hooks configurados (se instalan automáticamente con
bin/setup)
git clone https://github.com/quequeo/winbit-rails.git
cd winbit-railsCrear archivo .env en la raíz (no se commitea):
# Database
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
# Google OAuth
GOOGLE_CLIENT_ID=tu_client_id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=tu_client_secret
# Rails
RAILS_MASTER_KEY=tu_master_key
# Resend (notificaciones por email)
RESEND_API_KEY=re_xxxxxxxxxxxxx
RESEND_FROM_EMAIL=Winbit <noreply@yourdomain.com>
# Frontend URL (para links en emails y redirects OAuth)
FRONTEND_URL=http://localhost:5173
# CORS (frontend permitido)
CORS_ORIGINS=http://localhost:5173,https://winbit-6579c.web.app
# App Host (para links en emails)
APP_HOST=localhost:3000# Instalar dependencias
bundle install
# Preparar base de datos
bin/rails db:prepare
bin/rails db:seed # Crea admins y datos demo
# Levantar servidor
bin/rails server -p 3000API disponible en: http://localhost:3000
cd ui
npm install
npm run devUI disponible en: http://localhost:5173
- Ir a Google Cloud Console
- Crear un proyecto o usar uno existente
- Habilitar "Google+ API"
- Crear credenciales OAuth 2.0
- Agregar URIs de redirección autorizadas:
- Local:
http://localhost:3000/users/auth/google_oauth2/callback - Producción:
https://winbit-rails-55a941b2fe50.herokuapp.com/users/auth/google_oauth2/callback
- Local:
Solo estos emails pueden acceder (definidos en db/seeds.rb):
winbit.cfds@gmail.comjaimegarciamendez@gmail.com
Para agregar más admins, crear registro en tabla users con rol ADMIN o SUPERADMIN.
# Ejecutar todos los tests
bundle exec rspec
# Ejecutar tests específicos
bundle exec rspec spec/requests/api/admin/investors_spec.rb
# Con cobertura
COVERAGE=true bundle exec rspecCobertura actual: 79.36% (173 tests, 323/407 lines)
cd ui
# Ejecutar todos los tests
npm run test
# Con cobertura
npm run test -- --coverage
# Modo watch
npm run test -- --watch
# Solo un archivo
npm run test src/pages/InvestorsPage.test.tsxCobertura actual: 85.68% (124 tests)
| Métrica | Backend (Rails) | Frontend (React) |
|---|---|---|
| Lines | 79.36% | 85.68% |
| Branches | N/A | 85.03% |
| Functions | N/A | 65.28% |
| Total Tests | 173 | 124 |
- ✅ API Service (
api.ts): 100% - ✅ Formatters (
formatters.ts): 100% - ✅ Pages: 84.53% promedio
- DashboardPage: 100%
- EditPortfolioPage: 100%
- LoginPage: 100%
- InvestorsPage: 100%
- PortfoliosPage: 100%
- RequestsPage: 97.34%
- AdminsPage: 98.41%
Winbit utiliza Resend para enviar notificaciones automáticas:
- ✅ Depósito creado, aprobado, rechazado
- ✅ Retiro creado, aprobado, rechazado
- 💰 Nuevo depósito pendiente
- 💸 Nuevo retiro pendiente
# Obtener API key en https://resend.com/api-keys
heroku config:set RESEND_API_KEY=re_xxxxxxxxxxxxx -a winbit-rails
heroku config:set RESEND_FROM_EMAIL="Winbit <noreply@yourdomain.com>" -a winbit-rails- Free tier: 3,000 emails/mes
- Estimado Winbit: ~150-200 emails/mes
- Costo real: $0/mes (dentro del free tier)
📖 Documentación completa: Ver EMAILS.md
# En Heroku
heroku run rake investors:import -a winbit-rails
# Local
bin/rails investors:importEste script actualiza portfolios con datos de capital y retornos.
# Backend
bundle exec rubocop # Lint
bundle exec rubocop -a # Auto-fix
bundle exec brakeman # Security scan
# Frontend
cd ui
npm run lint # ESLint
npm run lint:fix # Auto-fixEl proyecto tiene hooks de pre-push configurados que ejecutan automáticamente:
- ✅ Bundle check
- ✅ RSpec tests
- ✅ Rubocop lint
- ✅ Brakeman security scan
- ✅ Vitest tests
Si algún check falla, el push es rechazado. Configuración en .githooks/pre-push.
- User: Admins del sistema (ADMIN, SUPERADMIN)
- Investor: Inversores con portfolios
- Portfolio: Balance actual y retornos acumulados
- PortfolioHistory: Historial de movimientos
- InvestorRequest: Solicitudes de depósito/retiro
- Wallet: Configuración de billeteras crypto
GET /api/public/wallets- Billeteras disponiblesGET /api/public/investor/:email- Info de inversorGET /api/public/investor/:email/history- Historial de movimientosPOST /api/public/requests- Crear solicitud de depósito/retiro
- Admins:
/api/admin/admins(CRUD) - Investors:
/api/admin/investors(CRUD + sorting) - Portfolios:
/api/admin/portfolios(list, update) - Requests:
/api/admin/requests(CRUD + approve/reject) - Dashboard:
/api/admin/dashboard(estadísticas)
⚠️ IMPORTANTE: Heroku está configurado para hacer deploy automático desde el branchmainde GitHub.NO es necesario hacer
git push heroku main- solo hacergit push origin mainy Heroku se encarga del resto.
# Login
heroku login
# Agregar remote (solo para comandos heroku, no para deploy)
git remote add heroku https://git.heroku.com/winbit-rails.githeroku/nodejs- Para construir UI Reactheroku/ruby- Para Rails
heroku config:set GOOGLE_CLIENT_ID=xxx
heroku config:set GOOGLE_CLIENT_SECRET=xxx
heroku config:set RAILS_MASTER_KEY=xxx
heroku config:set NODE_ENV=productionDATABASE_URL se configura automáticamente al agregar Heroku Postgres.
# Ver logs
heroku logs --tail -a winbit-rails
# Ejecutar migraciones
heroku run rails db:migrate -a winbit-rails
# Importar datos
heroku run rake investors:import -a winbit-rails
# Console
heroku run rails console -a winbit-rails# En rails console
User.create!(
email: 'nuevo@ejemplo.com',
name: 'Nuevo Admin',
role: 'ADMIN'
)# En rails console
investor = Investor.create!(
email: 'test@ejemplo.com',
name: 'Inversor Test',
status: 'ACTIVE'
)
Portfolio.create!(
investor: investor,
current_balance: 10000,
total_invested: 10000,
accumulated_return_usd: 0,
accumulated_return_percent: 0,
annual_return_usd: 0,
annual_return_percent: 0
)# Verificar que Postgres está corriendo
pg_isready
# Verificar variables de entorno
echo $POSTGRES_HOSTVerificar que las URIs en Google Cloud Console coincidan exactamente:
- Local:
http://localhost:3000/users/auth/google_oauth2/callback - Producción:
https://tu-app.herokuapp.com/users/auth/google_oauth2/callback
# Ejecutar tests manualmente para ver detalles
bundle exec rspec
cd ui && npm run test:runPrivado - Winbit