Skip to content

Sacobrt/SocialMediaAPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SocialMediaAPP πŸ“±

A full-stack social media application built with ASP.NET Core Web API and React, featuring user management, posts, comments, followers, and comprehensive statistics with network visualization.

πŸš€ Features

Core Functionality

  • User Management: Complete CRUD operations for user accounts with authentication
  • Posts & Comments: Create, read, update, and delete posts with nested commenting system
  • Follower System: Follow/unfollow users with relationship tracking
  • Authentication: JWT-based authentication with secure password hashing (BCrypt)
  • Statistics Dashboard: Interactive charts and network graphs showing user engagement
  • Image Management: User profile image upload and management
  • Pagination: Efficient data loading with search and filtering capabilities

Advanced Features

  • Network Graph Visualization: Interactive network showing user relationships
  • Statistics Charts: Highcharts integration for data visualization
  • Cyclic Data Generation: Special controller for generating test data patterns
  • Real-time Updates: Dynamic content loading with infinite scroll
  • Responsive Design: Mobile-first approach with Tailwind CSS
  • WYSIWYG Editor: Rich text editing for posts and comments

πŸ—οΈ Architecture

Backend (.NET 8)

  • Framework: ASP.NET Core Web API 8.0
  • Database: SQL Server with Entity Framework Core 9.0.2
  • Authentication: JWT Bearer tokens with custom security implementation
  • API Documentation: Swagger/OpenAPI 3.0 with comprehensive documentation
  • Data Mapping: AutoMapper for DTO transformations
  • Password Security: BCrypt.Net for secure password hashing
  • CORS: Configured for cross-origin requests

Frontend (React 18)

  • Framework: React 18.3.1 with Vite build tool
  • Routing: React Router DOM 6.30.0
  • Styling: Tailwind CSS 4.0.11 with custom components
  • HTTP Client: Axios with interceptors for authentication
  • Charts: Highcharts React for data visualization
  • Text Editor: React Draft WYSIWYG for rich content creation
  • UI Components: Headless UI with Heroicons
  • Utilities: Moment.js for date handling, React CountUp for animations

πŸ“Š Database Schema

Core Entities

Users
β”œβ”€β”€ ID (Primary Key)
β”œβ”€β”€ Username
β”œβ”€β”€ Password (BCrypt hashed)
β”œβ”€β”€ Email
β”œβ”€β”€ FirstName, LastName
β”œβ”€β”€ BirthDate
β”œβ”€β”€ CreatedAt
└── Image (Profile picture)

Posts
β”œβ”€β”€ ID (Primary Key)
β”œβ”€β”€ UserID (Foreign Key β†’ Users)
β”œβ”€β”€ Content (Rich text)
β”œβ”€β”€ Likes
β”œβ”€β”€ CreatedAt
└── Comments (One-to-Many)

Comments
β”œβ”€β”€ ID (Primary Key)
β”œβ”€β”€ UserID (Foreign Key β†’ Users)
β”œβ”€β”€ PostID (Foreign Key β†’ Posts)
β”œβ”€β”€ Content
β”œβ”€β”€ Likes
└── CreatedAt

Followers
β”œβ”€β”€ ID (Primary Key)
β”œβ”€β”€ UserID (Foreign Key β†’ Users) - Being followed
β”œβ”€β”€ FollowerUserID (Foreign Key β†’ Users) - Following
└── FollowedAt

Operators
β”œβ”€β”€ ID (Primary Key)
β”œβ”€β”€ UserID (Foreign Key β†’ Users)
β”œβ”€β”€ Email
└── Password (System administrators)

πŸ”§ API Endpoints

Authentication

  • POST /api/v1/Authorization/token - Generate JWT token

Users

  • GET /api/v1/User - Get all users
  • GET /api/v1/User/{id} - Get user by ID
  • POST /api/v1/User - Create new user (public)
  • PUT /api/v1/User/{id} - Update user
  • DELETE /api/v1/User/{id} - Delete user
  • GET /api/v1/User/pagination/{page} - Paginated users with search
  • POST /api/v1/User/{id}/setImage - Upload profile image
  • GET /api/v1/User/generate/{amount} - Generate test users

Posts

  • GET /api/v1/Post - Get all posts with comments
  • GET /api/v1/Post/{id} - Get specific post
  • POST /api/v1/Post - Create new post
  • PUT /api/v1/Post/{id} - Update post
  • DELETE /api/v1/Post/{id} - Delete post
  • GET /api/v1/Post/pagination/{page} - Paginated posts with search
  • GET /api/v1/Post/generate/{amount} - Generate test posts

Comments

  • GET /api/v1/Comment - Get all comments
  • GET /api/v1/Comment/{id} - Get specific comment
  • POST /api/v1/Comment - Create new comment
  • PUT /api/v1/Comment/{id} - Update comment
  • DELETE /api/v1/Comment/{id} - Delete comment
  • GET /api/v1/Comment/pagination/{page} - Paginated comments

Followers

  • GET /api/v1/Follower - Get all follower relationships
  • POST /api/v1/Follower - Create follow relationship
  • DELETE /api/v1/Follower/{id} - Unfollow user
  • GET /api/v1/Follower/followStatuses - Check follow status
  • GET /api/v1/Follower/pagination/{page} - Paginated followers

Statistics

  • GET /api/v1/Statistics/totalData - Get total counts
  • GET /api/v1/Statistics/topUserStats - Get top user statistics
  • GET /api/v1/Statistics/randomUsers - Get random user data
  • GET /api/v1/Statistics/pagination/{page} - Paginated statistics

πŸ› οΈ Setup Instructions

Prerequisites

  • .NET 8.0 SDK
  • Node.js 18+ and npm/bun
  • SQL Server (LocalDB or full instance)
  • Visual Studio 2022 or VS Code

Backend Setup

  1. Clone the repository

    git clone https://github.com/Sacobrt/SocialMediaAPP.git
    cd SocialMediaAPP/Backend
  2. Configure Database

    • Update appsettings.json with your SQL Server connection string
    • Run the database creation script: socialMedia.sql
  3. Install Dependencies

    dotnet restore
  4. Run the Application

    dotnet run
    • API will be available at https://localhost:7256
    • Swagger documentation at https://localhost:7256/swagger
    • Frontend will also start automatically and be available at http://localhost:5173

Frontend Setup

  1. Navigate to Frontend Directory

    cd SocialMediaAPP/Frontend
  2. Install Dependencies

    # Using npm
    npm install
    
    # Using bun (recommended)
    bun install
  3. Configure API URL

    • Update src/constants.js with your backend URL if different
  4. Run Development Server

    # Using npm
    npm run dev
    
    # Using bun
    bun run dev
    • Frontend will be available at http://localhost:5173

Production Build

# Frontend
bun run build

# This automatically moves built files to Backend/wwwroot
# Backend serves both API and frontend in production

πŸ” Authentication & Security

JWT Implementation

  • Token Generation: 8-hour expiration with secure HMAC SHA256 signing
  • Claims: UserID, Username, Email, FirstName, LastName, Image
  • Security: BCrypt password hashing with salt rounds

Authorization Levels

  • Public Endpoints: User registration, token generation
  • Authenticated Endpoints: All CRUD operations require valid JWT
  • Operator System: Special admin accounts for system management

CORS Configuration

  • Configured for development and production environments
  • Allows all origins, methods, and headers in development
  • Restrictive settings recommended for production

πŸ“ˆ Statistics & Analytics

Dashboard Features

  • Total Counts: Users, Posts, Comments with animated counters
  • Most Liked Content: Interactive column charts
  • User Activity: Recent user registrations timeline
  • Network Graph: Interactive visualization of user relationships
  • Top Users: Statistics on most active users

Data Visualization

  • Highcharts Integration: Professional charting library
  • Interactive Elements: Hover effects, clickable data points
  • Responsive Design: Charts adapt to screen size
  • Real-time Updates: Data refreshes automatically

πŸ”„ Data Management

Pagination System

  • Configurable Page Sizes: Default 20 items per page
  • Search Filtering: Full-text search across relevant fields
  • Sorting Options: Multiple sort criteria support
  • Performance Optimized: Efficient database queries with Entity Framework

Test Data Generation

  • Faker.Net Integration: Realistic test data generation
  • Bulk Operations: Generate hundreds of users, posts, comments
  • Relationship Maintenance: Proper foreign key relationships
  • Development Support: Quick setup for testing and development

🎨 Frontend Architecture

Component Structure

src/
β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”œβ”€β”€ AuthContext.jsx  # Authentication context
β”‚   β”œβ”€β”€ NavBar.jsx       # Navigation component
β”‚   β”œβ”€β”€ NetworkGraph.jsx # D3.js network visualization
β”‚   └── TotalData.jsx    # Statistics display
β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   β”œβ”€β”€ useAuth.js       # Authentication management
β”‚   β”œβ”€β”€ useError.js      # Error handling
β”‚   └── parseJwt.js      # JWT token parsing
β”œβ”€β”€ pages/               # Route components
β”‚   β”œβ”€β”€ users/           # User management pages
β”‚   β”œβ”€β”€ posts/           # Post management pages
β”‚   β”œβ”€β”€ comments/        # Comment management pages
β”‚   β”œβ”€β”€ followers/       # Follower management pages
β”‚   └── Statistics.jsx   # Analytics dashboard
└── services/            # API communication
    β”œβ”€β”€ HttpService.js   # Axios configuration
    β”œβ”€β”€ AuthService.js   # Authentication API
    └── *Service.js      # Entity-specific APIs

State Management

  • React Context: Authentication and error state
  • Local Storage: JWT token persistence
  • Component State: UI-specific state management
  • HTTP Interceptors: Automatic token attachment and error handling

πŸš€ Deployment

Development Environment

  • Backend: https://localhost:7256
  • Frontend: http://localhost:5173
  • Database: SQL Server LocalDB

Production Environment

  • Static Files: Served from Backend wwwroot
  • SPA Support: Fallback routing for client-side navigation
  • HTTPS: Enforced for security

Build Process

  1. Frontend builds to dist/ directory
  2. Build script moves files to Backend/wwwroot/
  3. Backend serves both API and static files
  4. Single deployment artifact

πŸ“ API Documentation

Swagger Integration

  • Comprehensive Documentation: All endpoints documented with examples
  • Authentication Support: JWT token testing interface
  • Multiple Environments: Development and production server configurations

Response Formats

  • Success Responses: Consistent JSON structure with data
  • Error Responses: Standardized error messages with HTTP status codes
  • Validation: Model state validation with detailed error messages

πŸ§ͺ Testing & Development

Data Generation

  • Realistic Data: Faker.Net generates authentic-looking test data
  • Bulk Operations: Generate thousands of records quickly
  • Relationship Integrity: Maintains proper foreign key relationships
  • Development Seeding: Pre-populated data for immediate testing

Development Tools

  • Hot Reload: Both frontend and backend support hot reload
  • API Explorer: Swagger UI for API testing
  • Network Inspector: Browser dev tools for request monitoring
  • Error Handling: Comprehensive error boundaries and logging

πŸ“„ License

This project is licensed under the MIT License - suitable for educational and commercial use.

πŸ‘¨β€πŸ’» Author

About

Edunova - final work for web programming education

Resources

Stars

Watchers

Forks

Languages