# croco-dev/darun architecture

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

- Interactive diagram: https://gitdiagram.com/croco-dev/darun
- Repository: https://github.com/croco-dev/darun

## Overview

##### High-Level Architecture Components

a. Frontend Layer:
- Service Web Application (Next.js)
- Admin Web Application (Next.js)
- Shared UI Components and Utilities

b. Backend Layer:
- GraphQL API (Serverless)
- Domain Services
- Database Layers (PostgreSQL and MongoDB indicated by repositories)

c. Shared Infrastructure:
- Authentication (Firebase)
- Storage Services
- Monitoring (Sentry)

##### Detailed Component Breakdown

a. Apps Layer (Top Level):

- Service Web   |    |   Admin Web   |
- (Next.js)    |    |   (Next.js)   |

- ↓                    ↓

- ↓

- GraphQL API   |
- (Serverless)  |

b. Domain Layer (Middle):

- Products   |  | Companies  |  |    Search    |
- Domain    |  |  Domain    |  |    Domain    |

- ↓              ↓               ↓

- Data Access Layer            |
- (PostgreSQL + MongoDB Repositories)   |

c. Shared Infrastructure (Cross-cutting):

- Authentication  |  |    Storage     |
- (Firebase)    |  |    Service    |

- ↓                   ↓

- Shared Utilities          |
- (Apollo, Router, UI, etc.)      |

##### Important Details

a. Technology Stack Annotations:
- Next.js for web applications
- GraphQL for API
- PostgreSQL for main database
- MongoDB for search functionality
- Firebase for authentication
- Serverless deployment

b. Key Infrastructure Components:
- Apollo Client/Server
- Domain-driven design structure
- Shared UI component library
- Authentication providers

##### Additional Elements

Important aspects:
- Environment configurations
- Build/deployment workflows
- Monitoring and logging
- Security boundaries
- Scalability points

- Applications (apps/)
- Business Logic (libs/backend/)
- Frontend Components (libs/frontend/)
- Shared Utilities (libs/shared/)

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this system unique, such as its domain-driven design approach and the separation of concerns between service and admin applications.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef domain fill:#f1c40f,color:black
    classDef database fill:#95a5a6,color:white
    classDef infrastructure fill:#7f8c8d,color:white
    classDef security fill:#e74c3c,color:white
    classDef shared fill:#9b59b6,color:white

    %% Frontend Layer
    subgraph Applications
        ServiceWeb["Service Web\n(Next.js)"]
        AdminWeb["Admin Web\n(Next.js)"]
    end

    %% Frontend Components
    subgraph FrontendComponents
        UIFoundation["UI Foundation"]
        UIIcons["UI Icons"]
        UILayout["UI Layout"]
        FrontendProducts["Frontend Products"]
        FrontendSearch["Frontend Search"]
        AdminComponents["Admin Components"]
    end

    %% API Layer
    GraphQLAPI["GraphQL API\n(Serverless)"]

    %% Domain Layer
    subgraph DomainServices
        Products["Products Domain"]
        Companies["Companies Domain"]
        Search["Search Domain"]
        Voting["Voting Domain"]
    end

    %% Infrastructure
    subgraph Infrastructure
        AuthClient["Auth Client"]
        AuthServer["Auth Server"]
        ApolloClient["Apollo Client"]
        ApolloServer["Apollo Server"]
        Monitoring["Sentry Monitoring"]
    end

    %% Database Layer
    Database[(Database Layer)]

    %% Relationships
    ServiceWeb --> GraphQLAPI
    AdminWeb --> GraphQLAPI
    GraphQLAPI --> DomainServices
    DomainServices --> Database
    ServiceWeb --> FrontendComponents
    AdminWeb --> FrontendComponents
    GraphQLAPI --> Infrastructure
    ServiceWeb --> Infrastructure
    AdminWeb --> Infrastructure

    %% Click events
    click ServiceWeb "https://github.com/croco-dev/darun/tree/trunk/apps/service-web"
    click AdminWeb "https://github.com/croco-dev/darun/tree/trunk/apps/admin-web"
    click GraphQLAPI "https://github.com/croco-dev/darun/tree/trunk/apps/graphql-api"
    click Products "https://github.com/croco-dev/darun/tree/trunk/libs/backend/src/libs/products"
    click Companies "https://github.com/croco-dev/darun/tree/trunk/libs/backend/src/libs/companies"
    click Search "https://github.com/croco-dev/darun/tree/trunk/libs/backend/src/libs/search"
    click Voting "https://github.com/croco-dev/darun/tree/trunk/libs/backend/src/libs/voting"
    click Database "https://github.com/croco-dev/darun/tree/trunk/libs/shared/provider-database"
    click AuthClient "https://github.com/croco-dev/darun/tree/trunk/libs/shared/provider-auth/client"
    click AuthServer "https://github.com/croco-dev/darun/tree/trunk/libs/shared/provider-auth/server"
    click ApolloClient "https://github.com/croco-dev/darun/tree/trunk/libs/shared/utils-apollo-client"
    click ApolloServer "https://github.com/croco-dev/darun/tree/trunk/libs/shared/utils-apollo-server"
    click UIFoundation "https://github.com/croco-dev/darun/tree/trunk/libs/shared/ui-foundation"
    click UIIcons "https://github.com/croco-dev/darun/tree/trunk/libs/shared/ui-icons"
    click UILayout "https://github.com/croco-dev/darun/tree/trunk/libs/shared/ui-layout"
    click Monitoring "https://github.com/croco-dev/darun/tree/trunk/libs/shared/utils-sentry"
    click FrontendProducts "https://github.com/croco-dev/darun/tree/trunk/libs/frontend/src/libs/products"
    click FrontendSearch "https://github.com/croco-dev/darun/tree/trunk/libs/frontend/src/libs/search"
    click AdminComponents "https://github.com/croco-dev/darun/tree/trunk/libs/admin/src/libs"

    %% Styling
    class ServiceWeb,AdminWeb frontend
    class GraphQLAPI backend
    class Products,Companies,Search,Voting domain
    class Database database
    class AuthClient,AuthServer security
    class ApolloClient,ApolloServer,Monitoring infrastructure
    class UIFoundation,UIIcons,UILayout,FrontendProducts,FrontendSearch,AdminComponents shared
```
