# juaneduardo-dev/blogger-app-backend architecture

> Architecture diagram of the GitHub repository juaneduardo-dev/blogger-app-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/juaneduardo-dev/blogger-app-backend
- Repository: https://github.com/juaneduardo-dev/blogger-app-backend

## Overview

##### Project’s Main Components
- API Layer: Represented by the “routes” directory. This includes endpoints for handling user actions (user_routes.py), managing publications (publication_routes.py), and processing reactions (reaction_routes.py).
- Business Logic Layer: The “services” directory hosts modules that encapsulate the business logic (e.g., publication_service.py, reaction_service.py, user_service.py).
- Data Layer: This is comprised of the “models” directory (containing database representations for degrees, pages, publications, tags, reactions, and users) plus “schemas” (for serialization/deserialization/validation).
- Configuration: Under “app/config” you have the database connection setup (contained in database.py), ensuring that the backend can correctly interact with a PostgreSQL database.
- Application Bootstrapping: The main entry point (app/main.py) which initializes and wires up the application.

##### Relationships and Interactions
- The API endpoints in the routes layer are the entry points that handle incoming HTTP requests.
- They delegate tasks to the corresponding services, which encapsulate the business rules.
- The services interact with the models to perform CRUD operations on the database.
- Schemas are used to validate the data flow between endpoints and services.
- Configuration settings, especially database connectivity, ensure that the data operations can reach a PostgreSQL database backend.

##### Architectural Patterns and Technologies
- Layered Architecture: Separation into well-defined layers (routes, services, models/schemas, config) allows for maintainability and scalability.
- Use of FastAPI as the API framework ensures high performance.
- SQLAlchemy (as inferred by the file structure and README mentioning database integration) is being used to map models to a relational database.
- PostgreSQL is the chosen relational database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interface
    subgraph "External Interface"
        client("External Clients"):::external
    end

    %% Application Bootstrapping
    subgraph "Application Bootstrapping"
        main("App Bootstrapping"):::boot
    end

    %% API Endpoints (Routes)
    subgraph "API Endpoints (Routes)"
        pubRoute("Publication Routes"):::api
        reactRoute("Reaction Routes"):::api
        userRoute("User Routes"):::api
    end

    %% Business Logic (Services)
    subgraph "Business Logic (Services)"
        pubService("Publication Service"):::service
        reactService("Reaction Service"):::service
        userService("User Service"):::service
    end

    %% Data Layer: Models and Schemas
    subgraph "Data Layer"
        subgraph "Data Models"
            degree("Degree"):::model
            page("Page"):::model
            publication("Publication"):::model
            pubTag("Publication Tag"):::model
            reaction("Reaction"):::model
            tag("Tag"):::model
            user("User"):::model
        end
        subgraph "Schemas"
            pubSchema("Publication Schema"):::schema
            reactSchema("Reaction Schema"):::schema
            userSchema("User Schema"):::schema
        end
    end

    %% Configuration and Database
    subgraph "Configuration & Database"
        dbConfig("Database Configuration"):::config
        db("PostgreSQL Database"):::database
    end

    %% Connections
    client -->|"initializes"| main
    main -->|"registers"| pubRoute
    main -->|"registers"| reactRoute
    main -->|"registers"| userRoute

    pubRoute -->|"delegates"| pubService
    reactRoute -->|"delegates"| reactService
    userRoute -->|"delegates"| userService

    pubService -->|"CRUD"| publication
    pubService -->|"validates"| pubSchema
    reactService -->|"CRUD"| reaction
    reactService -->|"validates"| reactSchema
    userService -->|"CRUD"| user
    userService -->|"validates"| userSchema

    %% Representative connection from Data Layer to Database Configuration
    publication ---|"DB operations"| dbConfig
    dbConfig ---|"connects"| db

    %% Click Events for API Endpoints
    click pubRoute "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/routes/publication_routes.py"
    click reactRoute "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/routes/reaction_routes.py"
    click userRoute "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/routes/user_routes.py"

    %% Click Events for Business Logic (Services)
    click pubService "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/services/publication_service.py"
    click reactService "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/services/reaction_service.py"
    click userService "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/services/user_service.py"

    %% Click Events for Data Models
    click degree "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/degree.py"
    click page "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/page.py"
    click publication "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/publication.py"
    click pubTag "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/publication_tag.py"
    click reaction "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/reaction.py"
    click tag "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/tag.py"
    click user "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/models/user.py"

    %% Click Events for Schemas
    click pubSchema "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/schemas/publication_schema.py"
    click reactSchema "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/schemas/reaction_schema.py"
    click userSchema "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/schemas/user_schema.py"

    %% Click Event for Database Configuration
    click dbConfig "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/config/database.py"

    %% Click Event for Application Bootstrapping
    click main "https://github.com/juaneduardo-dev/blogger-app-backend/blob/master/app/main.py"

    %% Styles
    classDef external fill:#D5DBDB,stroke:#1C2833,stroke-width:2px;
    classDef boot fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef api fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef schema fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef database fill:#F1948A,stroke:#922B21,stroke-width:2px;
```
