How md-atif-khan/codegen works
Project Type and Purpose
• CodeGen is a full-stack web application.
• Client: a Vite-powered React UI (with Tailwind CSS and ESLint).
• Server: an Express.js backend exposing REST/AI endpoints, persisting data in MongoDB, handling JWT-based auth.
File Structure
• Top-level directories:
– client/ (front-end)
– server/ (back-end)
• client/: React components, pages, context, hooks, services (API wrapper, validation), assets, config (vite, ESLint, PostCSS).
• server/: Express entry (server.js), MVC-style subdirectories—controllers, models, routes, services—plus middleware (auth, error, logger), config (database), and utils.
• render.yaml: deployment descriptor (e.g., Render.com).
README for Additional Insights
• Client runs on VITE dev server; connects to BACKEND via VITE_API_URL.
• Server uses MONGODB_URI, JWT_SECRET, API_KEY for AI routes.
• Communication: client ↔ server over REST; server ↔ MongoDB; server ↔ external AI service.
Main Components & Interactions
a. Frontend (React App)
– Components: CodeEditor, ClassStructure, CodeStructureViewer, CreateProject, Navbar, PrivateRoute.
– Pages: Home, Login/Signup, Dashboard, ProjectPage, ProjectEditor.
– Context/AuthContext manages JWT and user state.
– Hooks: useAuth for auth logic.
– Services: api.js wraps HTTP calls; validatePassword.js enforces client‐side rules.
b. Backend (Express API)
– Routes: authRoutes (login/signup), projectRoutes (CRUD), aiRoutes (AI code gen).
– Controllers delegate to services: authController → authService (JWT, password hashing); projectController → projectService (CRUD on Project model).
– Middleware: auth (protect routes by verifying JWT), logger (request logging), errorHandler (centralized error responses).
– Models: User, Project (Mongoose schemas).
c. Database
– MongoDB (single database) accessed via Mongoose.
d. External Services
– AI provider (invoked by aiRoutes using API_KEY).
Relationships & Data Flows
1. User interacts with React UI → triggers api.js calls.
2. HTTP(S) requests to Express endpoints.
3. Auth middleware checks JWT; controllers handle requests.
4. Services perform business logic, interact with Mongoose models to read/write MongoDB.
5. For code‐generation, projectController forwards to aiRoutes which call external AI API.
6. Responses flow back through middleware → sent to frontend.
7. UI updates via React state/context.
Architectural Patterns and Technologies
• Frontend: Component-based (React), SPA, Context API for state, hooks for logic separation, Vite build pipeline, Tailwind CSS for styling.
• Backend: MVC pattern (Models, Views are JSON, Controllers), services layer for business logic, middleware for cross-cutting concerns, environment-driven config.
• Security: JWT for stateless auth, CORS configured via CLIENT_URL.
• Deployment: Render.com descriptor (render.yaml).