How gkanawati/anunx works
Project Type and Purpose
• This is a full-stack web application (“Anunx – Anúncios Online”) built on Next.js.
• It offers user authentication (Next-Auth + Google OAuth), CRUD operations for product listings, image uploads (Cloudinary), and data persistence in MongoDB Atlas.
• The same Next.js codebase powers both the client-side rendering (React/Material-UI) and the backend API routes (Node.js + Express-style controllers + Mongoose).
File-Structure & Architectural Patterns
Top-Level Directories
• pages/ – Next.js pages (UI + API endpoints under pages/api).
• public/ – Static assets (images, CSS).
• src/components/ – Reusable React UI components.
• src/controllers/ – Business-logic handlers invoked by API routes.
• src/models/ – Mongoose schemas for users, products.
• src/utils/ – Helpers (dbConnect, password hashing, form value schemas).
• src/contexts, src/themes, src/styles – App theming and state contexts.
Patterns
• Layered MVC-style:
– Presentation: pages/ + components/ + Material-UI theme.
– Controllers: src/controllers handle request logic.
– Models: src/models handle data schema & persistence.
• API-route boundary: Next.js API routes in pages/api delegate to controllers.
• External services: MongoDB Atlas (database), Cloudinary (file storage), NextAuth (OAuth).
README Insights
• Tech Stack: Next.js, React, Material-UI, MongoDB Atlas, Cloudinary, Mongoose, bcrypt, formik, React-Dropzone, NextAuth.
• Deployment: Vercel.
• Responsive design, dark/light theme via Material-UI.
a. Main Components
• Client Browser (React pages, Material-UI)
• Next.js Server (SSR + Static + API routes)
• API Controllers layer (signin, products, users)
• Data Layer: MongoDB Atlas cluster
• File Storage: Cloudinary service
• Auth Provider: NextAuth + Google OAuth
b. Relationships & Data Flows
1. User ↔ Browser UI: React pages (SSR/CSR), form submissions (Sign in, Publish ad).
2. Browser → Next.js API: HTTP calls to /api/auth, /api/products, /api/users.
3. API Controllers → Data Layer: Mongoose → MongoDB Atlas.
4. API Controllers → Cloudinary: Image upload/delete calls.
5. NextAuth → Google OAuth external endpoints for login.
c. Architectural Patterns & Principles
• Separation of concerns: UI vs Business logic vs Data access layers.
• Server-Side Rendering (SSR) and API-first: Next.js pages for SEO + fast initial load, RESTful API routes for data.
• Authentication middleware (NextAuth) guarding pages via CheckAuth component.
d. Key Technologies / Frameworks
• Next.js (pages/, routing, SSR, API routes)
• React + Material-UI (UI components, theming)
• Mongoose + MongoDB Atlas (ODM + cloud DB)
• Cloudinary SDK (image storage)
• NextAuth (session management, OAuth)