# indiecodermm/comix architecture

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

- Interactive diagram: https://gitdiagram.com/indiecodermm/comix
- Repository: https://github.com/indiecodermm/comix

## Overview

##### High-Level Components

a) Client Layer:
- Next.js Frontend (app directory structure)
- Landing Page System
- Dashboard System
- Authentication Flow

b) API Layer:
- tRPC API Routes
- NextAuth Integration
- GitHub OAuth

c) Service Layer:
- GitHub Service Integration
- User Service
- Leaderboard Service
- Repository Service

d) Data Layer:
- PostgreSQL Database (with Drizzle ORM)
- Redis Cache
- External GitHub API

##### Detailed Component Breakdown

a) Frontend Architecture:
- Next.js app router structure with (landing) and (site) groups
- Feature modules (dashboard, leaderboard, stats, repo)
- Shared components and UI library
- Client-side state management

b) API Architecture:
- tRPC router structure
- API routes organization
- Authentication middleware flow
- Service integration points

c) Database Schema:
- User model
- Repository model
- Leaderboard data structure
- Redis caching layer

##### Interaction Flows

- Authentication flow with GitHub OAuth
- Data flow between frontend and backend via tRPC
- Cache interaction patterns
- GitHub API integration points
- Database read/write patterns

##### Specific Implementation Details

Technical elements:
- Feature-based directory structure
- Service layer abstraction
- Database migration system
- API route handling
- Component hierarchy

- The modular feature-based architecture
- Clear separation of concerns
- Type-safe API communication
- Caching strategy for performance
- Authentication and authorization flow
- Real-time statistics processing

Remember to:
- Use consistent styling
- Brief annotations for complex flows
- Both synchronous and asynchronous operations

This architecture represents a modern full-stack application with emphasis on type safety, performance, and scalability, which are crucial for a gamification platform tracking real-time GitHub activities.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Landing["Landing Page System"]
        Dashboard["Dashboard System"]
        Auth["Authentication Flow"]
        UI["Shared UI Components"]
    end

    subgraph API
        TRPC["tRPC API Routes"]
        NextAuth["NextAuth Integration"]
        GHOAuth["GitHub OAuth"]
    end

    subgraph Services
        GHS["GitHub Service"]
        US["User Service"]
        LS["Leaderboard Service"]
        RS["Repository Service"]
    end

    subgraph Data
        PG[(PostgreSQL)]
        Redis[(Redis Cache)]
        GHA["GitHub API"]
    end

    %% Client Layer Details
    Landing --> TRPC
    Dashboard --> TRPC
    Auth --> NextAuth
    NextAuth --> GHOAuth

    %% API Layer Connections
    TRPC --> GHS
    TRPC --> US
    TRPC --> LS
    TRPC --> RS

    %% Service Layer Connections
    GHS --> GHA
    GHS --> Redis
    US --> PG
    LS --> PG
    LS --> Redis
    RS --> PG
    RS --> GHA

    %% Data Layer Connections
    PG --> US
    Redis --> GHS
    GHA --> GHS

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white

    class Landing,Dashboard,Auth,UI frontend
    class TRPC,NextAuth,GHOAuth api
    class GHS,US,LS,RS service
    class PG,Redis database
    class GHA external

    %% Click Events
    click Landing "https://github.com/IndieCoderMM/comix/tree/dev/app/(landing)"
    click Dashboard "https://github.com/IndieCoderMM/comix/tree/dev/app/(site)/dashboard"
    click Auth "https://github.com/IndieCoderMM/comix/blob/dev/app/api/auth/[...nextauth]/route.ts"
    click TRPC "https://github.com/IndieCoderMM/comix/blob/dev/app/api/trpc/[trpc]/route.ts"
    click UI "https://github.com/IndieCoderMM/comix/tree/dev/components/ui"
    click GHS "https://github.com/IndieCoderMM/comix/blob/dev/services/github/index.ts"
    click US "https://github.com/IndieCoderMM/comix/blob/dev/services/user/index.ts"
    click LS "https://github.com/IndieCoderMM/comix/blob/dev/services/leaderboard/index.ts"
    click RS "https://github.com/IndieCoderMM/comix/blob/dev/services/repo/index.ts"
    click PG "https://github.com/IndieCoderMM/comix/blob/dev/db/db.ts"
    click Redis "https://github.com/IndieCoderMM/comix/blob/dev/lib/redis.ts"
```
