feat: initial commit — HermesMessages SaaS platform
Backend (FastAPI + Python 3.12): - Multi-tenant auth with JWT: login, register, refresh, Meta OAuth - Business & BusinessConfig management - WhatsApp webhook with HMAC signature verification - Bot engine powered by Claude AI - Calendar availability with Redis caching - Reservations CRUD with status management - Dashboard analytics (stats, agenda, peak hours) - Billing & plan management - Admin panel with platform-wide stats - Async bcrypt via asyncio.to_thread - IntegrityError handling for concurrent registration race conditions Frontend (React 18 + Vite + Tailwind CSS): - Multi-step guided registration form with helper text on every field - Login page with show/hide password toggle - Protected routes with AuthContext - Dashboard with stats cards, bar chart, and daily agenda - Reservations list with search, filters, and inline status actions - Calendar with weekly view, slot availability, and date blocking - Config page: business info, schedules, bot personality - Billing page with plan comparison and usage bar Design system: - Bricolage Grotesque + DM Sans typography - Emerald primary palette with semantic color tokens - scale(0.97) button press feedback, ease-out animations - Skeleton loaders, stagger animations, prefers-reduced-motion support - Accessible: aria-labels, visible focus rings, 4.5:1 contrast Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
0
backend/app/modules/business/__init__.py
Normal file
0
backend/app/modules/business/__init__.py
Normal file
65
backend/app/modules/business/models.py
Normal file
65
backend/app/modules/business/models.py
Normal file
@ -0,0 +1,65 @@
|
||||
from datetime import date, time
|
||||
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Date,
|
||||
Enum,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Time,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import ARRAY
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Business(Base):
|
||||
__tablename__ = "businesses"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False)
|
||||
type = Column(String, nullable=False)
|
||||
timezone = Column(String, nullable=False, default="UTC")
|
||||
status = Column(
|
||||
Enum("trial", "active", "suspended", name="business_status"),
|
||||
nullable=False,
|
||||
default="trial",
|
||||
)
|
||||
plan = Column(
|
||||
Enum("free", "basic", "pro", name="business_plan"),
|
||||
nullable=False,
|
||||
default="free",
|
||||
)
|
||||
meta_business_id = Column(String, nullable=True)
|
||||
whatsapp_phone_number_id = Column(String, nullable=True, unique=True)
|
||||
whatsapp_access_token = Column(String, nullable=True)
|
||||
created_at = Column(Date, server_default=func.current_date())
|
||||
|
||||
users = relationship("User", back_populates="business", cascade="all, delete-orphan")
|
||||
config = relationship("BusinessConfig", back_populates="business", uselist=False)
|
||||
reservations = relationship("Reservation", back_populates="business")
|
||||
|
||||
|
||||
class BusinessConfig(Base):
|
||||
__tablename__ = "business_configs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
business_id = Column(
|
||||
Integer, ForeignKey("businesses.id", ondelete="CASCADE"), nullable=False, unique=True
|
||||
)
|
||||
open_days = Column(ARRAY(Integer), nullable=False, default=list)
|
||||
open_time = Column(Time, nullable=False, default=time(9, 0))
|
||||
close_time = Column(Time, nullable=False, default=time(18, 0))
|
||||
slot_duration = Column(Integer, nullable=False, default=60)
|
||||
max_per_slot = Column(Integer, nullable=False, default=1)
|
||||
blocked_dates = Column(ARRAY(Date), nullable=False, default=list)
|
||||
assistant_name = Column(String, nullable=False, default="Hermes")
|
||||
tone = Column(
|
||||
Enum("formal", "casual", name="assistant_tone"), nullable=False, default="formal"
|
||||
)
|
||||
welcome_message = Column(String, nullable=True)
|
||||
|
||||
business = relationship("Business", back_populates="config")
|
||||
42
backend/app/modules/business/router.py
Normal file
42
backend/app/modules/business/router.py
Normal file
@ -0,0 +1,42 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.dependencies import get_current_business, get_current_user
|
||||
from app.modules.business import schemas, service
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/me", response_model=schemas.BusinessRead)
|
||||
async def get_my_business(
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_business(db, business_id)
|
||||
|
||||
|
||||
@router.put("/me", response_model=schemas.BusinessRead)
|
||||
async def update_my_business(
|
||||
body: schemas.BusinessUpdate,
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.update_business(db, business_id, body)
|
||||
|
||||
|
||||
@router.get("/me/config", response_model=schemas.BusinessConfigRead)
|
||||
async def get_my_config(
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_business_config(db, business_id)
|
||||
|
||||
|
||||
@router.put("/me/config", response_model=schemas.BusinessConfigRead)
|
||||
async def update_my_config(
|
||||
body: schemas.BusinessConfigUpdate,
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.update_business_config(db, business_id, body)
|
||||
48
backend/app/modules/business/schemas.py
Normal file
48
backend/app/modules/business/schemas.py
Normal file
@ -0,0 +1,48 @@
|
||||
from datetime import date, time
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BusinessRead(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
type: str
|
||||
timezone: str
|
||||
status: str
|
||||
plan: str
|
||||
meta_business_id: str | None
|
||||
whatsapp_phone_number_id: str | None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class BusinessUpdate(BaseModel):
|
||||
name: str | None = None
|
||||
type: str | None = None
|
||||
timezone: str | None = None
|
||||
|
||||
|
||||
class BusinessConfigRead(BaseModel):
|
||||
open_days: list[int]
|
||||
open_time: time
|
||||
close_time: time
|
||||
slot_duration: int
|
||||
max_per_slot: int
|
||||
blocked_dates: list[date]
|
||||
assistant_name: str
|
||||
tone: str
|
||||
welcome_message: str | None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class BusinessConfigUpdate(BaseModel):
|
||||
open_days: list[int] | None = None
|
||||
open_time: time | None = None
|
||||
close_time: time | None = None
|
||||
slot_duration: int | None = None
|
||||
max_per_slot: int | None = None
|
||||
blocked_dates: list[date] | None = None
|
||||
assistant_name: str | None = None
|
||||
tone: str | None = None
|
||||
welcome_message: str | None = None
|
||||
49
backend/app/modules/business/service.py
Normal file
49
backend/app/modules/business/service.py
Normal file
@ -0,0 +1,49 @@
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.modules.business.models import Business, BusinessConfig
|
||||
from app.modules.business.schemas import BusinessConfigUpdate, BusinessUpdate
|
||||
|
||||
|
||||
async def get_business(db: AsyncSession, business_id: int) -> Business:
|
||||
result = await db.execute(select(Business).where(Business.id == business_id))
|
||||
business = result.scalar_one_or_none()
|
||||
if not business:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Negocio no encontrado")
|
||||
return business
|
||||
|
||||
|
||||
async def update_business(
|
||||
db: AsyncSession, business_id: int, data: BusinessUpdate
|
||||
) -> Business:
|
||||
business = await get_business(db, business_id)
|
||||
for field, value in data.model_dump(exclude_none=True).items():
|
||||
setattr(business, field, value)
|
||||
await db.commit()
|
||||
await db.refresh(business)
|
||||
return business
|
||||
|
||||
|
||||
async def get_business_config(db: AsyncSession, business_id: int) -> BusinessConfig:
|
||||
result = await db.execute(
|
||||
select(BusinessConfig).where(BusinessConfig.business_id == business_id)
|
||||
)
|
||||
config = result.scalar_one_or_none()
|
||||
if not config:
|
||||
config = BusinessConfig(business_id=business_id)
|
||||
db.add(config)
|
||||
await db.commit()
|
||||
await db.refresh(config)
|
||||
return config
|
||||
|
||||
|
||||
async def update_business_config(
|
||||
db: AsyncSession, business_id: int, data: BusinessConfigUpdate
|
||||
) -> BusinessConfig:
|
||||
config = await get_business_config(db, business_id)
|
||||
for field, value in data.model_dump(exclude_none=True).items():
|
||||
setattr(config, field, value)
|
||||
await db.commit()
|
||||
await db.refresh(config)
|
||||
return config
|
||||
Reference in New Issue
Block a user