# ozyirl/igclone architecture

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

- Interactive diagram: https://gitdiagram.com/ozyirl/igclone
- Repository: https://github.com/ozyirl/igclone

## Overview

##### Project Type and Purpose
- This is a modern full-stack application generated via the T3 Stack (using create-t3-app). The README explicitly mentions that it uses technologies such as Next.js, NextAuth.js, Drizzle (an ORM), Tailwind CSS, and tRPC.
- The project is built on Next.js’s new App Directory convention, leveraging server components and API routes that tie into backend services (authentication, database access etc.).

##### Main Components
a. Frontend (Client Side):
- Next.js Application: Represent the “src/app” folder where layout components (layout.tsx, page.tsx, etc.) and specific feature pages (post, user, modal) are structured.
- UI and Presentational Components: Include the components in “src/_Components” and “src/components/ui”. They cover aspects like layout, navigation (NavBar), theme support (theme-provider) and interactive elements (buttons, dialogues).
- Styling: Indicate Tailwind CSS (tailwind.config.ts, globals.css) integration that supports UI styling.

b. Backend / API Layer:
- API Endpoints: The “src/app/api” directory contains several route handlers (e.g., caption, checkUser, createUser, like, postComment, etc.) that manage requests from the frontend.
- Server Logic: The “src/server” folder encompasses authentication (auth.ts), database connections, and query logic (queries.ts, db/index.ts, schema.ts). This layer handles business logic and database interactions.
- Database Management: Include the “drizzle” folder (and drizzle.config.ts) which contains migration files (SQL migrations, snapshots) and ORM schema definitions used to manage the database.
- Integration with External Services: The “uploadthing” endpoint in “src/app/api/uploadthing” shows integration with a file upload or media processing service.

##### Key Relationships and Data Flows
- A browser (client) interacts with the Next.js frontend, which is built as a collection of React components styled with Tailwind CSS.
- The frontend makes HTTP/API calls (often via tRPC or REST routes as indicated in “src/app/api”) to the backend.
- API route handlers trigger server-side operations, utilize authentication (from NextAuth.js as suggested in the README and server/auth.ts) and execute business logic.
- These API routes interact with the database using Drizzle (with migration scripts in the “drizzle” directory and DB configuration in “src/server/db”).
- Any file uploads or dynamic media handling go through specialized endpoints (uploadthing), which may communicate with third-party services.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project distinguishes between UI components, API layer logic, and database/server routines.
- Modular Design: Directory structure (e.g., “src/app/api” for endpoints, “src/server” for core business logic) enables modularity and easier testing and scaling.
- Component Reuse: With a well-structured UI components library (in “src/components/ui” and “src/_Components”), the design promotes reuse and consistency.
- API-First Approach: Clearly defined API routes that communicate with client-side components, likely using tRPC (mentioned in the README), streamline data flow.
- Use of Modern Build Tools and Configurations: With configuration files such as next.config.js, eslint configuration, prettier config, etc., the project emphasizes maintainability and code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Next.js Frontend"
        pages_layout("Pages & Layout"):::frontend
        ui_components_1("UI Components (_Components)"):::frontend
        ui_components_2("UI Components (components/ui)"):::frontend
        tailwind_config("Tailwind Config"):::frontend
        globals_css("Globals CSS"):::frontend
    end

    subgraph "API & Server"
        api_endpoints("API Endpoints"):::api
        server_logic("Server Logic"):::api
        uploadthing_api("Uploadthing API"):::external
    end

    subgraph "Database"
        database("Database (Drizzle ORM)"):::db
        db_management("Database Management"):::db
    end

    %% Connections
    pages_layout -->|"HTTPcalls"| api_endpoints
    api_endpoints -->|"triggers"| server_logic
    server_logic -->|"queries"| database
    server_logic -->|"manages"| db_management
    api_endpoints -->|"upload"| uploadthing_api

    %% Click Events
    click pages_layout "https://github.com/ozyirl/igclone/tree/main/src/app"
    click ui_components_1 "https://github.com/ozyirl/igclone/tree/main/src/_Components"
    click ui_components_2 "https://github.com/ozyirl/igclone/tree/main/src/components/ui"
    click tailwind_config "https://github.com/ozyirl/igclone/blob/main/tailwind.config.ts"
    click globals_css "https://github.com/ozyirl/igclone/blob/main/src/styles/globals.css"
    click api_endpoints "https://github.com/ozyirl/igclone/tree/main/src/app/api"
    click server_logic "https://github.com/ozyirl/igclone/tree/main/src/server"
    click db_management "https://github.com/ozyirl/igclone/tree/main/drizzle"
    click uploadthing_api "https://github.com/ozyirl/igclone/tree/main/src/app/api/uploadthing"

    %% Styles
    classDef frontend fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef api fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef db fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef external fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
```
