# guidotss/millonario-o-piramidal architecture

> Architecture diagram of the GitHub repository guidotss/millonario-o-piramidal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/guidotss/millonario-o-piramidal
- Repository: https://github.com/guidotss/millonario-o-piramidal

## Overview

##### Project Type and Purpose
- The project is a modern full-stack web application that leverages Next.js 14, React, and TypeScript for the frontend and uses Supabase for backend functionalities (authentication and database storage). Its purpose is to analyze startup ideas using AI – evaluating whether an idea is viable or potentially a scam – and it offers different subscription plans (Free and Pro).

##### Analyzing the File Structure
- Top-level files: In addition to configuration files (e.g., .gitignore, next.config.ts, package.json, tsconfig.json), noteworthy files include the README and a template environment file.
- src Directory: Contains all application code:
- app/ Folder: Implements Next.js pages and layouts. It is divided into routes such as:
a. (auth): Contains login, register pages along with actions and components (e.g., register-form.tsx)
b. dashboard: Provides a dashboard view with its own logic and actions.
c. pro: Contains pro components, actions, and pages for users who upgrade their plan.
- components/ Folder: Includes UI components built using shadcn/ui (e.g., badge, button, card, etc.). These components are used across the application.
- lib/ Folder: Holds utilities such as environment utilities (env.ts), hooks (for registration, toast notifications), Supabase client integration, and other helper functions.
- store/ Folder: Contains state management code (using Zustand) focused on managing user state.
- Middleware and Routing: The presence of src/app/middleware.ts indicates route protection or session management before serving pages.

##### Insights from the README
- The README describes the features of IdeaDetector 3000 – including the core analysis functionality using AI, secure authentication, modern UI, and subscription-based usage.
- The README also clarifies the division of the application into frontend and backend aspects, where server actions and Supabase serve as the back-end services.
- It explicitly lists the technologies in use, which is important to note in the overall architecture.

a. And List Main Components:
- Frontend:
- Next.js Application: With pages for authentication, dashboard, and pro features.
- React Components: UI components (using Shadcn/ui) and layouts handled in src/app and src/components.
- Zustand Store: For managing user state (located in src/store).
- Backend:
- Server Actions: Handling logic and server-side operations (embedded in Next.js actions files within each route).
- Supabase: Handling authentication, database storage (using src/lib/supabase-client.ts and environment variables).
- OpenAI API: Interacting with external AI services for idea analysis (managed via environment configurations).
- External Elements:
- Third-party services: Supabase for authentication/data & OpenAI for AI-powered idea analysis.
- Payment Systems: Implied within the pro upgrade process (though integration details might be abstracted).
- Other Components:
- Middleware: For authentication route protection.
- Utility libraries: Provided in src/lib for hooks and other helper functions.

b. Relationships and Interactions:
- The Frontend interacts with backend server actions to carry out business logic (submit ideas, handle registration, etc.)
- The UI communicates with the Zustand store to manage and persist user states (login status, subscription status).
- API calls from the server interact with Supabase to handle authentication and persist data securely.
- The idea analysis feature involves sending the idea input to the OpenAI API and returning a processed result back to the UI.

c. Architectural Patterns and Design Principles:
- Modular Separation: Clearly defined modules for routes (auth, dashboard, pro) enhance maintainability.
- MVC-like Pattern: Although not a strict MVC, the separation of view components (UI components), business logic (actions and server actions), and data access (Supabase integration) is evident.
- Client-Server Separation: Even though Next.js bridges the gap, the architecture cleanly separates the client-side rendering and server processing.
- State Management: Use of Zustand highlights unidirectional data flow within client-side components.

d. Relevant Technologies and Frameworks:
- Next.js 14, React, TypeScript, Tailwind CSS – denote modern frontend stack.
- Shadcn/ui – for reusable and styled UI components.
- Supabase – for authentication and database backend service.
- Zustand – for state management.
- OpenAI API – as the external AI service for idea analysis.

##### Being Detailed and Comprehensive
- The goal is to capture as many essential architectural elements as possible. It is beneficial to break down the application into its core components: UI/UX, business logic, backend integration, state management, and external services.
- Although it doesn’t have to cover every file, ensure major workflows (such as registering, logging in, idea analysis, subscription upgrade) are clearly represented by showing both entry points and data flows.

## Diagram (Mermaid)

```mermaid
graph TD
    User("User"):::external
    User -->|"accesses"| NextApp("Next.js Application"):::frontend

    subgraph "Frontend Components"
        NextApp -->|"routes"| Auth("Auth Routes & Components"):::frontend
        NextApp -->|"routes"| Dash("Dashboard Functionality"):::frontend
        NextApp -->|"routes"| Pro("Pro Features (Subscription Upgrade)"):::frontend
        NextApp -->|"renders"| UI("UI Components (Shadcn/ui based)"):::frontend
        NextApp -->|"manages"| Store("State Management (Zustand User Store)"):::frontend
    end

    Auth -->|"via"| Middleware("Middleware"):::backend
    Dash -->|"via"| Middleware
    Pro  -->|"via"| Middleware

    subgraph "Server Actions"
        Middleware -->|"triggers"| AuthA("Auth Actions"):::backend
        Middleware -->|"triggers"| DashA("Dashboard Actions"):::backend
        Middleware -->|"triggers"| ProA("Pro Actions"):::backend
    end

    AuthA -->|"interacts"| Supabase("Supabase Integration"):::backend
    DashA -->|"interacts"| Supabase
    ProA  -->|"interacts"| Supabase

    AuthA -->|"uses"| Utility("Utility Functions & Env Configurations"):::backend
    DashA -->|"uses"| Utility
    ProA  -->|"uses"| Utility

    AuthA -->|"calls"| OpenAI("OpenAI Integration"):::external
    DashA -->|"calls"| OpenAI
    ProA  -->|"calls"| OpenAI

    UI -->|"updates"| Store

    %% Click Events
    click NextApp "https://github.com/guidotss/millonario-o-piramidal/tree/main/src/app"
    click Auth "https://github.com/guidotss/millonario-o-piramidal/tree/main/src/app/(auth)"
    click Dash "https://github.com/guidotss/millonario-o-piramidal/tree/main/src/app/dashboard"
    click Pro "https://github.com/guidotss/millonario-o-piramidal/tree/main/src/app/pro"
    click UI "https://github.com/guidotss/millonario-o-piramidal/tree/main/src/components/ui"
    click Store "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/store/use-user-store.ts"
    click AuthA "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/app/(auth)/actions.ts"
    click DashA "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/app/dashboard/actions.ts"
    click ProA "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/app/pro/actions.ts"
    click Middleware "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/app/middleware.ts"
    click Supabase "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/lib/supabase-client.ts"
    click Utility "https://github.com/guidotss/millonario-o-piramidal/blob/main/src/lib/env.ts"

    %% Styles
    classDef frontend fill:#c3f7ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef external fill:#fadbd8,stroke:#333,stroke-width:2px;
```
