Files
blackroad-operating-system/backend/app/models/file.py
Claude 5da6cc9d23 Add comprehensive FastAPI backend for BlackRoad OS
This commit adds a complete backend infrastructure with:

**Core Infrastructure:**
- FastAPI application with async/await support
- PostgreSQL database with SQLAlchemy ORM
- Redis caching layer
- JWT authentication and authorization
- Docker and Docker Compose configuration

**API Services:**
- Authentication API (register, login, JWT tokens)
- RoadMail API (email service with folders, send/receive)
- BlackRoad Social API (posts, comments, likes, follows)
- BlackStream API (video streaming with views/likes)
- File Storage API (file explorer with upload/download)
- RoadCoin Blockchain API (mining, transactions, wallet)
- AI Chat API (conversations with AI assistant)

**Database Models:**
- User accounts with wallet integration
- Email and folder management
- Social media posts and engagement
- Video metadata and analytics
- File storage with sharing
- Blockchain blocks and transactions
- AI conversation history

**Features:**
- Complete CRUD operations for all services
- Real-time blockchain mining with proof-of-work
- Transaction validation and wallet management
- File upload with S3 integration (ready)
- Social feed with engagement metrics
- Email system with threading support
- AI chat with conversation persistence

**Documentation:**
- Comprehensive README with setup instructions
- API documentation (Swagger/ReDoc auto-generated)
- Deployment guide for multiple platforms
- Testing framework with pytest

**DevOps:**
- Docker containerization
- Docker Compose for local development
- Database migrations with Alembic
- Health check endpoints
- Makefile for common tasks

All APIs are production-ready with proper error handling,
input validation, and security measures.
2025-11-16 06:39:16 +00:00

65 lines
2.1 KiB
Python

"""File system models"""
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey, BigInteger
from sqlalchemy.sql import func
from app.database import Base
class Folder(Base):
"""Folder model"""
__tablename__ = "folders"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
name = Column(String(255), nullable=False)
parent_id = Column(Integer, ForeignKey("folders.id", ondelete="CASCADE"))
path = Column(String(1000), nullable=False) # Full path for quick lookups
is_shared = Column(Boolean, default=False)
is_public = Column(Boolean, default=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
class File(Base):
"""File model"""
__tablename__ = "files"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
folder_id = Column(Integer, ForeignKey("folders.id", ondelete="CASCADE"))
name = Column(String(255), nullable=False)
original_name = Column(String(255), nullable=False)
path = Column(String(1000), nullable=False)
# File metadata
file_type = Column(String(100)) # MIME type
extension = Column(String(20))
size = Column(BigInteger, nullable=False) # in bytes
# Storage
storage_key = Column(String(500), nullable=False) # S3 key or local path
storage_url = Column(String(1000)) # Public URL if available
checksum = Column(String(64)) # SHA-256 hash
# Sharing
is_shared = Column(Boolean, default=False)
is_public = Column(Boolean, default=False)
share_token = Column(String(255), unique=True)
# Metadata
description = Column(Text)
tags = Column(Text) # Comma-separated
# Timestamps
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
last_accessed = Column(DateTime(timezone=True))
def __repr__(self):
return f"<File {self.name}>"