Implements complete FastAPI backend infrastructure for MoreThanADiagnosis with:
Core Infrastructure:
- FastAPI application with CORS, error handling, health checks
- SQLAlchemy ORM with PostgreSQL support
- Pydantic configuration management
- Docker & Docker Compose for production deployment
Database Models (7 MVPs + Auth):
- User, Profile, Role, Consent (identity)
- RefreshToken, AuthAuditLog (authentication)
- ForumCategory, ForumThread, ForumPost, ForumReaction, ForumReport (forum)
- BlogPost (blog)
- PodcastEpisode (podcast)
- Resource (resources)
- TributeEntry (tribute)
- MerchProduct, Order, OrderItem (merch)
API Endpoints (Alphabetical MVPs):
- /api/v1/blog - Blog posts (list, get)
- /api/v1/forum - Categories, threads, posts, reactions, reports
- /api/v1/merch - Products, orders
- /api/v1/podcast - Episodes
- /api/v1/profiles - User profiles
- /api/v1/resources - Knowledge base
- /api/v1/tribute - Memorials
- /api/v1/health - Health checks
Configuration & Deployment:
- .env.example for configuration
- Dockerfile with multi-stage build
- docker-compose.yml for PostgreSQL + Redis + API
- Production-ready on nexus-vector with port 8000
- Non-root user, health checks, security best practices
Dependencies:
- FastAPI, SQLAlchemy, Pydantic
- PostgreSQL, Redis
- Testing (pytest), Security (passlib, python-jose)
- Full requirements.txt with 30+ packages
Status: Foundation complete, MVP endpoint stubs ready
Next: Database migrations, authentication implementation
Job ID: MTAD-IMPL-2025-11-18-CL
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
"""
|
|
Authentication models - RefreshToken and AuthAuditLog.
|
|
|
|
Job ID: MTAD-IMPL-2025-11-18-CL
|
|
"""
|
|
|
|
from sqlalchemy import Column, String, DateTime, ForeignKey, Integer
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.database import Base
|
|
|
|
|
|
class RefreshToken(Base):
|
|
"""Refresh Token entity - Session management."""
|
|
|
|
__tablename__ = "refresh_tokens"
|
|
|
|
id = Column(String(36), primary_key=True, index=True)
|
|
user_id = Column(String(36), ForeignKey("users.id"), index=True, nullable=False)
|
|
token_hash = Column(String(255), unique=True, nullable=False)
|
|
expires_at = Column(DateTime, nullable=False, index=True)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
revoked_at = Column(DateTime, nullable=True)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="refresh_tokens")
|
|
|
|
|
|
class AuthAuditLog(Base):
|
|
"""Auth Audit Log - Compliance and security auditing."""
|
|
|
|
__tablename__ = "auth_audit_logs"
|
|
|
|
id = Column(String(36), primary_key=True, index=True)
|
|
user_id = Column(String(36), ForeignKey("users.id"), index=True, nullable=True)
|
|
event_type = Column(String(50), index=True, nullable=False) # signup, login_success, login_fail, password_reset, mfa_enable, etc.
|
|
ip_address = Column(String(45), nullable=True)
|
|
user_agent = Column(String(500), nullable=True)
|
|
created_at = Column(DateTime, server_default=func.now(), index=True)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="audit_logs")
|