# commune-ai/app architecture

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

- Interactive diagram: https://gitdiagram.com/commune-ai/app
- Repository: https://github.com/commune-ai/app

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (Main client-side application)
- Component Structure
- Client-side Routing
- State Management

B. Backend Layer:
- Python API
- User Management System
- Utility Services

C. External Integrations:
- Wallet Integration
- Discord Widget Integration
- ComHub Widget Integration

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- (Next.js, React Components, Client Routing) │
- ┤
- Service Layer                 │
- (Python API, Authentication)        │
- ┤
- External Services              │
- (Wallet, Discord, ComHub Integration)   │
- ┘

##### Detailed Component Breakdown

- Auth Components (AuthModal, WalletModal)
- UI Components (Header, Footer, BackgroundEffects)
- Feature Sections (Hero, CallToAction, FrequentQuestions)
- Integration Widgets (DiscordWidget, ComHubWidget)

- API Routes (/api/api.py)
- User Management (/api/user.py)
- Utility Functions (/api/utils.py)

- Wallet Integration
- Discord Services
- ComHub Services

##### Connection Flows

- Client-to-API communications
- Authentication flows
- External service interactions
- Data flow between components

##### Additional Details

Annotations for:
- Environment configurations (.env)
- Build and deployment processes (Dockerfile, scripts/)
- Static assets handling (public/)
- Styling approach (tailwind.config.ts)

Remember to emphasize:
- The Next.js app structure and routing system
- The separation between frontend components and backend API
- The integration points with external services
- The authentication and wallet management flow
- The modular component structure

This will provide a clear understanding of the system's architecture while maintaining the necessary level of detail for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer (Port 3000)"]
        direction TB
        NextApp["Next.js Application"]:::frontend
        click NextApp "https://github.com/commune-ai/app/blob/main/app/app/layout.tsx"
        
        subgraph FrontendComponents["Frontend Components"]
            direction TB
            Auth["Authentication Modal"]:::frontend
            click Auth "https://github.com/commune-ai/app/blob/main/app/app/components/AuthModal/index.tsx"
            
            Wallet["Wallet Integration"]:::frontend
            click Wallet "https://github.com/commune-ai/app/blob/main/app/app/components/WalletModal/index.tsx"
            
            UI["UI Components"]:::frontend
            click UI "https://github.com/commune-ai/app/blob/main/app/app/components/Header/header.component.tsx"
            
            Modules["Module Management"]:::frontend
            click Modules "https://github.com/commune-ai/app/blob/main/app/app/modules/page.tsx"
            
            ClientAPI["Client API Handler"]:::frontend
            click ClientAPI "https://github.com/commune-ai/app/blob/main/app/app/client.ts"
        end
        
        RootPage["Root Page"]:::frontend
        click RootPage "https://github.com/commune-ai/app/blob/main/app/app/page.tsx"
    end
    
    subgraph Server["Server Layer (Port 8000)"]
        direction TB
        FastAPI["FastAPI Backend"]:::backend
        click FastAPI "https://github.com/commune-ai/app/blob/main/api/api.py"
        
        APIRoutes["API Routes"]:::backend
        UserMgmt["User Management"]:::backend
        click UserMgmt "https://github.com/commune-ai/app/blob/main/api/user.py"
        
        Utils["Utility Functions"]:::backend
        click Utils "https://github.com/commune-ai/app/blob/main/api/utils.py"
    end
    
    subgraph Storage["Storage Layer"]
        direction TB
        FileSystem["Local File System"]:::storage
    end
    
    subgraph Docker["Docker Environment"]
        direction TB
        DockerConfig["Docker Configuration"]:::docker
        click DockerConfig "https://github.com/commune-ai/app/tree/main/Dockerfile"
        
        Scripts["Runtime Scripts"]:::docker
        click Scripts "https://github.com/commune-ai/app/blob/main/run/start.sh"
    end
    
    %% Relationships
    NextApp --> FrontendComponents
    FrontendComponents --> ClientAPI
    ClientAPI --> FastAPI
    FastAPI --> APIRoutes
    FastAPI --> UserMgmt
    FastAPI --> Utils
    FastAPI --> FileSystem
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef backend fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef storage fill:#f1c40f,stroke:#f39c12,color:#000
    classDef docker fill:#9b59b6,stroke:#8e44ad,color:#fff
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Store["Storage Component"]:::storage
        Container["Docker Component"]:::docker
    end
```
