# phanthanhbach/social-network-app architecture

> Architecture diagram of the GitHub repository phanthanhbach/social-network-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phanthanhbach/social-network-app
- Repository: https://github.com/phanthanhbach/social-network-app

## Overview

##### Project Type and Purpose
- This is a Flutter-based social network application. The project supports multiple platforms (Android, iOS, Web, Linux, macOS, Windows), indicating a full-stack mobile and desktop cross-platform application.
- Its purpose is to allow users to authenticate, post content, and interact with posts/users, given the multiple BLoC implementations (authentication, sign in/up, posts management) and the separate repositories for posts and users.

##### Analyzing the File Structure
- Top-level Directories: Notice that the project contains a root “social_network_app” folder with platform-specific directories (android, ios, linux, macos, windows) – meaning the app is built to run on several platforms.
- The “lib” directory holds the core Flutter/Dart code, including:
– screens (UI components for authentication and home),
– blocs (state management for authentication, posting, user details, etc.),
– components (reusable UI elements like text fields and post input).
- The “packages” folder defines standalone modules (post_repository and user_repository) that encapsulate data logic, entities, models, and repository services.
- Configuration files (pubspec.yaml, analysis_options.yaml, various .gitignore files) ensure proper setup for building, testing, and deploying the app on different platforms.

##### Key Architectural Components
- UI Layer (Frontend):
– Flutter Screens: Authentication screens (sign in, sign up, welcome) and Home screens (home_screen, post_screen).
– Reusable Components: Text fields and home page components like post_text_field.
- Business Logic Layer:
– BLoC Implementations: Different blocs manage authentication (sign in, sign up, update user info) and post operations (create_post_bloc, get_posts_bloc). These handle state management and coordinate between UI and data.
- Data Layer/Repositories:
– Post Repository and User Repository (found in the “packages” folder): These abstract access to the backend services and data models/entities. They likely interface with an external service (e.g., Firebase, as hinted by the google-services.json file in the Android folder).
- Platform-Specific Layers:
– Directories like android, ios, etc. represent native wrappers and settings that allow the cross-platform Flutter app to run on these environments.

##### Relationships and Interactions
- The UI layer (screens and components) interacts with the Business Logic via BLoC events and state changes.
- BLoCs are the intermediaries that process user interactions and then trigger calls to the data repositories.
- The repositories (post_repository and user_repository) encapsulate the data access logic, including communicating with remote APIs or services (for example, Firebase) and performing CRUD operations.
- Platform-specific directories serve as containers that enable the cross-platform Flutter app to integrate with system-specific capabilities and configurations.

##### Architectural Patterns & Technologies
- Utilized Patterns: The project uses the BLoC (Business Logic Component) pattern extensively for state management.
- Component Separation: Clear separation between the presentation layer (UI in lib/screens and lib/components), business logic (lib/blocs), and data layer (packages for repositories), following best practices for maintainability and testability.
- Technologies: Flutter framework, Dart, potential integration with Firebase (as seen in android’s google-services.json), and platform-specific native code for iOS, Android, etc.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer (Screens and Components)"
        UI_Screens["Screens - Authentication & Home"]:::ui
        UI_Components["UI Components - Reusable Widgets"]:::ui
    end

    %% Business Logic Layer (BLoCs)
    subgraph "Business Logic Layer (BLoCs)"
        AuthenticationBLO["Authentication BLoC"]:::bloc
        SignInBLO["Sign In BLoC"]:::bloc
        SignUpBLO["Sign Up BLoC"]:::bloc
        MyUserBLO["My User BLoC"]:::bloc
        UpdateUserInfoBLO["Update User Info BLoC"]:::bloc
        CreatePostBLO["Create Post BLoC"]:::bloc
        GetPostsBLO["Get Posts BLoC"]:::bloc
    end

    %% Data Layer (Repositories)
    subgraph "Data Layer (Repositories)"
        PostRepo["Post Repository"]:::repo
        UserRepo["User Repository"]:::repo
        ExternalService["Firebase (External Service)"]:::external
    end

    %% Platform-Specific Integrations
    subgraph "Platform-Specific Integrations"
        Android["Android"]:::platform
        iOS["iOS"]:::platform
        Linux["Linux"]:::platform
        macOS["macOS"]:::platform
        Windows["Windows"]:::platform
        Web["Web"]:::platform
    end

    %% UI interactions with BLoCs
    UI_Screens -->|"triggers"| AuthenticationBLO
    UI_Screens -->|"triggers"| SignInBLO
    UI_Screens -->|"triggers"| SignUpBLO
    UI_Screens -->|"triggers"| CreatePostBLO
    UI_Screens -->|"triggers"| GetPostsBLO
    UI_Components -->|"used_in"| UI_Screens

    %% BLoCs interactions with Repositories
    AuthenticationBLO -->|"calls"| UserRepo
    SignInBLO -->|"calls"| UserRepo
    SignUpBLO -->|"calls"| UserRepo
    MyUserBLO -->|"calls"| UserRepo
    UpdateUserInfoBLO -->|"calls"| UserRepo
    CreatePostBLO -->|"calls"| PostRepo
    GetPostsBLO -->|"calls"| PostRepo

    %% Repositories interactions with External Service
    PostRepo -->|"syncs_with"| ExternalService
    UserRepo -->|"syncs_with"| ExternalService

    %% UI deployment on Platforms
    UI_Screens -->|"deployed_on"| Android
    UI_Screens -->|"deployed_on"| iOS
    UI_Screens -->|"deployed_on"| Linux
    UI_Screens -->|"deployed_on"| macOS
    UI_Screens -->|"deployed_on"| Windows
    UI_Screens -->|"deployed_on"| Web

    %% Click Events
    click UI_Screens "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/screens"
    click UI_Components "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/components"
    click AuthenticationBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/authentication_bloc"
    click SignInBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/sign_in_bloc"
    click SignUpBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/sign_up_bloc"
    click MyUserBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/my_user_bloc"
    click UpdateUserInfoBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/update_user_info_bloc"
    click CreatePostBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/create_post_bloc"
    click GetPostsBLO "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/lib/blocs/get_posts_bloc"
    click PostRepo "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/packages/post_repository"
    click UserRepo "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/packages/user_repository"
    click Android "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/android"
    click iOS "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/ios"
    click Linux "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/linux"
    click macOS "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/macos"
    click Windows "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/windows"
    click Web "https://github.com/phanthanhbach/social-network-app/tree/main/social_network_app/web"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef bloc fill:#a5d6a7,stroke:#388e3c,stroke-width:2px;
    classDef repo fill:#ffe082,stroke:#f9a825,stroke-width:2px;
    classDef platform fill:#ce93d8,stroke:#8e24aa,stroke-width:2px;
    classDef external fill:#ef9a9a,stroke:#e53935,stroke-width:2px;
```
