Skip to content

marisanasser/Nexa_BackEnd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

362 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nexa Backend

Laravel 10 REST API backend for the Nexa platform, providing authentication, campaign management, real-time chat, payment processing, and administrative features.

📋 Table of Contents

🎯 Overview

The Nexa Backend is built with Laravel 10 and provides a comprehensive REST API for:

  • User authentication and authorization (Laravel Sanctum)
  • Campaign creation and management
  • Real-time chat functionality (Laravel Reverb)
  • Payment processing (Stripe integration)
  • Admin dashboard and user management
  • Portfolio management for creators
  • Contract and offer management
  • Student verification system

✨ Features

Core Features

  • Authentication & Authorization

    • Email/password authentication
    • Google OAuth integration
    • Role-based access control (Admin, Creator, Brand, Student)
    • Account status management (Active, Blocked, Removed)
    • Password reset functionality
  • Campaign Management

    • Campaign creation and editing
    • Campaign approval workflow
    • Bid management
    • Campaign applications
    • Campaign timeline tracking
  • Real-time Chat

    • Reverb integration
    • Message history
    • Typing indicators
    • Read receipts
    • File attachments
  • Payment Processing

    • Stripe payment integration
    • Subscription management
    • Withdrawal processing
    • Payment method management
    • Automatic payment processing
  • Admin Features

    • Dashboard with metrics
    • User management (Creators, Brands, Students)
    • Campaign approval/rejection
    • Guide management
    • Brand rankings
    • Withdrawal verification
  • Additional Features

    • Portfolio management
    • Contract management
    • Offer system
    • Review system
    • Notification system
    • Student verification
    • Guide system

📦 Requirements

  • PHP >= 8.1 with extensions:
    • BCMath, Ctype, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML
  • PostgreSQL >= 13 (Supabase recomendado)
  • Redis (for caching and queues)

🚀 Installation

  1. Install PHP dependencies:

    composer install
  2. Copy environment file:

    cp .env.example .env
  3. Generate application key:

    php artisan key:generate
  4. Create storage link:

    php artisan storage:link
  5. Set up storage directories:

    php artisan storage:setup-directories

⚙️ Configuration

Environment Variables

Edit .env file with your configuration:

# Application
APP_NAME="Nexa Platform"
APP_ENV=local
APP_KEY=base64:... # Generated by php artisan key:generate
APP_DEBUG=true
APP_URL=http://localhost:8000
APP_TIMEZONE=UTC

# Database (PostgreSQL / Supabase)
DB_CONNECTION=pgsql
DB_HOST=your-supabase-host.supabase.co
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=your-password

# Redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

# Mail (AWS SES)
MAIL_MAILER=ses
MAIL_FROM_ADDRESS=noreply@nexacreators.com.br
MAIL_FROM_NAME="${APP_NAME}"

# AWS Configuration
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_DEFAULT_REGION=us-east-1
AWS_SES_REGION=us-east-1

# Stripe
STRIPE_SECRET=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret

# Pusher (optional, for broadcasting)
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

# Session & Cache
SESSION_DRIVER=redis
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis

# Sanctum
SANCTUM_STATEFUL_DOMAINS=localhost:5173,localhost:3000
SESSION_DOMAIN=localhost

🗄️ Database Setup

  1. Create the database:

    CREATE DATABASE nexa_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  2. Run migrations:

    php artisan migrate
  3. Seed the database (optional):

    php artisan db:seed

🔌 Real-time (Laravel Reverb)

O Nexa utiliza Laravel Reverb para funcionalidades em tempo real (Chat).

Running Reverb

Development:

php artisan reverb:start --debug

Production:

php artisan reverb:start

Para mais detalhes sobre a configuração, consulte a documentação oficial do Laravel Reverb.

📚 API Documentation

Base URL

http://localhost:8000/api

Authentication

All protected routes require a Bearer token in the Authorization header:

Authorization: Bearer {token}

Main API Endpoints

Authentication

  • POST /api/login - User login
  • POST /api/register - User registration
  • POST /api/logout - User logout
  • POST /api/forgot-password - Request password reset
  • POST /api/reset-password - Reset password
  • GET /api/auth/google - Google OAuth redirect
  • GET /api/auth/google/callback - Google OAuth callback

Campaigns

  • GET /api/campaigns - List campaigns
  • POST /api/campaigns - Create campaign
  • GET /api/campaigns/{id} - Get campaign details
  • PUT /api/campaigns/{id} - Update campaign
  • DELETE /api/campaigns/{id} - Delete campaign
  • POST /api/campaigns/{id}/apply - Apply to campaign
  • GET /api/campaigns/{id}/bids - Get campaign bids

Chat

  • GET /api/chat/rooms - Get user's chat rooms
  • GET /api/chat/rooms/{roomId}/messages - Get messages
  • POST /api/chat/rooms - Create chat room
  • POST /api/chat/messages - Send message
  • POST /api/chat/mark-read - Mark messages as read

Payments

  • POST /api/payment/process - Process payment
  • POST /api/stripe/create-payment-intent - Create Stripe payment intent
  • POST /api/stripe/webhook - Stripe webhook handler
  • GET /api/subscription/plans - Get subscription plans

💻 Development

Common Commands

# Run migrations
php artisan migrate

# Rollback last migration
php artisan migrate:rollback

# Create new migration
php artisan make:migration create_table_name

# Run seeders
php artisan db:seed

# Clear cache
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

# Optimize for production
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Generate IDE helper
php artisan ide-helper:generate
php artisan ide-helper:models
php artisan ide-helper:meta

Code Structure

The backend follows a Simplified Domain-Driven Design (DDD) architecture. For a detailed guide, see ARCHITECTURE.md.

app/
├── Domain/                # Core Business Logic (DDD)
│   ├── Campaign/          # Campaign Domain (Services, Actions)
│   ├── Payment/           # Payment Domain
│   ├── Contract/          # Contract Domain
│   └── Notification/      # Notification Domain
├── Http/
│   ├── Controllers/       # API Controllers (grouped by Domain)
│   │   ├── Auth/
│   │   ├── Campaign/
│   │   └── Payment/
├── Models/                # Eloquent Models (grouped by Domain)
│   ├── User/
│   ├── Campaign/
│   └── Payment/

database/ ├── migrations/ # Database migrations ├── seeders/ # Database seeders └── factories/ # Model factories

routes/ ├── api.php # API routes └── auth.php # Authentication routes

config/ # Configuration files storage/ # File storage public/ # Public assets


## 🧪 Testing

```bash
# Run all tests
php artisan test

# Run specific test file
php artisan test tests/Feature/AdminControllerTest.php

# Run with coverage
php artisan test --coverage

🚢 Deployment

Production Checklist

  1. Environment Configuration:

    APP_ENV=production
    APP_DEBUG=false
  2. Optimize Application:

    php artisan config:cache
    ...
  3. Run Migrations:

    php artisan migrate --force

Server Requirements

  • PHP 8.1+ with required extensions
  • Composer
  • PostgreSQL 13+
  • Redis
  • Web server (Nginx/Apache)
  • SSL certificate (for HTTPS)

🔒 Security

  • All API routes are protected with Laravel Sanctum
  • Admin routes require admin role middleware
  • Rate limiting on authentication routes
  • CSRF protection for web routes
  • Input validation on all requests
  • SQL injection protection via Eloquent ORM
  • XSS protection via Blade templating

📝 License

This project is licensed under the MIT License.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Write tests
  5. Submit a pull request

📞 Support

For issues and questions, please open an issue on the repository.


Note: Certifique-se de configurar todas as variáveis de ambiente no arquivo .env. O Laravel Reverb deve estar rodando para as funcionalidades de chat em tempo real funcionarem.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages